Main Page | Class Hierarchy | Class List | File List | Class Members

db_module.h

00001 // tacppd database description types
00002 // (c) Copyright 2000-2005 by tacppd team and contributors
00003 // see http://tacppd.org for more information
00004 
00005 //  This program is free software; you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License
00016 //  along with this program; if not, write to the Free Software
00017 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // all comments which start from /**<CR> - this is comments for KDoc
00020 //  for classes
00021 //    @short [short description of the class]
00022 //    @author [class author]
00023 //    @version [class version]
00024 //    @see [references to other classes or methods]
00025 //  for methods
00026 //    @see [references]
00027 //    @return [sentence describing the return value]
00028 //    @exception [list the exeptions that could be thrown]
00029 //    @param [name id] [description] - can be multiple
00030 
00031 #ifndef __DB_MODULE_H__
00032 #define __DB_MODULE_H__
00033 
00034 #ifndef _PTHREADS
00035 #define   _PTHREADS   // enable STL pthread-safe code
00036 #endif //_PTHREADS
00037 
00038 #ifndef _REENTRANT
00039 #define   _REENTRANT  // Pthread safe stuff in the stdlibs
00040 #endif //_REENTRANT   // or you should compile with -pthread key
00041 
00042 #include <iostream>
00043 #include <stdio.h>
00044 #include <stdarg.h>
00045 #include <time.h>
00046 
00047 #ifdef SOLARIS
00048 #include <strings.h>
00049 #endif //SOLARIS
00050 
00051 #include <pthread.h>
00052 #include <string>
00053 #include <list>
00054 
00055 #include "ipaddr.h"
00056 
00057 using std::list;
00058 using std::string;
00059 using namespace tacpp;
00060 
00061 #define T_INT_TYPE      (int)0
00062 #define T_UINT_TYPE     (unsigned int)0
00063 #define T_STR_TYPE      ""
00064 #define T_DATE_TYPE     (time_t)0
00065 #define T_BOOL_TYPE     false
00066 #define T_FLOAT_TYPE    (float)0
00067 #define T_IP_TYPE       ipaddr()
00068 
00069 #define T_NOIDX         0
00070 #define T_INDEX         1
00071 #define T_UNIQUE        2
00072 
00073 #define DB_MODULE_ERRLEN  300
00074 
00080 class DbField {
00083   pthread_mutex_t mutex_;
00086   void lock() {
00087     pthread_mutex_lock(&mutex_);
00088   }
00091   void unlock() {
00092     pthread_mutex_unlock(&mutex_);
00093   }
00096   string name_;
00099   string description_;
00102   string defv_;
00105   int t_;
00108   bool update_;
00111   bool request_;
00114   bool bool_type_;
00117   unsigned long int int_type_;
00120   float float_type_;
00123   string string_type_;
00126   int string_len_;
00129   time_t date_type_;
00132   ipaddr ip_type_;
00135   int idx_;
00136  public:
00140   string getName() {
00141     lock();
00142     string ret = name_;
00143     unlock();
00144     return ret;
00145   }
00148   void setName(string d) {
00149     lock();
00150     name_ = d;
00151     unlock();
00152   }
00156   string getDescription() {
00157     lock();
00158     string ret = description_;
00159     unlock();
00160     return ret;
00161   }
00164   void setDescription(string d) {
00165     lock();
00166     description_ = d;
00167     unlock();
00168   }
00172   string getDefv() {
00173     string ret;
00174     lock();
00175     ret = defv_;
00176     unlock();
00177     return ret;
00178   }
00181   void setDefv(string d) {
00182     lock();
00183     defv_ = d;
00184     unlock();
00185   }
00188   int getT() {
00189     int ret;
00190     lock();
00191     ret = t_;
00192     unlock();
00193     return ret;
00194   }
00197   void setT(int d) {
00198     lock();
00199     t_ = d;
00200     unlock();
00201   }
00204   bool getUpdate() {
00205     bool ret;
00206     lock();
00207     ret = update_;
00208     unlock();
00209     return ret;
00210   }
00213   void setUpdate(bool d) {
00214     lock();
00215     update_ = d;
00216     unlock();
00217   }
00220   bool getRequest() {
00221     bool ret;
00222     lock();
00223     ret = request_;
00224     unlock();
00225     return ret;
00226   }
00229   void setRequest(bool d) {
00230     lock();
00231     request_ = d;
00232     unlock();
00233   }
00236   bool getBoolType() {
00237     bool ret;
00238     lock();
00239     ret = bool_type_;
00240     unlock();
00241     return ret;
00242   }
00245   void setBoolType(bool d) {
00246     lock();
00247     bool_type_ = d;
00248     unlock();
00249   }
00253   unsigned long int getIntType() {
00254     unsigned long int ret;
00255     lock();
00256     ret = int_type_;
00257     unlock();
00258     return ret;
00259   }
00262   void setIntType(unsigned long int d) {
00263     lock();
00264     int_type_ = d;
00265     unlock();
00266   }
00270   float getFloatType() {
00271     float ret;
00272     lock();
00273     ret = float_type_;
00274     unlock();
00275     return ret;
00276   }
00279   void setFloatType(float d) {
00280     lock();
00281     float_type_ = d;
00282     unlock();
00283   }
00287   string getStringType() {
00288     string ret;
00289     lock();
00290     ret = string_type_;
00291     unlock();
00292     return ret;
00293   }
00296   void setStringType(string d) {
00297     lock();
00298     string_type_ = d;
00299     unlock();
00300   }
00304   int getStringLen() {
00305     int ret;
00306     lock();
00307     ret = string_len_;
00308     unlock();
00309     return ret;
00310   }
00313   void setStringLen(int d) {
00314     lock();
00315     string_len_ = d;
00316     unlock();
00317   }
00321   time_t getDateType() {
00322     time_t ret;
00323     lock();
00324     ret = date_type_;
00325     unlock();
00326     return ret;
00327   }
00330   void setDateType(time_t d) {
00331     lock();
00332     date_type_ = d;
00333     unlock();
00334   }
00338   ipaddr getIpType() {
00339     ipaddr ret;
00340     lock();
00341     ret = ip_type_;
00342     unlock();
00343     return ret;
00344   }
00347   void setIpType(ipaddr d) {
00348     lock();
00349     ip_type_ = d;
00350     unlock();
00351   }
00354   int getIdx() {
00355     int ret;
00356     lock();
00357     ret = idx_;
00358     unlock();
00359     return ret;
00360   }
00363   void setIdx(int d) {
00364     lock();
00365     idx_ = d;
00366     unlock();
00367   }
00370   ~DbField() {
00371     pthread_mutex_destroy(&mutex_);
00372   }
00375   DbField(const string n,const string d,const string f,bool v,int ix=0) {
00376     pthread_mutex_init(&mutex_,0);
00377     lock();
00378     t_ = 1;  // 1-bool,2-int/uint/ulong,3-float,4-string/char*,5-time_t,6-ipaddr
00379     update_ = false;
00380     request_ = false;
00381     name_ = n;
00382     description_ = d;
00383     defv_ = f;
00384     bool_type_ = v;
00385     int_type_ = 0;
00386     float_type_ = 0;
00387     string_len_ = 0;
00388     date_type_ = 0;
00389     ip_type_ = UNKNOWN_IP;
00390     idx_ = ix;
00391     unlock();
00392   }
00395   DbField(const string n,const string d,const string f,int v,int ix=0) {
00396     pthread_mutex_init(&mutex_,0);
00397     lock();
00398     t_ = 2; // 1-bool,2-int/uint/ulong,3-float,4-string/char*,5-time_t,6-ipaddr
00399     update_ = false;
00400     request_ = false;
00401     name_ = n;
00402     description_ = d;
00403     defv_ = f;
00404     bool_type_ = false;
00405     int_type_ = (unsigned long int)v;
00406     float_type_ = 0;
00407     string_len_ = 0;
00408     date_type_ = 0;
00409     ip_type_ = UNKNOWN_IP;
00410     idx_ = ix;
00411     unlock();
00412   }
00415   DbField(const string n,const string d,const string f,unsigned int v,int ix=0) {
00416     pthread_mutex_init(&mutex_,0);
00417     lock();
00418     t_ = 2; // 1-bool,2-int/uint/ulong,3-float,4-string/char*,5-time_t,6-ipaddr
00419     update_ = false;
00420     request_ = false;
00421     name_ = n;
00422     description_ = d;
00423     defv_ = f;
00424     bool_type_ = false;
00425     int_type_ = (unsigned long int)v;
00426     float_type_ = 0;
00427     string_len_ = 0;
00428     date_type_ = 0;
00429     ip_type_ = UNKNOWN_IP;
00430     idx_ = ix;
00431     unlock();
00432   }
00435   DbField(const string n,const string d,const string f,unsigned long int v,int ix=0) {
00436     pthread_mutex_init(&mutex_,0);
00437     lock();
00438     t_ = 2; // 1-bool,2-int/uint/ulong,3-float,4-string/char*,5-time_t,6-ipaddr
00439     update_ = false;
00440     request_ = false;
00441     name_ = n;
00442     description_ = d;
00443     defv_ = f;
00444     bool_type_ = false;
00445     int_type_ = v;
00446     float_type_ = 0;
00447     string_len_ = 0;
00448     date_type_ = 0;
00449     ip_type_ = UNKNOWN_IP;
00450     idx_ = ix;
00451     unlock();
00452   }
00455   DbField(const string n,const string d,const string f,float v,int ix=0) {
00456     pthread_mutex_init(&mutex_,0);
00457     lock();
00458     t_ = 3; // 1-bool,2-int/uint/ulong,3-float,4-string/char*,5-time_t,6-ipaddr
00459     update_ = false;
00460     request_ = false;
00461     name_ = n;
00462     description_ = d;
00463     defv_ = f;
00464     bool_type_ = false;
00465     int_type_ = 0;
00466     float_type_ = v;
00467     string_len_ = 0;
00468     date_type_ = 0;
00469     ip_type_ = UNKNOWN_IP;
00470     idx_ = ix;
00471     unlock();
00472   }
00475   DbField(const string n,const string d,const string f,string v,int l,int ix=0) {
00476     pthread_mutex_init(&mutex_,0);
00477     lock();
00478     t_ = 4; // 1-bool,2-int/uint/ulong,3-float,4-string/char*,5-time_t,6-ipaddr
00479     update_ = false;
00480     request_ = false;
00481     name_ = n;
00482     description_ = d;
00483     defv_ = f;
00484     bool_type_ = false;
00485     int_type_ = 0;
00486     float_type_ = 0;
00487     string_type_ = v;
00488     string_len_ = l;
00489     date_type_ = 0;
00490     ip_type_ = UNKNOWN_IP;
00491     idx_ = ix;
00492     unlock();
00493   }
00496   DbField(const string n,const string d,const string f,char *v,int l,int ix=0) {
00497     pthread_mutex_init(&mutex_,0);
00498     lock();
00499     t_ = 4; // 1-bool,2-int/uint/ulong,3-float,4-string/char*,5-time_t,6-ipaddr
00500     update_ = false;
00501     request_ = false;
00502     name_ = n;
00503     description_ = d;
00504     defv_ = f;
00505     bool_type_ = false;
00506     int_type_ = 0;
00507     float_type_ = 0;
00508     string_type_ = v;
00509     string_len_ = l;
00510     date_type_ = 0;
00511     ip_type_ = UNKNOWN_IP;
00512     idx_ = ix;
00513     unlock();
00514   }
00517   DbField(const string n,const string d,const string f,time_t v,int ix=0) {
00518     pthread_mutex_init(&mutex_,0);
00519     lock();
00520     t_ = 5; // 1-bool,2-int/uint/ulong,3-float,4-string/char*,5-time_t,6-ipaddr
00521     update_ = false;
00522     request_ = false;
00523     name_ = n;
00524     description_ = d;
00525     defv_ = f;
00526     bool_type_ = false;
00527     int_type_ = 0;
00528     float_type_ = 0;
00529     string_len_ = 0;
00530     date_type_ = v;
00531     ip_type_ = UNKNOWN_IP;
00532     idx_ = ix;
00533     unlock();
00534   }
00537   DbField(const string n,const string d,const string f,ipaddr v,int ix=0) {
00538     pthread_mutex_init(&mutex_,0);
00539     lock();
00540     t_ = 6; // 1-bool,2-int/uint/ulong,3-float,4-string/char*,5-time_t,6-ipaddr
00541     update_ = false;
00542     request_ = false;
00543     name_ = n;
00544     description_ = d;
00545     defv_ = f;
00546     bool_type_ = false;
00547     int_type_ = 0;
00548     float_type_ = 0;
00549     string_len_ = 0;
00550     date_type_ = 0;
00551     ip_type_ = v;
00552     idx_ = ix;
00553     unlock();
00554   }
00555 };
00556 
00562 class DbTable {
00565   pthread_mutex_t mutex_;
00568   void lock() {
00569     pthread_mutex_lock(&mutex_);
00570   }
00573   void unlock() {
00574     pthread_mutex_unlock(&mutex_);
00575   }
00578   list<DbField*> f_;
00581   string name_;
00584   string namemask_;
00587   string description_;
00588  public:
00592   string getName() {
00593     string ret;
00594     lock();
00595     ret = name_;
00596     unlock();
00597     return ret;
00598   }
00601   void setName(string d) {
00602     lock();
00603     name_ = d;
00604     unlock();
00605   }
00609   string getNamemask() {
00610     string ret;
00611     lock();
00612     ret = namemask_;
00613     unlock();
00614     return ret;
00615   }
00618   void setNamemask(string d) {
00619     lock();
00620     namemask_ = d;
00621     unlock();
00622   }
00626   string getDescription() {
00627     string ret;
00628     lock();
00629     ret = description_;
00630     unlock();
00631     return ret;
00632   }
00635   void setDescription(string d) {
00636     lock();
00637     description_ = d;
00638     unlock();
00639   }
00642   int size() {
00643     int ret;
00644     lock();
00645     ret = f_.size();
00646     unlock();
00647     return ret;
00648   }
00651   DbTable(const string n,const string m,const string d) {
00652     pthread_mutex_init(&mutex_,0);
00653     lock();
00654     description_ = d;
00655     namemask_ = m;
00656     name_ = n;
00657     unlock();
00658   }
00661   ~DbTable() {
00662     lock();
00663     DbField *tmp;
00664     for(list<DbField*>::iterator i=f_.begin();i!=f_.end() && !f_.empty();) {
00665       tmp = *i;
00666       i = f_.erase(i);
00667       delete tmp;
00668     }
00669     f_.clear();
00670     unlock();
00671     pthread_mutex_destroy(&mutex_);
00672   }
00675   void clear() {
00676     DbField *tmp;
00677     lock();
00678     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00679       tmp = *i;
00680       unlock();
00681       tmp->setRequest(false);
00682       tmp->setUpdate(false);
00683       tmp->setBoolType(false);
00684       tmp->setIntType(0);
00685       tmp->setFloatType(0);
00686       tmp->setStringType("");
00687       tmp->setStringLen(0);
00688       tmp->setDateType(0);
00689       tmp->setIpType(UNKNOWN_IP);
00690       lock();
00691     }
00692     unlock();
00693   }
00696   void set_request(const string n) {
00697     DbField *tmp;
00698     lock();
00699     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00700       tmp = *i;
00701       if(tmp->getName() == n)
00702         tmp->setRequest(true);
00703     }
00704     unlock();
00705   }
00708   void set_update(const string n) {
00709     DbField *tmp;
00710     lock();
00711     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00712       tmp = *i;
00713       if(tmp->getName() == n)
00714         tmp->setUpdate(true);
00715     }
00716     unlock();
00717   }
00720   void add(const string n,const string d,const string df,bool v,int ix=0) {
00721     DbField *tmp;
00722     lock();
00723     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00724       tmp = *i;
00725       if(tmp->getName() == n) {
00726         tmp->setBoolType(v);
00727         unlock();
00728         return;
00729       }
00730     }
00731     f_.push_back(new DbField(n,d,df,v,ix));
00732     unlock();
00733   }
00736   void add(const string n,bool v) {
00737     add(n,"","",v);
00738   }
00741   void add(const string n,const string d,const string df,int v,int ix=0) {
00742     DbField *tmp;
00743     lock();
00744     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00745       tmp = *i;
00746       if(tmp->getName() == n) {
00747         tmp->setIntType((unsigned long int)v);
00748         unlock();
00749         return;
00750       }
00751     }
00752     f_.push_back(new DbField(n,d,df,v,ix));
00753     unlock();
00754   }
00757   void add(const string n,int v) {
00758     add(n,"","",v);
00759   }
00762   void add(const string n,const string d,const string df,unsigned int v,int ix=0) {
00763     DbField *tmp;
00764     lock();
00765     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00766       tmp = *i;
00767       if(tmp->getName() == n) {
00768         tmp->setIntType((unsigned long int)v);
00769         unlock();
00770         return;
00771       }
00772     }
00773     f_.push_back(new DbField(n,d,df,v,ix));
00774     unlock();
00775   }
00778   void add(const string n,unsigned int v) {
00779     add(n,"","",v);
00780   }
00783   void add(const string n,const string d,const string df,unsigned long int v,int ix=0) {
00784     DbField *tmp;
00785     lock();
00786     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00787       tmp = *i;
00788       if(tmp->getName() == n) {
00789         tmp->setIntType(v);
00790         unlock();
00791         return;
00792       }
00793     }
00794     f_.push_back(new DbField(n,d,df,v,ix));
00795     unlock();
00796   }
00799   void add(const string n,unsigned long int v) {
00800     add(n,"","",v);
00801   }
00804   void add(const string n,const string d,const string df,float v,int ix=0) {
00805     DbField *tmp;
00806     lock();
00807     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00808       tmp = *i;
00809       if(tmp->getName() == n) {
00810         tmp->setFloatType(v);
00811         unlock();
00812         return;
00813       }
00814     }
00815     f_.push_back(new DbField(n,d,df,v,ix));
00816     unlock();
00817   }
00820   void add(const string n,float v) {
00821     add(n,"","",v);
00822   }
00825   void add(const string n,const string d,const string df,string v,int l,int ix=0) {
00826     DbField *tmp;
00827     lock();
00828     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00829       tmp = *i;
00830       if(tmp->getName() == n) {
00831         tmp->setStringType(v);
00832         unlock();
00833         return;
00834       }
00835     }
00836     f_.push_back(new DbField(n,d,df,v,l,ix));
00837     unlock();
00838   }
00841   void add(const string n,string v,int l=0) {
00842     add(n,"","",v,l);
00843   }
00846   void add(const string n,const string d,const string df,char *v,int l,int ix=0) {
00847     DbField *tmp;
00848     lock();
00849     string stmp = v;
00850     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00851       tmp = *i;
00852       if(tmp->getName() == n) {
00853         tmp->setStringType(stmp);
00854         unlock();
00855         return;
00856       }
00857     }
00858     f_.push_back(new DbField(n,d,df,stmp,l,ix));
00859     unlock();
00860   }
00863   void add(const string n,char *v,int l=0) {
00864     add(n,"","",v,l);
00865   }
00868   void add(const string n,const string d,const string df,time_t v,int ix=0) {
00869     DbField *tmp;
00870     lock();
00871     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00872       tmp = *i;
00873       if(tmp->getName() == n) {
00874         tmp->setDateType(v);
00875         unlock();
00876         return;
00877       }
00878     }
00879     f_.push_back(new DbField(n,d,df,v,ix));
00880     unlock();
00881   }
00884   void add(const string n,time_t v) {
00885     add(n,"","",v);
00886   }
00889   void add(const string n,const string d,const string df,ipaddr v,int ix=0) {
00890     DbField *tmp;
00891     lock();
00892     for(list<DbField*>::iterator i=f_.begin();i!=f_.end();i++) {
00893       tmp = *i;
00894       if(tmp->getName() == n) {
00895         tmp->setIpType(v);
00896         unlock();
00897         return;
00898       }
00899     }
00900     f_.push_back(new DbField(n,d,df,v,ix));
00901     unlock();
00902   }
00905   void add(const string n,ipaddr v) {
00906     add(n,"","",v);
00907   }
00910   string get_name(int n) {
00911     string ret;
00912     lock();
00913     if(f_.size() > 0 && (int)f_.size() > n) {
00914       DbField *tmp = 0;
00915       int count = 0;
00916       list<DbField*>::const_iterator i;
00917       for(i=f_.begin();i!=f_.end();i++,count++) {
00918         if(count == n) {
00919           tmp = *i;
00920           ret = tmp->getName();
00921           break;
00922         }
00923       }
00924     }
00925     unlock();
00926     return ret;
00927   }
00930   string get_descr(int n) {
00931     string ret;
00932     lock();
00933     if(f_.size() > 0 && (int)f_.size() > n) {
00934       DbField *tmp = 0;
00935       int count = 0;
00936       list<DbField*>::const_iterator i;
00937       for(i=f_.begin();i!=f_.end();i++,count++) {
00938         if(count == n) {
00939           tmp = *i;
00940           ret = tmp->getDescription();
00941           break;
00942         }
00943       }
00944     }
00945     unlock();
00946     return ret;
00947   }
00950   string get_defv(int n) {
00951     string ret;
00952     lock();
00953     if(f_.size() > 0 && (int)f_.size() > n) {
00954       DbField *tmp = 0;
00955       int count = 0;
00956       list<DbField*>::const_iterator i;
00957       for(i=f_.begin();i!=f_.end();i++,count++) {
00958         if(count == n) {
00959           tmp = *i;
00960           ret = tmp->getDefv();
00961           break;
00962         }
00963       }
00964     }
00965     unlock();
00966     return ret;
00967   }
00970   int get_type(int n) {
00971     int ret;
00972     lock();
00973     ret = 0;
00974     if(f_.size() > 0 && (int)f_.size() > n) {
00975       DbField *tmp = 0;
00976       int count = 0;
00977       list<DbField*>::const_iterator i;
00978       for(i=f_.begin();i!=f_.end();i++,count++) {
00979         if(count == n) {
00980           tmp = *i;
00981           ret = tmp->getT();
00982           break;
00983         }
00984       }
00985     }
00986     unlock();
00987     return ret;
00988   }
00991   int get_idx(int n) {
00992     int ret;
00993     lock();
00994     ret = 0;
00995     if(f_.size() > 0 && (int)f_.size() > n) {
00996       DbField *tmp = 0;
00997       int count = 0;
00998       list<DbField*>::const_iterator i;
00999       for(i=f_.begin();i!=f_.end();i++,count++) {
01000         if(count == n) {
01001           tmp = *i;
01002           ret = tmp->getIdx();
01003           break;
01004         }
01005       }
01006     }
01007     unlock();
01008     return ret;
01009   }
01012   bool get_request(int n) {
01013     bool ret;
01014     lock();
01015     ret = false;
01016     if(f_.size() > 0 && (int)f_.size() > n) {
01017       DbField *tmp = 0;
01018       int count = 0;
01019       list<DbField*>::const_iterator i;
01020       for(i=f_.begin();i!=f_.end();i++,count++) {
01021         if(count == n) {
01022           tmp = *i;
01023           ret = tmp->getRequest();
01024           break;
01025         }
01026       }
01027     }
01028     unlock();
01029     return ret;
01030   }
01033   bool get_update(int n) {
01034     bool ret;
01035     lock();
01036     ret = false;
01037     if(f_.size() > 0 && (int)f_.size() > n) {
01038       DbField *tmp = 0;
01039       int count = 0;
01040       list<DbField*>::const_iterator i;
01041       for(i=f_.begin();i!=f_.end();i++,count++) {
01042         if(count == n) {
01043           tmp = *i;
01044           ret = tmp->getUpdate();
01045           break;
01046         }
01047       }
01048     }
01049     unlock();
01050     return ret;
01051   }
01054   bool get(const string n,bool *v) {
01055     DbField *tmp;
01056     lock();
01057     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01058       tmp = *i;
01059       if(tmp->getName() == n) {
01060         if(tmp->getT() != 1) {
01061           unlock();
01062           return false;
01063         }
01064         *v = tmp->getBoolType();
01065         unlock();
01066         return true;
01067       }
01068     }
01069     unlock();
01070     return false;
01071   }
01074   void set(const string n,bool v) {
01075     DbField *tmp;
01076     lock();
01077     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01078       tmp = *i;
01079       if(tmp->getName() == n) {
01080         if(tmp->getT() != 1) {
01081           unlock();
01082           return;
01083         }
01084         tmp->setBoolType(v);
01085         unlock();
01086         return;
01087       }
01088     }
01089     unlock();
01090     return;
01091   }
01094   bool get(const string n,int *v) {
01095     DbField *tmp;
01096     lock();
01097     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01098       tmp = *i;
01099       if(tmp->getName() == n) {
01100         if(tmp->getT() != 2) {
01101           unlock();
01102           return false;
01103         }
01104         *v = tmp->getIntType();
01105         unlock();
01106         return true;
01107       }
01108     }
01109     unlock();
01110     return false;
01111   }
01114   void set(const string n,int v) {
01115     DbField *tmp;
01116     lock();
01117     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01118       tmp = *i;
01119       if(tmp->getName() == n) {
01120         if(tmp->getT() != 2) {
01121           unlock();
01122           return;
01123         }
01124         tmp->setIntType(v);
01125         unlock();
01126         return;
01127       }
01128     }
01129     unlock();
01130     return;
01131   }
01134   bool get(const string n,float *v) {
01135     DbField *tmp;
01136     lock();
01137     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01138       tmp = *i;
01139       if(tmp->getName() == n) {
01140         if(tmp->getT() != 3) {
01141           unlock();
01142           return false;
01143         }
01144         *v = tmp->getFloatType();
01145         unlock();
01146         return true;
01147       }
01148     }
01149     unlock();
01150     return false;
01151   }
01154   void set(const string n,float v) {
01155     DbField *tmp;
01156     lock();
01157     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01158       tmp = *i;
01159       if(tmp->getName() == n) {
01160         if(tmp->getT() != 3) {
01161           unlock();
01162           return;
01163         }
01164         tmp->setFloatType(v);
01165         unlock();
01166         return;
01167       }
01168     }
01169     unlock();
01170     return;
01171   }
01174   bool get(const string n,char *v) {
01175     DbField *tmp;
01176     lock();
01177     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01178       tmp = *i;
01179       if(tmp->getName() == n) {
01180         if(tmp->getT() != 4) {
01181           unlock();
01182           return false;
01183         }
01184         strncpy(v,tmp->getStringType().c_str(),300);
01185         unlock();
01186         return true;
01187       }
01188     }
01189     unlock();
01190     return false;
01191   }
01194   bool get(const string n,string *v) {
01195     DbField *tmp;
01196     lock();
01197     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01198       tmp = *i;
01199       if(tmp->getName() == n) {
01200         if(tmp->getT() != 4) {
01201           unlock();
01202           return false;
01203         }
01204         *v = tmp->getStringType();
01205         unlock();
01206         return true;
01207       }
01208     }
01209     unlock();
01210     return false;
01211   }
01214   int getslen(const string n) {
01215     DbField *tmp;
01216     int ret;
01217     lock();
01218     ret = 0;
01219     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01220       tmp = *i;
01221       if(tmp->getName() == n) {
01222         ret = tmp->getStringLen();
01223         unlock();
01224         return ret;
01225       }
01226     }
01227     unlock();
01228     return ret;
01229   }
01232   void set(const string n,string v) {
01233     DbField *tmp;
01234     lock();
01235     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01236       tmp = *i;
01237       if(tmp->getName() == n) {
01238         if(tmp->getT() != 4) {
01239           unlock();
01240           return;
01241         }
01242         tmp->setStringType(v);
01243         unlock();
01244         return;
01245       }
01246     }
01247     unlock();
01248     return;
01249   }
01252   bool get(const string n,time_t *v) {
01253     DbField *tmp;
01254     lock();
01255     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01256       tmp = *i;
01257       if(tmp->getName() == n) {
01258         if(tmp->getT() != 5) {
01259           unlock();
01260           return false;
01261         }
01262         *v = tmp->getDateType();
01263         unlock();
01264         return true;
01265       }
01266     }
01267     unlock();
01268     return false;
01269   }
01272   void set(const string n,time_t v) {
01273     DbField *tmp;
01274     lock();
01275     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01276       tmp = *i;
01277       if(tmp->getName() == n) {
01278         if(tmp->getT() != 5) {
01279           unlock();
01280           return;
01281         }
01282         tmp->setDateType(v);
01283         unlock();
01284         return;
01285       }
01286     }
01287     unlock();
01288     return;
01289   }
01293   bool get(const string n,ipaddr *v) {
01294     DbField *tmp;
01295     lock();
01296     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01297       tmp = *i;
01298       if(tmp->getName() == n) {
01299         if(tmp->getT() != 6) {
01300           unlock();
01301           return false;
01302         }
01303         *v = tmp->getIpType();
01304         unlock();
01305         return true;
01306       }
01307     }
01308     unlock();
01309     return false;
01310   }
01313   void set(const string n,ipaddr v) {
01314     DbField *tmp;
01315     lock();
01316     for(list<DbField*>::const_iterator i=f_.begin();i!=f_.end();i++) {
01317       tmp = *i;
01318       if(tmp->getName() == n) {
01319         if(tmp->getT() != 6) {
01320           unlock();
01321           return;
01322         }
01323         tmp->setIpType(v);
01324         unlock();
01325         return;
01326       }
01327     }
01328     unlock();
01329     return;
01330   }
01331 };
01332 
01333 #endif //__DB_MODULE_H__

Generated on Thu Jul 21 23:09:45 2005 for tacppd.kdevelop by doxygen 1.3.5