00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _DEBUG_
00025 #include <iostream>
00026 #endif
00027
00028 #include "storage.h"
00029
00030
00031 storage::~storage ()
00032 {
00033 }
00034
00035
00036
00037 void storage::set_val (string key, s_int32 value)
00038 {
00039 #ifdef _DEBUG_
00040 std::cout << "storage::set_val \"" << key << "\" = " << value << std::endl;
00041 #endif
00042 if (!value) data.erase (key);
00043 else
00044 data[key] = value;
00045
00046 changed = 1;
00047 }
00048
00049
00050 s_int32 storage::get_val (string key)
00051 {
00052 #ifdef _DEBUG_
00053 if (data.find (key) != data.end ())
00054 std::cout << "storage::get_val \"" << key << "\" = " << data[key] << std::endl;
00055 else
00056 std::cout << "storage::get_val no such key \"" << key << "\"" << std::endl;
00057 #endif
00058 if (data.find (key) == data.end ()) return 0;
00059 else return data[key];
00060 }
00061
00062
00063 s_int32& storage::operator[] (string key)
00064 {
00065 return data[key];
00066 }
00067
00068
00069 pair<string, s_int32> storage::next ()
00070 {
00071 if (changed)
00072 {
00073 changed = 0;
00074 i = data.begin ();
00075 }
00076
00077 if (i == data.end ())
00078 {
00079 changed = 1;
00080 return pair<string, s_int32> (NULL, 0);
00081 }
00082
00083 return *i++;
00084 }
00085
00086
00087
00088 void objects::set_val (const char* key, storage *val)
00089 {
00090 map<const char*, storage*, ltstr>::iterator j;
00091
00092
00093 for (j = data.begin (); j != data.end (); j++)
00094 if (strcmp ((*j).first, key) == 0)
00095 {
00096 #ifdef _DEBUG_
00097 std::cout << "*** objects::set: key already exists: '" << key << "'\n";
00098 std::cout << "*** container contents: ";
00099
00100 for (j = data.begin (); j != data.end (); j++)
00101 std::cout << "'" << (*j).first << "', ";
00102
00103 std::cout << "\n\n" << flush;
00104 #endif
00105
00106 return;
00107 }
00108
00109 data[key] = val;
00110 changed = 1;
00111 }
00112
00113
00114 storage* objects::get_val (const char* key)
00115 {
00116 map<const char*, storage*, ltstr>::iterator j;
00117
00118
00119 for (j = data.begin (); j != data.end (); j++)
00120 if (strcmp ((*j).first, key) == 0)
00121 return (*j).second;
00122
00123 #ifdef _DEBUG_
00124 std::cout << "*** objects::get: key does not exist: '" << key << "'\n";
00125 std::cout << "*** container contents: ";
00126
00127 for (j = data.begin (); j != data.end (); j++)
00128 cout << "'" << (*j).first << "', ";
00129
00130 cout << "\n\n" << flush;
00131 #endif
00132
00133
00134
00135 return NULL;
00136 }
00137
00138
00139 void objects::erase (const char *key)
00140 {
00141
00142 if (data.find (key) != data.end ())
00143 {
00144 data.erase (key);
00145 changed = 1;
00146 }
00147 }
00148
00149
00150 storage *objects::next ()
00151 {
00152 if (changed)
00153 {
00154 changed = 0;
00155 i = data.begin ();
00156 }
00157
00158 if (i == data.end ())
00159 {
00160 changed = 1;
00161 return NULL;
00162 }
00163
00164 return (*i++).second;
00165 }
00166