00001 #include "AIDA_TreeFactory.h"
00002 #include "AIDA_Tree.h"
00003 #include "AIDA_Dev/IDevAnalysisFactory.h"
00004 #include "AIDA_Dev/IStoreFactory.h"
00005 #include <memory>
00006 #include <stdexcept>
00007
00008 #ifdef ANAPHE_TREE_NO_EXCEPTIONS_TO_USER
00009 #include <exception>
00010 #include <iostream>
00011 #define TREE_REPORT_ERROR( XXX ) std::cerr << XXX << std::endl
00012 #endif
00013
00014 Anaphe::AIDA_Tree_native::AIDA_TreeFactory::AIDA_TreeFactory()
00015 {}
00016
00017 Anaphe::AIDA_Tree_native::AIDA_TreeFactory::~AIDA_TreeFactory()
00018 {}
00019
00020 AIDA::ITree*
00021 Anaphe::AIDA_Tree_native::AIDA_TreeFactory::create()
00022 {
00023 std::string storeName = "";
00024 return this->create( storeName );
00025 }
00026
00027 AIDA::ITree*
00028 Anaphe::AIDA_Tree_native::AIDA_TreeFactory::create( const std::string & storeName,
00029 const std::string & storeType,
00030 bool readOnly,
00031 bool createNew,
00032 const std::string & options )
00033 {
00034 #ifdef ANAPHE_TREE_NO_EXCEPTIONS_TO_USER
00035 try {
00036 #endif
00037
00038 std::auto_ptr<AIDA::Dev::IDevAnalysisFactory> af( dynamic_cast<AIDA::Dev::IDevAnalysisFactory*>( AIDA_createAnalysisFactory() ) );
00039 if ( ! af.get() ) {
00040 throw std::runtime_error( "The tree factory could not retrieve an analysis factory" );
00041 }
00042 std::string m_storeType = storeType;
00043 if ( m_storeType == "" ) m_storeType = "Memory";
00044 AIDA::Dev::IStoreFactory* sf = 0;
00045 sf = af->storeFactory( m_storeType );
00046 if ( ! sf ) {
00047 throw std::runtime_error( "The tree factory could not create a factory for stores of type " + m_storeType );
00048 }
00049 AIDA::Dev::IStore* m_store = 0;
00050 m_store = sf->createStore( storeName, readOnly, createNew, options );
00051 if ( ! m_store ) {
00052 throw std::runtime_error( "The tree factory could not create a store of type " + m_storeType );
00053 }
00054 return new Anaphe::AIDA_Tree_native::AIDA_Tree( m_store );
00055 #ifdef ANAPHE_TREE_NO_EXCEPTIONS_TO_USER
00056 }
00057 catch( std::exception& e ) {
00058 TREE_REPORT_ERROR( e.what() );
00059 return 0;
00060 }
00061 #endif
00062 }