00001 00002 // File: gnSourceFactory.h 00003 // Purpose: Manage data sources 00004 // Description: Manages data sources by tracking open files/databases/URLs 00005 // Changes: 00006 // Version: libGenome 0.5.1 00007 // Author: Aaron Darling 00008 // Modified by: 00009 // Copyright: (c) Aaron Darling 00010 // Licenses: See COPYING file for details 00012 #ifndef _gnSourceFactory_h_ 00013 #define _gnSourceFactory_h_ 00014 00015 #include "gn/gnDefs.h" 00016 00017 #include <string> 00018 #include <vector> 00019 #include <map> 00020 #include "gn/gnBaseSource.h" 00021 00037 class GNDLLEXPORT gnSourceFactory{ 00038 public: 00039 ~gnSourceFactory(); 00040 00045 static gnSourceFactory* GetSourceFactory(); 00046 // Plugin Sources 00051 uint32 GetSourceClassListSize() const; 00057 boolean DelSourceClass( const string& ext ); 00063 gnBaseSource* GetSourceClass( const string& ext ) const; 00069 gnBaseSource* MatchSourceClass( const string& sourceStr ) const; 00075 boolean HasSourceClass( const string& ext ) const; 00083 boolean SetSourceClass( const string& ext, const gnBaseSource& source ); 00089 boolean SetDefaultSourceClass( const gnBaseSource* source ); 00094 gnBaseSource* GetDefaultSourceClass() const; 00095 // Directory paths to search for sources 00100 uint32 GetPathListSize() const; 00106 boolean AddPath( const string& path ); 00112 boolean DelPath( uint32 i ); 00119 boolean InsPath( const string& path, uint32 i ); 00125 string GetPath( uint32 i ) const; 00131 boolean HasPath( string path ) const; 00132 // Sources 00137 uint32 GetSourceListSize() const; 00145 gnBaseSource* AddSource( const string& sourceStr, boolean searchPaths = true ); 00151 gnBaseSource* GetSource( uint32 i ) const; 00158 void DelSource( uint32 i ); 00165 boolean DelSource( const gnBaseSource* source ); 00172 gnBaseSource* HasSource( string sourceStr, boolean searchPaths = true ) const; 00173 00174 private: 00175 gnSourceFactory(); 00176 gnSourceFactory(gnSourceFactory& gnsf); 00177 gnSourceFactory& operator=(gnSourceFactory& gnsf); 00178 00179 boolean PathExists( string path ) const; 00180 static boolean GetURL( const string& urlStr, string& localFile ); 00181 00182 vector< string > m_pathList; 00183 vector< gnBaseSource* > m_sourceList; 00184 map< string, gnBaseSource* > m_sourceClassList; 00185 gnBaseSource* m_pDefaultSourceClass; 00186 };//class gnSourceFactory 00187 00188 inline 00189 gnSourceFactory* gnSourceFactory::GetSourceFactory() 00190 { 00191 //use construct on first use method to avoid the static constructor 00192 //initialization fiasco... 00193 static gnSourceFactory* m_sSourceFactory = new gnSourceFactory(); 00194 return m_sSourceFactory; 00195 } 00196 00197 // Plugin Sources 00198 inline 00199 uint32 gnSourceFactory::GetSourceClassListSize() const 00200 { 00201 return m_sourceClassList.size(); 00202 } 00203 inline 00204 boolean gnSourceFactory::SetDefaultSourceClass( const gnBaseSource* source ) 00205 { 00206 if(m_pDefaultSourceClass != NULL){ 00207 delete m_pDefaultSourceClass; 00208 } 00209 m_pDefaultSourceClass = source->Clone(); 00210 return true; 00211 } 00212 inline 00213 gnBaseSource* gnSourceFactory::GetDefaultSourceClass() const 00214 { 00215 return m_pDefaultSourceClass; 00216 } 00217 00218 // Directory paths to search for sources 00219 inline 00220 uint32 gnSourceFactory::GetPathListSize() const 00221 { 00222 return m_pathList.size(); 00223 } 00224 inline 00225 uint32 gnSourceFactory::GetSourceListSize() const 00226 { 00227 return m_sourceList.size(); 00228 } 00229 00230 00231 #endif 00232 // _gnSourceFactory_h_