DurableTable.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2005 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 
00039 
00040 #ifndef __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00041 #error DurableTable.h must only be included from within DurableStore.h
00042 #endif
00043 
00049 template <typename _Type>
00050 class DurableTable {
00051 public:
00052     DurableTable(DurableTableImpl*   impl,
00053                  const std::string&  name,
00054                  DurableObjectCache<_Type>* cache)
00055         : impl_(impl), name_(name), cache_(cache) {}
00056     
00057     ~DurableTable()
00058     {
00059         delete impl_;
00060     }
00061 
00067     int del(const SerializableObject& key);
00068 
00072     size_t size();
00073 
00078     DurableIterator* itr() { return impl_->itr(); }
00079 
00083     DurableTableImpl* impl() { return impl_; }
00084 
00088     std::string name() { return name_; }
00089 
00093     DurableObjectCache<_Type>* cache() { return cache_; }
00094 
00095 protected:
00096     DurableTableImpl*   impl_;
00097     std::string         name_;
00098     DurableObjectCache<_Type>* cache_;
00099 
00100     int cleanup_put_flags(int flags);
00101 
00102 private:
00103     DurableTable();
00104     DurableTable(const DurableTable&);
00105 };
00106 
00111 template <typename _DataType>
00112 class SingleTypeDurableTable : public DurableTable<_DataType> {
00113 public:
00117     SingleTypeDurableTable(DurableTableImpl*   impl,
00118                            const std::string&  name,
00119                            DurableObjectCache<_DataType>* cache)
00120         : DurableTable<_DataType>(impl, name, cache) {}
00121 
00131     int put(const SerializableObject& key,
00132             const _DataType* data,
00133             int flags);
00134 
00148     int get(const SerializableObject& key,
00149             _DataType**               data,
00150             bool*                     from_cache = 0);
00151 
00156     int get_copy(const SerializableObject& key,
00157                  _DataType* data);
00158     
00159 private:
00160     // Not implemented on purpose -- can't copy
00161     SingleTypeDurableTable(const SingleTypeDurableTable&);
00162 };
00163 
00170 template <typename _BaseType, typename _Collection>
00171 class MultiTypeDurableTable : public DurableTable<_BaseType> {
00172 public:
00176     MultiTypeDurableTable(DurableTableImpl*   impl,
00177                           const std::string&  name,
00178                           DurableObjectCache<_BaseType>* cache)
00179         : DurableTable<_BaseType>(impl, name, cache) {}
00180     
00191     int put(const SerializableObject& key,
00192             TypeCollection::TypeCode_t type,
00193             const _BaseType* data,
00194             int flags);
00195 
00210     int get(const SerializableObject& key,
00211             _BaseType**               data,
00212             bool*                     from_cache = 0);
00213 
00219     static int new_object(TypeCollection::TypeCode_t typecode,
00220                           SerializableObject** generic_object);
00221 
00222 private:
00223     // Not implemented on purpose -- can't copy
00224     MultiTypeDurableTable(const MultiTypeDurableTable&);
00225 };
00226 
00238 class StaticTypedDurableTable : public DurableTable< SerializableObject > {
00239 public:
00245     StaticTypedDurableTable(DurableTableImpl*   impl,
00246                             const std::string&  name)
00247         : DurableTable< SerializableObject >(impl, name, 0) {}
00248     
00249     
00250     template<typename _Type>
00251     int put(const SerializableObject& key, const _Type* data, int flags);
00252 
00253     template<typename _Type>
00254     int get(const SerializableObject& key, _Type** data);
00255 
00256 private:
00257     // Not implemented on purpose -- can't copy
00258     StaticTypedDurableTable(const StaticTypedDurableTable&);
00259 };

Generated on Fri Dec 22 14:47:58 2006 for DTN Reference Implementation by  doxygen 1.5.1