it_bus_pdk/persistent_string_map.h

00001 #ifndef _IT_BUS_PERSISTENT_STRING_MAP_H_
00002 #define _IT_BUS_PERSISTENT_STRING_MAP_H_
00003 
00004 // @Copyright 2004 IONA Technologies, Plc. All Rights Reserved.
00005 //
00006 
00007 #include <it_bus_pdk/persistent_map_base.h>
00008 
00009 namespace IT_Bus
00010 {
00011     class StringPersistenceHandler
00012     {
00013       public:
00014 
00015         IT_EXPLICIT StringPersistenceHandler(
00016             const IT_String& str
00017         ) :
00018             m_t(IT_CONST_CAST(IT_String&, str)),
00019             m_p(0),
00020             m_sz(0)
00021         {}
00022 
00023         IT_EXPLICIT StringPersistenceHandler(
00024             IT_String& str
00025         ) :
00026             m_t(str),
00027             m_p(0),
00028             m_sz(0)
00029         {}
00030         
00031         ~StringPersistenceHandler()
00032         {
00033             if (m_p != 0)
00034             {
00035                 char* p = IT_STATIC_CAST(char*, m_p);
00036                 delete [] p;
00037             }
00038         }
00039 
00040         void*&
00041         writebuf()
00042         {
00043             return m_p;
00044         }    
00045 
00046         void*
00047         readbuf()
00048         {
00049             const void* p = m_t.c_str();
00050             return IT_CONST_CAST(void*, p);
00051         }    
00052 
00053         IT_ULong&
00054         writebuflen()
00055         {
00056             return m_sz;
00057         }
00058 
00059         IT_ULong
00060         readbuflen() const
00061         {
00062             return m_t.length() + 1;
00063         }
00064 
00065         AllocFunc
00066         allocator()
00067         {
00068             return operator new;
00069         }
00070 
00071         void
00072         update_read_buffer_after_write()
00073         {
00074             if (m_p != 0)
00075             {
00076                 char* p = IT_STATIC_CAST(char*, m_p);
00077                 m_t = p;
00078                 operator delete(p);
00079                 m_p = 0;
00080             }
00081         }
00082 
00083       private:
00084         IT_String& m_t;
00085         void*      m_p;
00086         IT_ULong   m_sz;
00087     };
00088 
00089     template<class Data>
00090     class PersistentStringMap :
00091         private PersistentMapBase<IT_String, Data,
00092                                   StringPersistenceHandler,
00093                                   PODPersistenceHandler<Data> >
00094     {
00095       public:
00096         typedef PersistentMapBase<
00097             IT_String, Data,
00098             StringPersistenceHandler, PODPersistenceHandler<Data>
00099         > BaseClass;
00100 
00101         typedef IT_TYPENAME BaseClass::key_type             key_type;
00102         typedef IT_TYPENAME BaseClass::data_type            data_type;
00103         typedef IT_TYPENAME BaseClass::reference_type       reference_type;
00104         typedef IT_TYPENAME BaseClass::const_reference_type const_reference_type;
00105         typedef IT_TYPENAME BaseClass::value_type           value_type;
00106         typedef IT_TYPENAME BaseClass::size_type            size_type;
00107         typedef IT_TYPENAME BaseClass::difference_type      difference_type;
00108 
00109         typedef IT_TYPENAME BaseClass::iterator iterator;
00110 
00111         PersistentStringMap(
00112             const char* id,
00113             DBConfig*   cfg
00114         );
00115         PersistentStringMap(
00116             const char*       id,
00117             DBConfig*         cfg,
00118             const value_type* first,
00119             const value_type* last
00120         );
00121         PersistentStringMap(
00122             const PersistentStringMap<Data>& mp
00123         );
00124         ~PersistentStringMap();
00125 
00126         PersistentStringMap<Data>&
00127         operator=(
00128             const PersistentStringMap<Data>& mp
00129         );
00130 
00131         BaseClass::begin;
00132         BaseClass::end;
00133         BaseClass::insert;
00134         BaseClass::erase;
00135         BaseClass::find;
00136         BaseClass::empty;
00137         BaseClass::size;
00138     };
00139 }
00140 
00141 #if IT_SUPPORTS_COMPILE_TIME_INSTANTIATION
00142 #include <it_bus_pdk/persistent_string_map.cxx>
00143 #endif
00144 
00145 #endif  

Generated on Tue Mar 20 15:27:53 2007 for Artix by  doxygen 1.5.1-p1