Changeset 15655
- Timestamp:
- 2008-05-22T16:44:51+12:00 (16 years ago)
- Location:
- gsdl/trunk/lib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/lib/dbclass.cpp
r15652 r15655 26 26 #include "dbclass.h" 27 27 #include "OIDtools.h" 28 #include "unitool.h" 28 29 29 30 … … 36 37 text_t data; 37 38 return getkeydata (key, data); 39 } 40 41 42 // May be overwritten by subclasses; returns true on success 43 bool dbclass::getinfo (const text_t& key, infodbclass &info) 44 { 45 text_t data; 46 if (!getkeydata(key, data)) return false; 47 48 // Use getinfoline() to parse the data value into the infodbclass object 49 text_t::iterator data_iterator = data.begin(); 50 text_t ikey, ivalue; 51 info.clear(); 52 while (getinfoline(data_iterator, data.end(), ikey, ivalue)) 53 { 54 info.addinfo(ikey, ivalue); 55 } 56 57 return true; 58 } 59 60 61 // returns true on success 62 bool dbclass::getinfoline (text_t::iterator &here, text_t::iterator end, 63 text_t &key, text_t &value) 64 { 65 key.clear(); 66 value.clear(); 67 68 // ignore white space 69 while (here != end && is_unicode_space (*here)) ++here; 70 71 // get the '<' 72 if (here == end || *here != '<') return false; 73 ++here; 74 75 // get the key 76 while (here != end && *here != '>') { 77 key.push_back(*here); 78 ++here; 79 } 80 81 // get the '>' 82 if (here == end || *here != '>') return false; 83 ++here; 84 85 // get the value 86 while (here != end && *here != '\n') { 87 if (*here == '\\') { 88 // found escape character 89 ++here; 90 if (here != end) { 91 if (*here == 'n') value.push_back ('\n'); 92 else if (*here == 'r') value.push_back ('\r'); 93 else value.push_back(*here); 94 } 95 96 } else { 97 // a normal character 98 value.push_back(*here); 99 } 100 101 ++here; 102 } 103 104 return true; 105 } 106 107 108 // returns true on success 109 bool dbclass::setinfo (const text_t &key, const infodbclass &info) 110 { 111 text_t subkey; 112 text_t data; 113 114 // get all the keys and values 115 infodbclass::const_iterator info_here = info.begin(); 116 infodbclass::const_iterator info_end = info.end(); 117 while (info_here != info_end) { 118 // add the key 119 subkey.clear(); 120 subkey.push_back('<'); 121 text_t::const_iterator subkey_here = (*info_here).first.begin(); 122 text_t::const_iterator subkey_end = (*info_here).first.end(); 123 while (subkey_here != subkey_end) { 124 if (*subkey_here == '>') { 125 subkey.push_back('\\'); subkey.push_back('>'); 126 } else if (*subkey_here == '\n') { 127 subkey.push_back('\\'); subkey.push_back('n'); 128 } else if (*subkey_here == '\r') { 129 subkey.push_back('\\'); subkey.push_back('r'); 130 } else if (*subkey_here == '\\') { 131 subkey.push_back('\\'); subkey.push_back('\\'); 132 } else { 133 subkey.push_back (*subkey_here); 134 } 135 ++subkey_here; 136 } 137 subkey.push_back('>'); 138 139 // add the values 140 text_tarray::const_iterator subvalue_here = (*info_here).second.begin(); 141 text_tarray::const_iterator subvalue_end = (*info_here).second.end(); 142 while (subvalue_here != subvalue_end) { 143 data += subkey; 144 145 text_t::const_iterator thissubvalue_here = (*subvalue_here).begin(); 146 text_t::const_iterator thissubvalue_end = (*subvalue_here).end(); 147 while (thissubvalue_here != thissubvalue_end) { 148 if (*thissubvalue_here == '>') { 149 data.push_back('\\'); data.push_back('>'); 150 } else if (*thissubvalue_here == '\n') { 151 data.push_back('\\'); data.push_back('n'); 152 } else if (*thissubvalue_here == '\r') { 153 data.push_back('\\'); data.push_back('r'); 154 } else if (*thissubvalue_here == '\\') { 155 data.push_back('\\'); data.push_back('\\'); 156 } else { 157 data.push_back (*thissubvalue_here); 158 } 159 160 ++thissubvalue_here; 161 } 162 163 data.push_back('\n'); 164 ++subvalue_here; 165 } 166 167 ++info_here; 168 } 169 170 return setkeydata(key, data); 38 171 } 39 172 -
gsdl/trunk/lib/dbclass.h
r15652 r15655 54 54 virtual ~dbclass(); 55 55 56 // MUST be implemented by subclasses; returns true if opened 56 void setlogout (ostream *logout_arg) { logout = logout_arg; } 57 58 59 // ----------------------------------------------------------------------------------------------- 60 // These functions MUST be implemented by subclasses, as they are database-specific 61 62 // returns true if opened 57 63 virtual bool opendatabase (const text_t &filename, int mode, int num_retrys, bool need_filelock) = 0; 58 64 59 // MUST be implemented by subclasses60 65 virtual void closedatabase () = 0; 61 66 62 // MUST be implemented by subclasses63 67 virtual void deletekey (const text_t &key) = 0; 64 68 65 // May be overwritten by subclasses; returns true if exists 66 virtual bool exists (const text_t& key); 67 68 // Must be implemented by subclasses; returns true on success 69 virtual bool getinfo (const text_t& key, infodbclass &info) = 0; 70 71 // MUST be implemented by subclasses; returns true on success 69 // returns true on success 72 70 virtual bool getkeydata (const text_t& key, text_t &data) = 0; 73 71 74 // MUST be implemented by subclasses;returns array of keys72 // returns array of keys 75 73 virtual text_tarray getkeys () = 0; 76 74 77 // Must be implemented by subclasses; returns true on success 78 virtual bool setinfo (const text_t &key, const infodbclass &info) = 0; 79 80 // MUST be implemented by subclasses; returns true on success 75 // returns true on success 81 76 virtual bool setkeydata (const text_t &key, const text_t &data) = 0; 82 77 83 78 84 void setlogout (ostream *logout_arg) { logout = logout_arg; } 79 // ----------------------------------------------------------------------------------------------- 80 // These functions may be overwritten by subclasses, but a default implementation is provided 81 82 // returns true if exists 83 virtual bool exists (const text_t& key); 84 85 // returns true on success 86 virtual bool getinfo (const text_t& key, infodbclass &info); 87 88 // returns true on success 89 virtual bool setinfo (const text_t &key, const infodbclass &info); 90 85 91 86 92 // replaces the .c, .p, .n, .l syntax (child, parent, next, previous) … … 92 98 ostream *logout; 93 99 100 // returns true on success 101 bool getinfoline (text_t::iterator &here, text_t::iterator end, text_t &key, text_t &value); 102 94 103 void get_first_child (text_t &OID, infodbclass &info); 95 104 void get_last_child (text_t &OID, infodbclass &info); -
gsdl/trunk/lib/gdbmclass.cpp
r15652 r15655 116 116 117 117 // returns true on success 118 bool gdbmclass::getinfo (const text_t& key, infodbclass &info)119 {120 text_t data;121 if (!getkeydata(key, data)) return false;122 123 // Use getinfoline() to parse the data value into the infodbclass object124 text_t::iterator data_iterator = data.begin();125 text_t ikey, ivalue;126 info.clear();127 while (getinfoline(data_iterator, data.end(), ikey, ivalue))128 {129 info.addinfo(ikey, ivalue);130 }131 132 return true;133 }134 135 136 // returns true on success137 118 bool gdbmclass::getkeydata (const text_t& key, text_t &data) 138 119 { … … 181 162 182 163 // returns true on success 183 bool gdbmclass::setinfo (const text_t &key, const infodbclass &info)184 {185 if (gdbmfile == NULL) return false;186 187 text_t subkey;188 text_t data;189 190 // get all the keys and values191 infodbclass::const_iterator info_here = info.begin();192 infodbclass::const_iterator info_end = info.end();193 while (info_here != info_end) {194 // add the key195 subkey.clear();196 subkey.push_back('<');197 text_t::const_iterator subkey_here = (*info_here).first.begin();198 text_t::const_iterator subkey_end = (*info_here).first.end();199 while (subkey_here != subkey_end) {200 if (*subkey_here == '>') {201 subkey.push_back('\\'); subkey.push_back('>');202 } else if (*subkey_here == '\n') {203 subkey.push_back('\\'); subkey.push_back('n');204 } else if (*subkey_here == '\r') {205 subkey.push_back('\\'); subkey.push_back('r');206 } else if (*subkey_here == '\\') {207 subkey.push_back('\\'); subkey.push_back('\\');208 } else {209 subkey.push_back (*subkey_here);210 }211 ++subkey_here;212 }213 subkey.push_back('>');214 215 // add the values216 text_tarray::const_iterator subvalue_here = (*info_here).second.begin();217 text_tarray::const_iterator subvalue_end = (*info_here).second.end();218 while (subvalue_here != subvalue_end) {219 data += subkey;220 221 text_t::const_iterator thissubvalue_here = (*subvalue_here).begin();222 text_t::const_iterator thissubvalue_end = (*subvalue_here).end();223 while (thissubvalue_here != thissubvalue_end) {224 if (*thissubvalue_here == '>') {225 data.push_back('\\'); data.push_back('>');226 } else if (*thissubvalue_here == '\n') {227 data.push_back('\\'); data.push_back('n');228 } else if (*thissubvalue_here == '\r') {229 data.push_back('\\'); data.push_back('r');230 } else if (*thissubvalue_here == '\\') {231 data.push_back('\\'); data.push_back('\\');232 } else {233 data.push_back (*thissubvalue_here);234 }235 236 ++thissubvalue_here;237 }238 239 data.push_back('\n');240 ++subvalue_here;241 }242 243 ++info_here;244 }245 246 return setkeydata(key, data);247 }248 249 250 // returns true on success251 164 bool gdbmclass::setkeydata (const text_t &key, const text_t &data) 252 165 { … … 329 242 return to_uni(nextkey); // convert to unicode 330 243 } 331 332 333 // returns true on success334 bool gdbmclass::getinfoline (text_t::iterator &here, text_t::iterator end,335 text_t &key, text_t &value)336 {337 key.clear();338 value.clear();339 340 // ignore white space341 while (here != end && is_unicode_space (*here)) ++here;342 343 // get the '<'344 if (here == end || *here != '<') return false;345 ++here;346 347 // get the key348 while (here != end && *here != '>') {349 key.push_back(*here);350 ++here;351 }352 353 // get the '>'354 if (here == end || *here != '>') return false;355 ++here;356 357 // get the value358 while (here != end && *here != '\n') {359 if (*here == '\\') {360 // found escape character361 ++here;362 if (here != end) {363 if (*here == 'n') value.push_back ('\n');364 else if (*here == 'r') value.push_back ('\r');365 else value.push_back(*here);366 }367 368 } else {369 // a normal character370 value.push_back(*here);371 }372 373 ++here;374 }375 376 return true;377 } -
gsdl/trunk/lib/gdbmclass.h
r15652 r15655 63 63 64 64 // returns true on success 65 bool getinfo (const text_t& key, infodbclass &info);66 67 // returns true on success68 65 bool getkeydata (const text_t& key, text_t &data); 69 66 70 67 // returns array of keys 71 68 text_tarray getkeys (); 72 73 // returns true on success74 bool setinfo (const text_t &key, const infodbclass &info);75 69 76 70 // returns true on success … … 87 81 text_t getfirstkey (); 88 82 text_t getnextkey (const text_t &key); 89 90 // returns true on success91 bool getinfoline (text_t::iterator &here, text_t::iterator end, text_t &key, text_t &value);92 83 }; 93 84 -
gsdl/trunk/lib/sqlitedbclass.cpp
r15652 r15655 90 90 91 91 // returns true on success 92 bool sqlitedbclass::getinfo (const text_t& key, infodbclass &info)93 {94 text_t data;95 if (!getkeydata(key, data)) return false;96 97 // Use getinfoline() to parse the data value into the infodbclass object98 text_t::iterator data_iterator = data.begin();99 text_t ikey, ivalue;100 info.clear();101 while (getinfoline(data_iterator, data.end(), ikey, ivalue))102 {103 info.addinfo(ikey, ivalue);104 }105 106 return true;107 }108 109 110 // returns true on success111 92 bool sqlitedbclass::getkeydata (const text_t& key, text_t &data) 112 93 { … … 151 132 152 133 // returns true on success 153 bool sqlitedbclass::setinfo (const text_t &key, const infodbclass &info)154 {155 text_t subkey;156 text_t data;157 158 // get all the keys and values159 infodbclass::const_iterator info_here = info.begin();160 infodbclass::const_iterator info_end = info.end();161 while (info_here != info_end) {162 // add the key163 subkey.clear();164 subkey.push_back('<');165 text_t::const_iterator subkey_here = (*info_here).first.begin();166 text_t::const_iterator subkey_end = (*info_here).first.end();167 while (subkey_here != subkey_end) {168 if (*subkey_here == '>') {169 subkey.push_back('\\'); subkey.push_back('>');170 } else if (*subkey_here == '\n') {171 subkey.push_back('\\'); subkey.push_back('n');172 } else if (*subkey_here == '\r') {173 subkey.push_back('\\'); subkey.push_back('r');174 } else if (*subkey_here == '\\') {175 subkey.push_back('\\'); subkey.push_back('\\');176 } else {177 subkey.push_back (*subkey_here);178 }179 ++subkey_here;180 }181 subkey.push_back('>');182 183 // add the values184 text_tarray::const_iterator subvalue_here = (*info_here).second.begin();185 text_tarray::const_iterator subvalue_end = (*info_here).second.end();186 while (subvalue_here != subvalue_end) {187 data += subkey;188 189 text_t::const_iterator thissubvalue_here = (*subvalue_here).begin();190 text_t::const_iterator thissubvalue_end = (*subvalue_here).end();191 while (thissubvalue_here != thissubvalue_end) {192 if (*thissubvalue_here == '>') {193 data.push_back('\\'); data.push_back('>');194 } else if (*thissubvalue_here == '\n') {195 data.push_back('\\'); data.push_back('n');196 } else if (*thissubvalue_here == '\r') {197 data.push_back('\\'); data.push_back('r');198 } else if (*thissubvalue_here == '\\') {199 data.push_back('\\'); data.push_back('\\');200 } else {201 data.push_back (*thissubvalue_here);202 }203 204 ++thissubvalue_here;205 }206 207 data.push_back('\n');208 ++subvalue_here;209 }210 211 ++info_here;212 }213 214 return setkeydata(key, data);215 }216 217 218 // returns true on success219 134 bool sqlitedbclass::setkeydata (const text_t &key, const text_t &data) 220 135 { … … 233 148 234 149 235 // returns true on success236 bool sqlitedbclass::getinfoline (text_t::iterator &here, text_t::iterator end,237 text_t &key, text_t &value)238 {239 key.clear();240 value.clear();241 242 // ignore white space243 while (here != end && is_unicode_space (*here)) ++here;244 245 // get the '<'246 if (here == end || *here != '<') return false;247 ++here;248 249 // get the key250 while (here != end && *here != '>') {251 key.push_back(*here);252 ++here;253 }254 255 // get the '>'256 if (here == end || *here != '>') return false;257 ++here;258 259 // get the value260 while (here != end && *here != '\n') {261 if (*here == '\\') {262 // found escape character263 ++here;264 if (here != end) {265 if (*here == 'n') value.push_back ('\n');266 else if (*here == 'r') value.push_back ('\r');267 else value.push_back(*here);268 }269 270 } else {271 // a normal character272 value.push_back(*here);273 }274 275 ++here;276 }277 278 return true;279 }280 281 282 150 // ---------------------------------------------------------------------------------------- 283 // CORE SQLFUNCTIONS151 // SQLITE-ONLY FUNCTIONS 284 152 // ---------------------------------------------------------------------------------------- 285 153 -
gsdl/trunk/lib/sqlitedbclass.h
r15652 r15655 46 46 47 47 // returns true on success 48 bool getinfo (const text_t& key, infodbclass &info);49 50 // returns true on success51 48 bool getkeydata (const text_t& key, text_t &data); 52 49 53 50 // returns array of keys 54 51 text_tarray getkeys (); 55 56 // returns true on success57 bool setinfo (const text_t &key, const infodbclass &info);58 52 59 53 // returns true on success … … 64 58 sqlite3* sqlitefile; 65 59 66 bool getinfoline (text_t::iterator &here, text_t::iterator end, text_t &key, text_t &value);67 68 60 bool sqlexec (const text_t &sql_cmd); 69 61 bool sqlgetarray (const text_t &sql_cmd, vector<text_tmap> &sql_results);
Note:
See TracChangeset
for help on using the changeset viewer.