00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmstools/mmsrecordset.h"
00034
00035 MMSRecordSet::~MMSRecordSet() {
00036 for(vector< map<string, string>* >::iterator it = rows.begin();it!=rows.end();it++) {
00037 if(*it) delete *it;
00038 *it=NULL;
00039 }
00040 rows.clear();
00041 }
00042
00043 void MMSRecordSet::addRow() {
00044 this->count++;
00045 this->recnum = this->count-1;
00046 rows.push_back(new map<string, string> );
00047 }
00048
00049 bool MMSRecordSet::next() {
00050 if(this->recnum < this->count - 1) {
00051 this->recnum++;
00052 return true;
00053 }
00054
00055 return false;
00056 }
00057
00058 bool MMSRecordSet::previous() {
00059 if(this->recnum > 0) {
00060 this->recnum--;
00061 return true;
00062 }
00063
00064 return false;
00065 }
00066
00067 const unsigned int MMSRecordSet::getCount() const {
00068 return (unsigned int) this->count;
00069 }
00070
00071 const string MMSRecordSet::getInfo() const {
00072 return this->info;
00073 }
00074
00075 bool MMSRecordSet::setRecordNum(int num) {
00076 if(num < this->count) {
00077 this->recnum = num;
00078 return true;
00079 }
00080
00081 return false;
00082 }
00083
00084 const int MMSRecordSet::getRecordNum() const {
00085 return this->recnum;
00086 }
00087
00088 static string defret = "";
00089
00090 string &MMSRecordSet::operator[](string key) {
00091 if(this->recnum == -1)
00092 return defret;
00093
00094 map<string,string>::iterator found;
00095 found = rows.at(this->recnum)->find(key);
00096 if (found != rows.at(this->recnum)->end())
00097 return found->second;
00098 else {
00099 pair< map<string,string>::iterator, bool > ret = rows.at(this->recnum)->insert(make_pair(key,string("")));
00100 return ret.first->second;
00101 }
00102 }
00103
00104 const string &MMSRecordSet::operator[](const string key) const {
00105 if(this->recnum == -1)
00106 return defret;
00107
00108 map<string,string>::iterator found;
00109 found = rows.at(this->recnum)->find(key);
00110 if (found != rows.at(this->recnum)->end())
00111 return found->second;
00112
00113 return defret;
00114 }
00115
00116 bool MMSRecordSet::reset() {
00117 for(vector< map<string, string>* >::iterator it = rows.begin();it!=rows.end();it++) {
00118 if(*it) delete *it;
00119 *it=NULL;
00120 }
00121
00122 rows.clear();
00123
00124 this->recnum = -1;
00125 this->count = 0;
00126 this->info = "not specified";
00127
00128 return true;
00129 }