Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsrecordset.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
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 }

Generated by doxygen