CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CondCore/ORA/src/Container.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Container.h"
00002 #include "DatabaseContainer.h"
00003 #include "ClassUtils.h"
00004 
00005 ora::ContainerIterator::ContainerIterator():
00006   m_buffer(){
00007 }
00008 
00009 ora::ContainerIterator::ContainerIterator( Handle<IteratorBuffer>& iteratorBuffer ):
00010   m_buffer( iteratorBuffer ){
00011 }
00012 
00013 ora::ContainerIterator::ContainerIterator( const ContainerIterator& rhs ):
00014   m_buffer( rhs.m_buffer ){
00015 }
00016 
00017 ora::ContainerIterator::~ContainerIterator(){
00018 }
00019 
00020 ora::ContainerIterator& ora::ContainerIterator::operator=( const ContainerIterator& rhs ){
00021   if(this != &rhs ) m_buffer = rhs.m_buffer;
00022   return *this;
00023 }
00024 
00025 void ora::ContainerIterator::reset(){
00026   m_buffer->reset();
00027 }
00028 
00029 bool ora::ContainerIterator::next(){
00030   return m_buffer->next();
00031 }
00032 
00033 int ora::ContainerIterator::itemId(){
00034   return m_buffer->itemId();
00035 }
00036 
00037 ora::Object ora::ContainerIterator::getItem(){
00038   return Object( m_buffer->getItem(), m_buffer->type() );
00039 }
00040 
00041 boost::shared_ptr<void> ora::ContainerIterator::getItemAsType( const std::type_info& asTypeInfo ){
00042   Reflex::Type castType = ClassUtils::lookupDictionary( asTypeInfo );
00043   void* ptr = m_buffer->getItemAsType( castType );
00044   return boost::shared_ptr<void>( ptr, RflxDeleter( m_buffer->type() ) );
00045 }
00046 
00047 ora::Container::Container():
00048   m_dbContainer(){
00049 }
00050 
00051 ora::Container::Container( Handle<DatabaseContainer>& dbContainer ):
00052   m_dbContainer( dbContainer ){
00053 }
00054 
00055 ora::Container::Container( const Container& rhs ):
00056   m_dbContainer( rhs.m_dbContainer ){
00057 }
00058 
00059 ora::Container::~Container(){
00060 }
00061 
00062 ora::Container& ora::Container::operator=( const Container& rhs ){
00063   if(this != &rhs ) m_dbContainer = rhs.m_dbContainer;
00064   return *this;  
00065 }
00066 
00067 int ora::Container::id(){
00068   return m_dbContainer->id();
00069 }
00070 
00071 const std::string& ora::Container::name(){
00072   return m_dbContainer->name();
00073 }
00074 
00075 const std::string& ora::Container::className(){
00076   return m_dbContainer->className();
00077 }
00078 
00079 const std::string& ora::Container::mappingVersion(){
00080   return m_dbContainer->mappingVersion();
00081 }
00082 
00083 size_t ora::Container::size(){
00084   return m_dbContainer->size();
00085 }
00086 
00087 ora::ContainerIterator ora::Container::iterator(){
00088   Handle<IteratorBuffer> buff = m_dbContainer->iteratorBuffer();
00089   return ContainerIterator( buff );
00090 }
00091 
00092 void ora::Container::extendSchema( const std::type_info& typeInfo ){
00093   Reflex::Type type = ClassUtils::lookupDictionary( typeInfo );
00094   m_dbContainer->extendSchema( type );
00095 }
00096 
00097 void ora::Container::setAccessPermission( const std::string& principal, 
00098                                           bool forWrite ){
00099   m_dbContainer->setAccessPermission( principal, forWrite );
00100 }
00101 
00102 ora::Object ora::Container::fetchItem(int itemId){
00103   return Object( m_dbContainer->fetchItem(itemId), m_dbContainer->type() );
00104 }
00105 
00106 boost::shared_ptr<void> ora::Container::fetchItemAsType(int itemId,
00107                                                         const std::type_info& asTypeInfo){
00108   Reflex::Type asType = ClassUtils::lookupDictionary( asTypeInfo );
00109   void* ptr = m_dbContainer->fetchItemAsType(itemId, asType );
00110   if(!ptr) return boost::shared_ptr<void>();
00111   return boost::shared_ptr<void>( ptr, RflxDeleter( m_dbContainer->type() ) );
00112 }
00113 
00114 bool ora::Container::lock(){
00115   return m_dbContainer->lock();
00116 }
00117 
00118 bool ora::Container::isLocked(){
00119   return m_dbContainer->isLocked();
00120 }
00121 
00122 int ora::Container::insertItem( const Object& data ){
00123   const Reflex::Type& objType = data.type();
00124   if(!objType){
00125     throwException("Object class has not been found in the dictionary.",
00126                    "Container::insertItem");
00127   }
00128   return m_dbContainer->insertItem( data.address(), objType );
00129 }
00130 
00131 int ora::Container::insertItem( const void* data,
00132                                          const std::type_info& typeInfo ){
00133   Reflex::Type type = ClassUtils::lookupDictionary( typeInfo );
00134   return m_dbContainer->insertItem( data, type );
00135 }
00136 
00137 void ora::Container::updateItem( int itemId,
00138                                  const Object& data ){
00139   const Reflex::Type& objType = data.type();
00140   if(!objType){
00141     throwException("Object class has not been found in the dictionary.",
00142                    "Container::updateItem");
00143   }
00144   return m_dbContainer->updateItem( itemId, data.address(), objType );
00145 }
00146 
00147 void ora::Container::updateItem( int itemId,
00148                                  const void* data,
00149                                  const std::type_info& typeInfo ){
00150   Reflex::Type type = ClassUtils::lookupDictionary( typeInfo );
00151   m_dbContainer->updateItem( itemId, data, type );
00152 }
00153 
00154 void ora::Container::erase( int itemId ){
00155   m_dbContainer->erase(itemId );
00156 }
00157 
00158 void ora::Container::flush(){
00159   m_dbContainer->flush();
00160 }
00161 
00162 void ora::Container::setItemName( const std::string& name, 
00163                                   int itemId ){
00164   m_dbContainer->setItemName( name, itemId );
00165 }
00166 
00167 bool ora::Container::getNames( std::vector<std::string>& destination ){
00168   return m_dbContainer->getNames( destination );
00169 }
00170 
00171