00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019
00020
00021 #include "SOMELibCatalog.h"
00022 #include "limits.h"
00023 #include <algorithm>
00024 #ifdef _DEBUG
00025 #include <iostream>
00026 #endif
00027
00028 SOME::LibCatalog::LibCatalog(SOME::BasicDynLib* l):
00029 lib(l),
00030 class_index_cache(UINT_MAX)
00031 {
00032 typedef void (*initSOMELibCatalog_FUNC)(SOME::LibCatalog*);
00033 initSOMELibCatalog_FUNC foo = (initSOMELibCatalog_FUNC) l->getFunction("initSOMELibCatalog");
00034 (*foo)(this);
00035 }
00036
00037 SOME::LibCatalog::~LibCatalog()
00038 {
00039
00040 }
00041
00042
00043
00044 const std::string& SOME::LibCatalog::getPath() const
00045 {
00046 return lib->getFilePath();
00047 }
00048
00049 void SOME::LibCatalog::setLibTitle(const std::string& t)
00050 {
00051 title = t;
00052 }
00053
00054 void SOME::LibCatalog::setVersion(const std::string& v)
00055 {
00056 version = v;
00057 }
00058
00059 SOME::ClassCatalog *SOME::LibCatalog::addClassCatalog(const std::string& classname, const std::string& category, SOME::ClassCatalog::ConstructFunc def, SOME::ClassCatalog::ConstructFunc one, SOME::ClassCatalog::ConstructFunc two)
00060 {
00061 #ifdef _DEBUG
00062 std::cout << "Adding class: " << classname << ", category: " << category << std::endl;
00063 #endif
00064 SOME::ClassCatalog class_info(classname, category, def, one, two);
00065
00066
00067 classes.push_back(class_info);
00068
00069 return &classes.back();
00070 }
00071
00072 bool SOME::LibCatalog::hasClass(const std::string& classname)
00073 {
00074 for (ClassContainer::size_type i = 0; i < classes.size(); i++)
00075 {
00076 if (classes[i].getClassName() == classname)
00077 {
00078 class_index_cache = i;
00079 return true;
00080 }
00081 }
00082 class_index_cache = UINT_MAX;
00083 return false;
00084 }
00085
00086 const SOME::ClassCatalog& SOME::LibCatalog::getClass(const std::string& classname)
00087 {
00088 if (class_index_cache != UINT_MAX && class_index_cache < classes.size())
00089 if (classes[class_index_cache].getClassName() == classname)
00090 return classes[class_index_cache];
00091
00092 for (ClassContainer::size_type i = 0; i < classes.size(); i++)
00093 {
00094 if (classes[i].getClassName() == classname)
00095 {
00096 class_index_cache = i;
00097 return classes[i];
00098 }
00099 }
00100
00101 throw ClassDoesNotExist(title, classname);
00102 }
00103
00104 SOME::LibCatalog::ClassContainer SOME::LibCatalog::getCategory(const std::string& category)
00105 {
00106 ClassContainer results;
00107
00108 for (ClassContainer::size_type i = 0; i < classes.size(); i++)
00109 {
00110
00111 if (classes[i].getCategory() == category)
00112 results.push_back(classes[i]);
00113 }
00114
00115 return results;
00116 }
00117
00118 SOME::LibCatalog::ClassContainer SOME::LibCatalog::getByCategory(const std::string& key, const std::string& value )
00119 {
00120 ClassContainer results;
00121
00122 for (ClassContainer::size_type i = 0; i < classes.size(); i++)
00123 {
00124 if (classes[i].infoEquals(key, value))
00125 results.push_back(classes[i]);
00126 }
00127
00128 return results;
00129 }
00130
00131 SOME::LibCatalog::ClassContainer SOME::LibCatalog::getByCategory( std::map < std::string, std::string > & keys )
00132 {
00133 ClassContainer results;
00134
00135 for (ClassContainer::size_type i = 0; i < classes.size(); i++)
00136 {
00137 std::map < std::string, std::string > ::iterator i2 = keys.begin();
00138 bool match = true;
00139 for (; match && i2 != keys.end(); i2++ )
00140 {
00141 match = classes[i].infoEquals((*i2).first, (*i2).second);
00142
00143 }
00144
00145 if (match)
00146 results.push_back(classes[i]);
00147 }
00148
00149 return results;
00150 }
00151
00152 std::set < std::string > SOME::LibCatalog::enumCategory( const std::string& key )
00153 {
00154 std::set < std::string > results;
00155 for (ClassContainer::size_type i = 0; i < classes.size(); i++)
00156 {
00157
00158 results.insert(classes[i].getCategory(key));
00159 }
00160
00161 return results;
00162 }
00163
00164 std::set < std::string > SOME::LibCatalog::enumCategory( const std::string& key, std::map < std::string, std::string > &catmap )
00165 {
00166 std::set < std::string > results;
00167 for (ClassContainer::size_type i = 0; i < classes.size(); i++)
00168 {
00169 std::map < std::string, std::string > ::iterator i2 = catmap.begin();
00170 bool match = true;
00171 for (; match && i2 != catmap.end(); i2++ )
00172 {
00173 match = classes[i].infoEquals((*i2).first, (*i2).second);
00174
00175 }
00176
00177
00178 if (match)
00179 results.insert(classes[i].getCategory(key));
00180 }
00181
00182 return results;
00183 }