GUIScript: Make LoadSymbol return an object.
[gemrb.git] / gemrb / core / Variables.h
blob67c646248e8c3bb9f661f0f362af79e6d3e5c3a4
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 |Avenger|
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef VARIABLES_H
22 #define VARIABLES_H
25 #include "SClassID.h"
26 #include "exports.h"
27 #include "globals.h"
28 #include "win32def.h"
30 #ifndef ReleaseFun
31 typedef void (*ReleaseFun)(void *);
32 #endif
34 #define GEM_VARIABLES_INT 0
35 #define GEM_VARIABLES_STRING 1
36 #define GEM_VARIABLES_POINTER 2
38 class GEM_EXPORT Variables {
39 protected:
40 // Association
41 class MyAssoc {
42 MyAssoc* pNext;
43 char* key;
44 union {
45 ieDword nValue;
46 char* sValue;
47 void* pValue;
48 } Value;
49 unsigned long nHashValue;
50 friend class Variables;
52 struct MemBlock {
53 MemBlock* pNext;
55 public:
56 // abstract iteration position
57 typedef MyAssoc *iterator;
58 public:
59 // Construction
60 Variables(int nBlockSize = 10, int nHashTableSize = 2049);
61 void LoadInitialValues(const char* name);
63 // Attributes
64 //sets the way we handle keys, no parsing for .ini file entries, parsing for game variables
65 //you should set this only on an empty mapping
66 inline int ParseKey(int arg)
68 assert( m_nCount == 0 );
69 m_lParseKey = ( arg > 0 );
70 return 0;
72 //sets the way we handle values
73 inline void SetType(int type)
75 m_type = type;
77 inline int GetCount() const
79 return m_nCount;
81 inline bool IsEmpty() const
83 return m_nCount == 0;
86 // Lookup
87 int GetValueLength(const char* key) const;
88 bool Lookup(const char* key, char* dest, int MaxLength) const;
89 bool Lookup(const char* key, ieDword& rValue) const;
90 bool Lookup(const char* key, char*& dest) const;
91 bool Lookup(const char* key, void*& dest) const;
93 // Operations
94 void SetAtCopy(const char* key, const char* newValue);
95 void SetAtCopy(const char* key, int newValue);
96 void SetAt(const char* key, char* newValue);
97 void SetAt(const char* key, void* newValue);
98 void SetAt(const char* key, ieDword newValue);
99 void Remove(const char* key);
100 void RemoveAll(ReleaseFun fun);
101 void InitHashTable(unsigned int hashSize, bool bAllocNow = true);
103 iterator GetNextAssoc(iterator rNextPosition, const char*& rKey,
104 ieDword& rValue) const;
105 // Implementation
106 protected:
107 Variables::MyAssoc** m_pHashTable;
108 unsigned int m_nHashTableSize;
109 bool m_lParseKey;
110 int m_nCount;
111 Variables::MyAssoc* m_pFreeList;
112 MemBlock* m_pBlocks;
113 int m_nBlockSize;
114 int m_type; //could be string or ieDword
116 Variables::MyAssoc* NewAssoc(const char* key);
117 void FreeAssoc(Variables::MyAssoc*);
118 Variables::MyAssoc* GetAssocAt(const char*, unsigned int&) const;
119 inline bool MyCopyKey(char*& dest, const char* key) const;
120 inline unsigned int MyHashKey(const char*) const;
122 public:
123 ~Variables();
126 #endif