00001 #include "namespace.h"
00002 #include "config.h"
00003
00004 NameSpace::NameSpace() : superNameSpace(NULL), ruleRunTime(0) {};
00005 NameSpace::NameSpace(NameSpace *isuperNameSpace) : superNameSpace(isuperNameSpace), ruleRunTime(0) {};
00006
00007 void NameSpace::ruleRunTimeStep(){
00008 ruleRunTime++;
00009 };
00010
00011 int NameSpace::getRuleRunTime() const{
00012 if (superNameSpace==NULL)
00013 return ruleRunTime;
00014 else
00015 return superNameSpace->getRuleRunTime();
00016 };
00017
00018 void NameSpace::setRuleRunTime(int iruleRunTime){
00019 if (iruleRunTime<=ruleRunTime)
00020 throw "ERROR: NameSpace::setRuleRunTime - rule run time was not incremented";
00021 ruleRunTime = iruleRunTime;
00022 };
00023
00024
00025
00026
00027
00028
00029
00030
00031 bool NameSpace::isAttributeSet(const string &name, const string &attribute, const bool global) const{
00032 if (verbose>5) cout << "NameSpace::isAttributeSet " << name << " " << attribute << " " << global << endl;
00033 NameAttributesMap::const_iterator found = info.find(name);
00034 if (((found == info.end())||(global))&&(superNameSpace!=NULL))
00035 return superNameSpace->isAttributeSet(name,attribute,global);
00036 else if (found != info.end()) {
00037 return found->second.find(attribute) != found->second.end();
00038 }
00039 else
00040 return false;
00041 };
00042
00043 bool NameSpace::isAttributeEqual(const string &name, const string &attribute, const string& value, const bool global) const{
00044 return getAttributeValue(name,attribute,global) == value;
00045 };
00046
00047 string NameSpace::getAttributeValue(const string &name, const string &attribute, const bool global) const{
00048
00049 NameAttributesMap::const_iterator found = info.find(name);
00050 if (((found == info.end())||(global))&&(superNameSpace!=NULL))
00051 return superNameSpace->getAttributeValue(name,attribute,global);
00052 else if (found != info.end()) {
00053 Attributes::const_iterator foundAttribute = found->second.find(attribute);
00054 if (foundAttribute != found->second.end())
00055 return foundAttribute->second;
00056 else
00057 return "";
00058 }
00059 else
00060 return "";
00061 };
00062
00063 void NameSpace::setAttributeValue(const string &name, const string &attribute, const string& value, const bool global){
00064 if (verbose > 5) cout << "NameSpace::setAttributeValue " << name << " " << attribute << " " << value << " "
00065 << global << " " << (superNameSpace!=NULL) << endl;
00066 if ((global)&&(superNameSpace!=NULL))
00067 superNameSpace->setAttributeValue(name, attribute, value, global);
00068 else
00069 info[name][attribute] = value;
00070 }
00071
00072 void NameSpace::setAttribute(const string &name, const string &attribute, const bool global){
00073 setAttributeValue(name,attribute,ATTRIBUTETRUE,global);
00074 };
00075
00076 void NameSpace::processArguments(const Node* arguments){
00077
00078 };
00079
00080 void NameSpace::importLocals(const string& name, const NameSpace &nameSpace){
00081 NameAttributesMap::const_iterator found = nameSpace.info.find("");
00082 if (found != nameSpace.info.end()){
00083 info[name] = found->second;
00084 }
00085 };