DurableTable.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 
00019 #ifndef __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00020 #error DurableTable.h must only be included from within DurableStore.h
00021 #endif
00022 
00028 template <typename _Type>
00029 class DurableTable {
00030 public:
00031     DurableTable(DurableTableImpl*   impl,
00032                  const std::string&  name,
00033                  DurableObjectCache<_Type>* cache)
00034         : impl_(impl), name_(name), cache_(cache) {}
00035     
00036     ~DurableTable()
00037     {
00038         delete impl_;
00039     }
00040 
00046     int del(const SerializableObject& key);
00047 
00051     size_t size();
00052 
00057     DurableIterator* itr() { return impl_->itr(); }
00058 
00062     DurableTableImpl* impl() { return impl_; }
00063 
00067     std::string name() { return name_; }
00068 
00072     DurableObjectCache<_Type>* cache() { return cache_; }
00073 
00074 protected:
00075     DurableTableImpl*   impl_;
00076     std::string         name_;
00077     DurableObjectCache<_Type>* cache_;
00078 
00079     int cleanup_put_flags(int flags);
00080 
00081 private:
00082     DurableTable();
00083     DurableTable(const DurableTable&);
00084 };
00085 
00090 template <typename _DataType>
00091 class SingleTypeDurableTable : public DurableTable<_DataType> {
00092 public:
00096     SingleTypeDurableTable(DurableTableImpl*   impl,
00097                            const std::string&  name,
00098                            DurableObjectCache<_DataType>* cache)
00099         : DurableTable<_DataType>(impl, name, cache) {}
00100 
00110     int put(const SerializableObject& key,
00111             const _DataType* data,
00112             int flags);
00113 
00127     int get(const SerializableObject& key,
00128             _DataType**               data,
00129             bool*                     from_cache = 0);
00130 
00135     int get_copy(const SerializableObject& key,
00136                  _DataType* data);
00137     
00138 private:
00139     // Not implemented on purpose -- can't copy
00140     SingleTypeDurableTable(const SingleTypeDurableTable&);
00141 };
00142 
00149 template <typename _BaseType, typename _Collection>
00150 class MultiTypeDurableTable : public DurableTable<_BaseType> {
00151 public:
00155     MultiTypeDurableTable(DurableTableImpl*   impl,
00156                           const std::string&  name,
00157                           DurableObjectCache<_BaseType>* cache)
00158         : DurableTable<_BaseType>(impl, name, cache) {}
00159     
00170     int put(const SerializableObject& key,
00171             TypeCollection::TypeCode_t type,
00172             const _BaseType* data,
00173             int flags);
00174 
00189     int get(const SerializableObject& key,
00190             _BaseType**               data,
00191             bool*                     from_cache = 0);
00192 
00198     static int new_object(TypeCollection::TypeCode_t typecode,
00199                           SerializableObject** generic_object);
00200 
00201 private:
00202     // Not implemented on purpose -- can't copy
00203     MultiTypeDurableTable(const MultiTypeDurableTable&);
00204 };
00205 
00217 class StaticTypedDurableTable : public DurableTable< SerializableObject > {
00218 public:
00224     StaticTypedDurableTable(DurableTableImpl*   impl,
00225                             const std::string&  name)
00226         : DurableTable< SerializableObject >(impl, name, 0) {}
00227     
00228     
00229     template<typename _Type>
00230     int put(const SerializableObject& key, const _Type* data, int flags);
00231 
00232     template<typename _Type>
00233     int get(const SerializableObject& key, _Type** data);
00234 
00235 private:
00236     // Not implemented on purpose -- can't copy
00237     StaticTypedDurableTable(const StaticTypedDurableTable&);
00238 };

Generated on Sat Sep 8 08:43:27 2007 for DTN Reference Implementation by  doxygen 1.5.3