Go to the documentation of this file.00001 #ifndef INCLUDE_ORA_CONTAINER_H
00002 #define INCLUDE_ORA_CONTAINER_H
00003
00004 #include "Object.h"
00005 #include "Handle.h"
00006
00007 #include <typeinfo>
00008 #include <boost/shared_ptr.hpp>
00009
00010 namespace ora {
00011
00012 class IteratorBuffer;
00013 class DatabaseContainer;
00014
00015 class ContainerIterator {
00016
00017 public:
00018 ContainerIterator( Handle<IteratorBuffer>& iteratorBuffer );
00019
00020 ContainerIterator( const ContainerIterator& rhs );
00021
00022 virtual ~ContainerIterator();
00023
00024 ContainerIterator& operator=( const ContainerIterator& rhs );
00025
00026 Object getItem();
00027
00028 template <typename T> boost::shared_ptr<T> get();
00029
00030 int itemId();
00031
00032 bool next();
00033
00034 void reset();
00035
00036 private:
00037 boost::shared_ptr<void> getItemAsType( const std::type_info& asTypeInfo );
00038
00039 private:
00040 Handle<IteratorBuffer> m_buffer;
00041 };
00042
00043 class Container {
00044
00045 public:
00046 Container( Handle<DatabaseContainer>& dbContainer );
00047
00048 Container( const Container& rhs );
00049
00050 virtual ~Container();
00051
00052 Container& operator=( const Container& rhs );
00053
00054 int id();
00055
00056 const std::string& name();
00057
00058 const std::string& className();
00059
00060 const std::string& mappingVersion();
00061
00062 size_t size();
00063
00064 void extendSchema( const std::type_info& typeInfo );
00065
00066 template <typename T> void extendSchema();
00067
00068 ContainerIterator iterator();
00069
00070 Object fetchItem( int itemId );
00071
00072 template <typename T> boost::shared_ptr<T> fetch( int itemId );
00073
00074 int insertItem( const Object& data );
00075
00076 template <typename T> int insert( const T& data );
00077
00078 void updateItem( int itemId, const Object& data );
00079
00080 template <typename T> void update( int itemId, const T& data );
00081
00082 void erase( int itemId );
00083
00084 void flush();
00085
00086 void setItemName( const std::string& name, int itemId );
00087
00088 bool getNames( std::vector<std::string>& destination );
00089
00090 private:
00091 boost::shared_ptr<void> fetchItemAsType(int itemId, const std::type_info& asTypeInfo);
00092 int insertItem( const void* data, const std::type_info& typeInfo );
00093 void updateItem( int itemId, const void* data, const std::type_info& typeInfo );
00094
00095
00096
00097 private:
00098 Handle<DatabaseContainer> m_dbContainer;
00099 };
00100
00101 }
00102
00103 template <typename T>
00104 inline
00105 boost::shared_ptr<T> ora::ContainerIterator::get(){
00106 return boost::static_pointer_cast<T>( getItemAsType( typeid(T) ));
00107 }
00108
00109 template <typename T>
00110 inline
00111 void ora::Container::extendSchema(){
00112 extendSchema( typeid(T) );
00113 }
00114
00115 template <typename T>
00116 inline
00117 boost::shared_ptr<T> ora::Container::fetch( int itemId){
00118 return boost::static_pointer_cast<T>( fetchItemAsType( itemId, typeid(T) ));
00119 }
00120
00121 template <typename T>
00122 inline
00123 int ora::Container::insert( const T& data ){
00124 return insertItem( &data, typeid( data ) );
00125 }
00126
00127 template <typename T>
00128 inline
00129 void ora::Container::update( int itemId, const T& data ){
00130 return updateItem( itemId, &data, typeid( data ) );
00131 }
00132
00133 #endif