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.
31 typedef void (*ReleaseFun
)(void *);
34 #define GEM_VARIABLES_INT 0
35 #define GEM_VARIABLES_STRING 1
36 #define GEM_VARIABLES_POINTER 2
38 class GEM_EXPORT Variables
{
49 unsigned long nHashValue
;
50 friend class Variables
;
56 // abstract iteration position
57 typedef MyAssoc
*iterator
;
60 Variables(int nBlockSize
= 10, int nHashTableSize
= 2049);
61 void LoadInitialValues(const char* name
);
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 );
72 //sets the way we handle values
73 inline void SetType(int type
)
77 inline int GetCount() const
81 inline bool IsEmpty() const
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;
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;
107 Variables::MyAssoc
** m_pHashTable
;
108 unsigned int m_nHashTableSize
;
111 Variables::MyAssoc
* m_pFreeList
;
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;