Oid.h

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB 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 GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #ifndef _EYEDB_OID_H
00026 #define _EYEDB_OID_H
00027 
00028 #include <iostream>
00029 
00030 namespace eyedb {
00031 
00037   class Oid;
00038 
00039   std::ostream& operator<<(std::ostream&, const Oid &);
00040   std::ostream& operator<<(std::ostream&, const Oid *);
00041 
00045   class Oid {
00046 
00047     // ----------------------------------------------------------------------
00048     // Oid Interface
00049     // ----------------------------------------------------------------------
00050 
00051   public:
00055     Oid() {
00056       oid = nullOid.oid;
00057     }
00058 
00063     Oid(const Oid &_oid);
00064 
00069     Oid(const char *str);
00070 
00077     Oid(eyedbsm::Oid::NX nx, eyedbsm::Oid::DbID dbid,
00078         eyedbsm::Oid::Unique unique);
00079 
00084     eyedbsm::Oid::NX getNX() const     {return oid.getNX();}
00085 
00090     eyedbsm::Oid::DbID getDbid() const   {return oid.getDbID();}
00091 
00096     eyedbsm::Oid::Unique getUnique() const {return oid.getUnique();}
00097 
00098 
00103     const char *getString() const;
00104 
00109     const char *toString()  const {return getString();}
00110 
00111 
00117     Oid &operator =(const Oid &oid);
00118 
00124     bool operator <(const Oid &oid) const {
00125       if (getDbid() != oid.getDbid())
00126         return getDbid() < oid.getDbid();
00127       return getNX() < oid.getNX();
00128     }
00129 
00134     bool operator !() const {
00135       return !isValid() ? true : false;
00136     }
00137 
00142     const eyedbsm::Oid *getOid() const {return &oid;}
00143 
00148     void setOid(const eyedbsm::Oid&);
00149 
00154     void setOid(const eyedbsm::Oid *_oid) {oid = *_oid;}
00155 
00160     eyedbsm::Oid *getOid() {return &oid;}
00161 
00162 
00167     Bool isValid() const {
00168       return oid.getNX() ? True : False;
00169     }    
00170 
00175     void invalidate() {
00176 
00177       oid = nullOid.oid;
00178     }
00179 
00185     Bool compare(const Oid &_oid) const {
00186       return IDBBOOL(!memcmp(&oid, &_oid.oid, sizeof(oid)));
00187     }
00188 
00194     Bool operator==(const Oid &_oid) const {
00195       return IDBBOOL(!memcmp(&oid, &_oid.oid, sizeof(oid)));
00196     }
00197 
00203     Bool operator!=(const Oid &_oid) const {
00204       return IDBBOOL(memcmp(&oid, &_oid.oid, sizeof(oid)));
00205     }
00206 
00207     static const Oid nullOid;
00208 
00209     ~Oid() {}
00210 
00211   private:
00212     eyedbsm::Oid oid;
00213 
00214   public: /* restricted */
00215     Oid(const eyedbsm::Oid &);
00216     Oid(const eyedbsm::Oid *);
00217   };
00218 
00219   class Collection;
00220   class OidList;
00221   class LinkedList;
00222   class LinkedListCursor;
00223 
00227   class OidArray {
00228 
00229   public:
00235     OidArray(const Oid *oids = NULL, int count = 0);
00236 
00241     OidArray(const Collection *coll);
00242 
00247     OidArray(const OidList &list);
00248 
00253     OidArray(const OidArray &oid_arr);
00254 
00260     OidArray& operator=(const OidArray &oid_arr);
00261 
00267     void set(const Oid *oids, int count);
00268 
00273     int getCount() const {return count;}
00274 
00275 
00281     Oid & operator[](int x) {
00282       return oids[x];
00283     }
00284 
00290     const Oid &operator[](int x) const {
00291       return oids[x];
00292     }
00293 
00298     OidList *toList() const;
00299 
00300     ~OidArray();
00301 
00302   private:
00303     int count;
00304     Oid *oids;
00305   };
00306 
00307   class OidListCursor;
00308 
00312   class OidList {
00313 
00314   public:
00318     OidList();
00319 
00324     OidList(const OidArray &oid_array);
00325 
00330     int getCount() const;
00331 
00336     void insertOid(const Oid &oid);
00337 
00342     void insertOidLast(const Oid &oid);
00343 
00348     void insertOidFirst(const Oid &oid);
00349 
00355     Bool suppressOid(const Oid &oid);
00356 
00362     Bool exists(const Oid &oid) const;
00363 
00367     void empty();
00368 
00373     OidArray *toArray() const;
00374 
00375     ~OidList();
00376 
00377   private:
00378     LinkedList *list;
00379     friend class OidListCursor;
00380   };
00381 
00385   class OidListCursor {
00386 
00387   public:
00392     OidListCursor(const OidList &oidlist);
00393 
00398     OidListCursor(const OidList *oidlist);
00399 
00405     Bool getNext(Oid &oid);
00406 
00407     ~OidListCursor();
00408 
00409   private:
00410     LinkedListCursor *c;
00411   };
00412 
00417 }
00418 
00419 #endif

Generated on Mon Dec 22 18:16:00 2008 for eyedb by  doxygen 1.5.3