Main Page   Class Hierarchy   Compound List   File List   Compound Members  

SOMELibFactory.cpp

00001 /********************************************************************
00002 ** Copyright (C) 2000 SOMELib Project
00003 **
00004 ** This library is free software; you can redistribute it and/or
00005 ** modify it under the terms of the GNU Library General Public
00006 ** License as published by the Free Software Foundation; either
00007 ** version 2 of the License, or (at your option) any later version.
00008 **
00009 ** This library is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 ** Library General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU Library General Public
00015 ** License along with this library; if not, write to the
00016 ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017 ** Boston, MA  02111-1307, USA.
00018 **
00019 *******************************************************************/
00020 
00021 #include "SOMELibFactory.h"
00022 #include <algorithm>
00023 
00024 SOME::LibFactory& SOME::getLibFactory()
00025 {
00026     static SOME::LibFactory the_instance;
00027     return the_instance;
00028 }
00029 
00030 SOME::LibFactory::LibFactory()
00031 {}
00032 
00033 
00034 
00035 namespace
00036 {
00037 class PathExists
00038 {
00039 public:
00040 PathExists(const std::string& p): path(p)
00041     {}
00042 
00043 
00044     bool operator()(const SOME::LibCatalog& lib) const
00045     {
00046         return lib.getPath() == path;
00047     }
00048 private:
00049     const std::string& path;
00050 };
00051 }
00052 
00053 void SOME::LibFactory::addLib(const std::string& path)
00054 {
00055     //check to see if this lib is already loaded
00056     if (std::find_if (libs.begin(), libs.end(), PathExists(path)) != libs.end())
00057         return ;
00058 
00059     BasicDynLib* new_lib = newDynLib();
00060     if (new_lib->loadLibrary(path.c_str()))
00061         libs.push_back(SOME::LibCatalog(new_lib));
00062 }
00063 
00064 //Adds libs specified by the SOME::Path object (This can be whole dirs)
00065 void SOME::LibFactory::addLib(Path& path)
00066 {
00067     Path::iterator it;
00068     for( it=path.begin(); it!=path.end(); it++ )
00069         addLib( *it );
00070 }
00071 
00072 const SOME::ClassCatalog& SOME::LibFactory::getClassCatalog(const std::string& classname)
00073 {
00074     LibContainer::iterator iter = libs.begin();
00075     for (; iter != libs.end(); iter++)
00076     {
00077         if (iter->hasClass(classname))
00078             return iter->getClass(classname);
00079     }
00080 
00081     throw ClassDoesNotExist(classname);
00082 }
00083 
00084 std::vector < SOME::ClassCatalog > SOME::LibFactory::getCategory(const std::string& category)
00085 {
00086     std::vector < SOME::ClassCatalog > results;
00087 
00088     LibContainer::iterator iter = libs.begin();
00089     for (; iter != libs.end(); iter++)
00090     {
00091         const std::vector < SOME::ClassCatalog > & lib_results = iter->getCategory(category);
00092         std::copy(lib_results.begin(), lib_results.end(), std::back_inserter(results));
00093     }
00094 
00095     return results;
00096 }
00097 
00098 std::vector < SOME::ClassCatalog > SOME::LibFactory::getByCategory(const std::string& key, const std::string& value)
00099 {
00100     std::vector < SOME::ClassCatalog > results;
00101 
00102     LibContainer::iterator iter = libs.begin();
00103     for (; iter != libs.end(); iter++)
00104     {
00105         const std::vector < SOME::ClassCatalog > & lib_results = iter->getByCategory(key, value);
00106         std::copy(lib_results.begin(), lib_results.end(), std::back_inserter(results));
00107     }
00108 
00109     return results;
00110 }
00111 
00112 std::vector < SOME::ClassCatalog > SOME::LibFactory::getByCategory( std::map < std::string, std::string > &keys )
00113 {
00114     std::vector < SOME::ClassCatalog > results;
00115 
00116     LibContainer::iterator iter = libs.begin();
00117     for (; iter != libs.end(); iter++)
00118     {
00119         const std::vector < SOME::ClassCatalog > & lib_results = iter->getByCategory( keys );
00120         std::copy(lib_results.begin(), lib_results.end(), std::back_inserter(results));
00121     }
00122 
00123     return results;
00124 }
00125 
00126 std::set < std::string > SOME::LibFactory::enumCategory(const std::string& key)
00127 {
00128     std::set < std::string > results;
00129 
00130     LibContainer::iterator iter = libs.begin();
00131     for (; iter != libs.end(); iter++)
00132     {
00133         const std::set < std::string > & lib_results = iter->enumCategory(key);
00134 
00135         std::copy(lib_results.begin(), lib_results.end(), std::inserter(results, results.end()));
00136     }
00137 
00138     return results;
00139 }
00140 
00141 std::set < std::string > SOME::LibFactory::enumCategory(const std::string& key, std::map < std::string, std::string > &catmap)
00142 {
00143     std::set < std::string > results;
00144 
00145     LibContainer::iterator iter = libs.begin();
00146     for (; iter != libs.end(); iter++)
00147     {
00148         const std::set < std::string > & lib_results = iter->enumCategory(key, catmap);
00149 
00150         std::copy(lib_results.begin(), lib_results.end(), std::inserter(results, results.end()));
00151     }
00152 
00153     return results;
00154 }
00155 
00156 std::string SOME::LibFactory::getLibExtension()
00157 {
00158 #ifdef USE_SOME_UNIX_SO
00159     return ".so";
00160 #endif
00161 #ifdef USE_SOME_WINDOWS_DLL
00162     return ".dll";
00163 #endif
00164 #ifdef USE_SOME_HPUX_SL
00165     return ".sl";
00166 #endif
00167 }

Generated at Fri Dec 8 14:24:48 2000 for SOMELib by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000