ValueCache.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 #include <map>
00026 
00027 namespace eyedb {
00028 
00029   class ValueItem {
00030 
00031   public:
00032     ValueItem(Object *o, const Value &, Collection::ItemId, int state);
00033 
00034     void setState(int state);
00035     int getState() const {return state;}
00036 
00037     const Value& getValue() const {return v;}
00038     Collection::ItemId getId() const {return id;}
00039 
00040     void release();
00041 
00042     void incRef() {refcnt++;}
00043 
00044   private:
00045     Object *o;
00046     Value v;
00047     Collection::ItemId id;
00048     int state;
00049     unsigned int refcnt;
00050     ~ValueItem();
00051   };
00052 
00053   class ValueCache {
00054 
00055   public:
00056     static Collection::ItemId DefaultItemID;
00057 
00058     ValueCache(Object *);
00059 
00060     Status insert(const Value &, Collection::ItemId, int state);
00061 
00062     Status suppress(ValueItem *item);
00063 
00064     ValueItem *get(Collection::ItemId);
00065     ValueItem *get(const Value &);
00066 
00067     void setObject(Object *_o) {o = _o;}
00068 
00069     void empty();
00070 
00071     typedef std::map<Value, ValueItem *> ValueMap;
00072     typedef std::map<Collection::ItemId, ValueItem *> IdMap;
00073 
00074     typedef std::map<Value, ValueItem *>::iterator ValueMapIterator;
00075     typedef std::map<Collection::ItemId, ValueItem *>::iterator IdMapIterator;
00076 
00077     unsigned int size() const {return val_map.size();}
00078 
00079     ValueMap &getValueMap() {return val_map;}
00080     IdMap &getIdMap() {return id_map;}
00081     void trace();
00082 
00083     // bwc
00084     Status suppressOid(ValueItem *item) {return suppress(item);}
00085     Status suppressObject(ValueItem *item) {return suppress(item);}
00086     Status suppressData(ValueItem *item) {return suppress(item);}
00087     Status setState(int state);
00088     ValueItem *get(Data data, Size item_size);
00089     Status insert(const eyedbsm::Oid *oid, Collection::ItemId id, int state) {
00090       return insert(Value(*oid), id, state);
00091     }
00092     // ...
00093 
00094     ~ValueCache();
00095 
00096   private:
00097     Object *o;
00098     //std::map<Value, ValueItem *> val_map;
00099     //std::map<Collection::ItemId, ValueItem *> id_map;
00100     ValueMap val_map;
00101     IdMap id_map;
00102     Collection::ItemId current_id;
00103   };
00104 }

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