26 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)    27   #error "Only <final/final.h> can be included directly."    33 #include <unordered_map>    36 #include "final/input/fkey_map.h"    49   static auto getMaxHashSize() -> std::size_t
    51     static const auto size = std::max( FKeyMap::getKeyMap().size()
    52                                      , FKeyMap::getKeyCapMap().size() ) * 2;
    58 template <
typename BufferT>
    70   const char* 
string{
nullptr};
    71   const uInt8 length{0};
    72   const BufferT* buffer{
nullptr};
    76 template <
typename IterT>
    77 constexpr 
auto hash_function (IterT iter, 
const IterT end) -> std::size_t
    83     sum += std::size_t(*iter);
    85     sum += ( iter != end ) ? std::size_t(*iter) << 8 : 0;
    88   return sum % Const::getMaxHashSize();
    92 template <
typename BufferT>
    93 constexpr 
auto hash_function (
const BufferT& buf) -> std::size_t
    95   return hash_function (std::begin(buf), std::end(buf));
    99 template <
typename BufferT>
   104     if ( key.string && ! key.buffer )
   105       return hash_function (key.string, key.string + key.length);
   108       return hash_function (*key.buffer);
   110     return hash_function(std::string(
"unknown"));
   115 template <
typename BufferT>
   121     if ( lhs.string && ! lhs.buffer && rhs.string && ! rhs.buffer )
   123       return lhs.length == rhs.length
   124           && std::memcmp(lhs.string, rhs.string, rhs.length) == 0;
   127     if ( ! lhs.string && lhs.buffer && rhs.string && ! rhs.buffer )
   129       return lhs.buffer->getSize() == rhs.length
   130           && lhs.buffer->strncmp_front(rhs.string, rhs.length);
   133     if ( lhs.string && ! lhs.buffer && ! rhs.string && rhs.buffer )
   135       return lhs.length == rhs.buffer->getSize()
   136           && rhs.buffer->strncmp_front(lhs.string, lhs.length);
   145 template <
typename BufferT>
   146 using HashMap = std::unordered_map<KeySequence<BufferT>
   152 template <
typename BufferT>
   153 auto createKeyCapMap() -> HashMap<BufferT>
   155   const auto& fkey_cap_table = FKeyMap::getKeyCapMap();
   156   HashMap<BufferT> fkey_cap_map;
   157   fkey_cap_map.reserve(fkey_cap_table.size());
   159   for (
const auto& item : fkey_cap_table)
   160     if ( item.string && item.length != 0 )
   161       fkey_cap_map[{item.string, item.length}] = item.num;
   167 template <
typename BufferT, 
typename IterT>
   168 auto createKeyCapMap (IterT begin, IterT end) -> HashMap<BufferT>
   170   HashMap<BufferT> fkey_cap_map;
   171   fkey_cap_map.reserve(std::size_t(end - begin));
   174   while ( iter != end )
   176     if ( iter->string && iter->length != 0 )
   177       fkey_cap_map[{iter->string, iter->length}] = iter->num;
   186 template <
typename BufferT>
   187 auto createKeyMap() -> HashMap<BufferT>
   189   auto& fkey_table = FKeyMap::getKeyMap();
   190   HashMap<BufferT> fkey_map;
   191   fkey_map.reserve(fkey_table.size());
   193   for (
auto& item : fkey_table)
   194     if ( item.length != 0 )  
   195       fkey_map[{item.string.data(), item.length}] = item.num;
   203 template <
typename BufferT>
   204 auto getKeyCapMap() -> internal::HashMap<BufferT>&
   206   using HashMapType = internal::HashMap<BufferT>;
   207   static const auto& fkey_cap_map = std::make_unique<HashMapType>(internal::createKeyCapMap<BufferT>());
   208   return *fkey_cap_map;
   212 template <
typename BufferT, 
typename IterT>
   213 void setKeyCapMap (IterT begin, IterT end)
   215   getKeyCapMap<BufferT>() = internal::createKeyCapMap<BufferT>(begin, end);
   219 template <
typename BufferT>
   220 auto getKeyMap() -> internal::HashMap<BufferT>&
   222   using HashMapType = internal::HashMap<BufferT>;
   223   static const auto& fkey_map = std::make_unique<HashMapType>(internal::createKeyMap<BufferT>());
   228 template <
typename BufferT>
   229 auto getTermcapKey (
const BufferT& char_rbuf) -> FKey
   231   auto& hashmap = getKeyCapMap<BufferT>();
   234   if ( iter != hashmap.end() )  
   241 template <
typename BufferT>
   242 auto getKnownKey (
const BufferT& char_rbuf) -> FKey
   244   auto& hashmap = getKeyMap<BufferT>();
   247   if ( iter != hashmap.end() )  
   257 #endif  // FKEYHASHMAP_H Definition: fkey_hashmap.h:59
 
Definition: fkey_hashmap.h:116
 
Definition: class_template.cpp:25
 
Definition: fkey_hashmap.h:100
 
Definition: fkey_hashmap.h:47