#ifdef COMPILE__Getter_Function #ifndef OBJECT_TYPE #error object type undefined #error specify an object type using #define OBJECT_TYPE Object_Type #endif #ifndef PARAMETER_TYPE #error parameter type undefined #error specify a parameter type using #define PARAMETER_TYPE Parameter_Type #endif #ifndef EXACTMATCH #define EXACTMATCH true #endif #ifndef SORT_CRITERION #define SORT_CRITERION std::less #endif #include "ATOOLS/Org/Getter_Function.H" #include "ATOOLS/Org/STL_Tools.H" #include "ATOOLS/Org/Shell_Tools.H" #include "ATOOLS/Org/Exception.H" #include "ATOOLS/Org/Message.H" #include "ATOOLS/Org/MyStrStream.H" #include #include using namespace ATOOLS; template typename Getter_Function:: String_Getter_Map *Getter_Function:: s_getters=NULL; template bool Getter_Function:: s_exactmatch=EXACTMATCH; template Getter_Function:: Getter_Function(const std::string &name): m_display(true) { static bool initialized=false; if (!initialized || s_getters==NULL) { s_getters = new String_Getter_Map(); initialized=true; } #ifdef DEBUG__Getter_Function std::cout<<"Getter_Function::Getter_Function(..): " <<"Added getter '"< \""<find(name)); if (git!=s_getters->end()) { std::cout< {\n" <<" Doubled identifier \""<second).name())<<"'.\n " <<"This operation may lead to wrong results " <<"or a program crash.\n}"<erase(git); } s_getters->insert(std::pair(name,this)); } template Getter_Function::~Getter_Function() { if (s_getters==NULL) return; for (typename String_Getter_Map::iterator git=s_getters->begin(); git!=s_getters->end();++git) { if (git->second==this) { s_getters->erase(git); break; } } if (s_getters->empty()) { delete s_getters; s_getters=NULL; } } template void Getter_Function:: PrintInfo(std::ostream &str,const size_t width) const { str< ObjectType * Getter_Function:: operator()(const Parameter_Type ¶meters) const { std::cout<<"Getter_Function::operator(): " <<"Virtual function called."< void Getter_Function:: PrintGetterInfo(std::ostream &str,const size_t width, const std::string &indent, const std::string &separator, const std::string &lineend, const std::string &replacefrom, const std::string &replaceto) { if (s_getters==NULL) return; const IOS_BASE::fmtflags def=str.flags(); str.setf(IOS_BASE::left,IOS_BASE::adjustfield); for (typename String_Getter_Map::const_iterator git=s_getters->begin(); git!=s_getters->end();++git) { if (!git->second->m_display) continue; std::string escapedname=StringReplace(git->first,replacefrom,replaceto); str<second->PrintInfo(str,width); str< ObjectType *Getter_Function:: GetObject(const Parameter_Type ¶meters) const { return (*this)(parameters); } template ObjectType *Getter_Function:: GetObject(const std::string &name,const Parameter_Type ¶meters) { if (s_getters==NULL) return NULL; if (!s_exactmatch) { for (typename String_Getter_Map::reverse_iterator git=s_getters->rbegin(); git!=s_getters->rend();++git) { if ((name.length()==0 && git->first.length()==0) || (git->first.length()>0 && name.find(git->first)==0)) return (*git->second)(parameters); } return NULL; } typename String_Getter_Map::iterator git=s_getters->find(name); if (git!=s_getters->end()) return (*git->second)(parameters); return NULL; } template std::vector *> Getter_Function:: GetGetters(const std::string &name) { Getter_List list; if (s_getters==NULL) return list; for (typename String_Getter_Map::reverse_iterator git=s_getters->rbegin(); git!=s_getters->rend();++git) { if (name.length()==0 || (git->first.length()>0 && git->first.find(name)!=std::string::npos)) list.push_back(git->second); } return list; } template class ATOOLS::Getter_Function; #endif