EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EVEMarshalStringTable.h
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Captnoord
24 */
25 
26 #ifndef __EVE_MARSHAL_STRING_TABLE_H__INCL__
27 #define __EVE_MARSHAL_STRING_TABLE_H__INCL__
28 
29 #include "python/PyRep.h"
30 
31 /* Since returned index is always > 0, we may use 0 as error signal. */
32 #define STRING_TABLE_ERROR 0
33 
48 : public Singleton<MarshalStringTable>
49 {
50 public:
52 
60  uint8 LookupIndex( const std::string& str );
61 
69  uint8 LookupIndex( const char* str );
70 
78  const char* LookupString( uint8 index );
79 
80 private:
88  uint32 hash( const char* str )
89  {
90  uint32 hash = 5381;
91  int c;
92 
93  while( ( c = *str++ ) )
94  hash = ( ( hash << 5 ) + hash ) + c; /* hash * 33 + c */
95 
96  return hash;
97  }
98 
99  typedef std::unordered_map<uint32, uint8> StringTableMap;
100  typedef StringTableMap::iterator StringTableMapItr;
101  typedef StringTableMap::const_iterator StringTableMapConstItr;
102 
103  StringTableMap mStringTableMap;
104 
105  /* we made up this list so we have efficient string communication with the client */
106  static const char* const s_mStringTable[];
107 
108  /* the current string count of the string table */
109  static const size_t s_mStringTableSize;
110 };
111 
112 #define sMarshalStringTable \
113  ( MarshalStringTable::get() )
114 
115 #endif /* !__EVE_MARSHAL_STRING_TABLE_H__INCL__ */
116 
117 
118 
unsigned __int8 uint8
Definition: eve-compat.h:46
static const size_t s_mStringTableSize
StringTableMap::const_iterator StringTableMapConstItr
a singleton data container for communication string lookup.
StringTableMap mStringTableMap
static const char *const s_mStringTable[]
unsigned __int32 uint32
Definition: eve-compat.h:50
StringTableMap::iterator StringTableMapItr
const char * LookupString(uint8 index)
lookup a string using a index
std::unordered_map< uint32, uint8 > StringTableMap
Template used for singleton classes.
Definition: Singleton.h:43
uint32 hash(const char *str)
djb2 algorithm taken from http://www.cse.yorku.ca/~oz/hash.html slightly modified ...
uint8 LookupIndex(const std::string &str)
lookup a index nr using a string