InternalKeyDurableTable.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) 2006 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 #ifndef _INTERNAL_KEY_DURABLE_TABLE_H_
00039 #define _INTERNAL_KEY_DURABLE_TABLE_H_
00040 
00041 #include "../debug/Logger.h"
00042 #include "../debug/DebugUtils.h"
00043 #include "DurableStore.h"
00044 #include "StorageConfig.h"
00045 
00046 namespace oasys {
00047 
00071 template <typename _ShimType, typename _KeyType, typename _DataType>
00072 class InternalKeyDurableTable : public Logger {
00073 public:
00074     InternalKeyDurableTable(const char* classname,
00075                             const char* logpath,
00076                             const char* datatype,
00077                             const char* table_name);
00078 
00079     virtual ~InternalKeyDurableTable();
00080     
00084     int do_init(const StorageConfig& cfg,
00085                 DurableStore*        store);
00086 
00090     void close();
00091     
00092     bool add(_DataType* data);
00093     
00094     _DataType* get(_KeyType id);
00095     
00096     bool update(_DataType* data);
00097 
00098     bool del(_KeyType id);
00099 
00103     class iterator {
00104     public:
00105         typedef class InternalKeyDurableTable<_ShimType,
00106                                               _KeyType,
00107                                               _DataType> table_t;
00108 
00109         virtual ~iterator();
00110 
00117         int next();
00118 
00122         void begin() { next(); }
00123 
00127         bool more() { return !done_; }
00128 
00132         _KeyType cur_val() { return cur_val_.value(); }
00133 
00134     private:
00135         friend class InternalKeyDurableTable<_ShimType,
00136                                              _KeyType,
00137                                              _DataType>;
00138 
00139         iterator(table_t* table, DurableIterator* iter);
00140 
00141         table_t*  table_;       
00142         DurableIterator* iter_; 
00143         _ShimType cur_val_;     
00144         bool      done_;        
00145     };
00146     
00151     iterator* new_iterator()
00152     {
00153         return new iterator(this, table_->itr());
00154     }
00155 
00156 protected:
00157     SingleTypeDurableTable<_DataType>* table_;
00158     const char* datatype_;
00159     const char* table_name_;
00160 };
00161 
00162 #include "InternalKeyDurableTable.tcc"
00163 
00164 } // namespace oasys
00165 
00166 #endif /* _INTERNAL_KEY_DURABLE_TABLE_H_ */

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