/
MappedAccess.cpp
199 lines (171 loc) · 3.87 KB
/
MappedAccess.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*********************************************************************************\
* MappedAccess.cpp
* Class used to provide mapped access to configuration items
* (C) 2002 MasterMind
\*********************************************************************************/
#include "XBApp_mxm.h"
#include "XBFont_mxm.h"
#include <XBMesh.h>
#include <XBUtil.h>
#include "XBResource_mxm.h"
#include <xgraphics.h>
#include "MXM.h"
#include "MappedAccess.h"
#include "StdString.h"
#pragma warning(disable:4786)
#pragma warning(disable:4503)
#include <conio.h>
#include <iostream>
#include <string>
#include <map>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CMappedAccess::CMappedAccess()
{
}
void CMappedAccess::Clear( void )
{
m_mapSections.clear();
}
void CMappedAccess::SetString( LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szValue )
{
TMapSections::iterator itSection;
string sSection, sKey, sValue;
TMapStrings::iterator itKey;
if ( szSection )
{
sSection = szSection;
itSection = m_mapSections.find( sSection );
if ( itSection != m_mapSections.end() )
{
if ( szKey )
{
sKey = szKey;
itKey = itSection->second.find( sKey );
if ( itKey != itSection->second.end() )
{
if ( szValue )
{
sValue = szValue;
itKey->second = sValue;
}
else
{
// Delete the key/value pair
itSection->second.erase( sKey );
}
}
else
{
// Add the key/value if value is valid
if ( szValue )
{
sValue = szValue;
itSection->second.insert( TMapStrings::value_type( sKey, sValue ));
}
}
}
else
{
// NULL key means want to delete the section
m_mapSections.erase( sSection );
}
}
else
{
// Didn't find this section....
if ( szKey && szValue )
{
sKey = szKey;
sValue = szValue;
// Create new map, if we have valid key and value
TMapStrings mapTmp;
mapTmp.insert( TMapStrings::value_type( sKey, sValue ) );
m_mapSections.insert( TMapSections::value_type( sSection, mapTmp ) );
}
}
}
// return sDefault.c_str();
}
int CMappedAccess::GetNumberSections( void )
{
return m_mapSections.size();
}
CStdString CMappedAccess::GetString( LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szDefault )
{
TMapSections::iterator itSection;
CStdString sSection, sKey, sDefault;
TMapStrings::iterator itKey;
CStdString sTemp;
sSection = szSection;
sKey = szKey;
sDefault = szDefault;
itSection = m_mapSections.find( sSection );
if ( itSection != m_mapSections.end() )
{
itKey = itSection->second.find( sKey );
if ( itKey != itSection->second.end() )
{
sDefault = itKey->second;
}
}
return sDefault;
}
int CMappedAccess::GetNumberKeys( LPCTSTR szSection )
{
int iReturn = 0;
TMapSections::iterator itSection;
CStdString sSection;
sSection = szSection;
itSection = m_mapSections.find( sSection );
if ( itSection != m_mapSections.end() )
{
iReturn = itSection->second.size();
}
return iReturn;
}
CStdString CMappedAccess::GetSectionName( int iPos )
{
TMapSections::iterator itSection;
itSection = m_mapSections.begin();
while( iPos && itSection != m_mapSections.end() )
{
iPos--;
itSection++;
}
if ( (iPos == 0) && (itSection != m_mapSections.end()) )
{
return itSection->first.c_str();
}
else
{
return _T("");
}
}
CStdString CMappedAccess::GetKeyName( LPCTSTR szSection, int iPos )
{
CStdString sReturn;
TMapSections::iterator itSection;
string sSection;
TMapStrings::iterator itKey;
sSection = szSection;
itSection = m_mapSections.find( sSection );
if ( itSection != m_mapSections.end() )
{
// now, iterate through this list....
itKey = itSection->second.begin();
while( iPos && ( itKey != itSection->second.end()))
{
iPos--;
itKey++;
}
if( (iPos==0) && ( itKey != itSection->second.end()))
{
sReturn = itKey->first.c_str();
}
}
return sReturn;
}