diff --git a/main/Scene-load.cc b/main/Scene-load.cc index 9a4c75a..e4b982c 100644 --- a/main/Scene-load.cc +++ b/main/Scene-load.cc @@ -9,6 +9,7 @@ #include "parser/parser.h" #include "parser/nodes.h" #include "util/Polygon.h" +#include "util/Scope.h" using namespace std; diff --git a/util/Scope.h b/util/Scope.h new file mode 100644 index 0000000..9089053 --- /dev/null +++ b/util/Scope.h @@ -0,0 +1,55 @@ + +#ifndef SCOPE_H +#define SCOPE_H + +#include +#include +#include + +class Scope +{ + public: + Scope() { push(); } + bool contains(const std::string & key) + { + for (m_list_type::const_reverse_iterator it = m_list.rbegin(); + it != m_list.rend(); + it++) + { + if (it->find(key) != it->end()) + { + return true; + } + } + return false; + } + double & operator[](const std::string & key) + { + for (m_list_type::reverse_iterator it = m_list.rbegin(); + it != m_list.rend(); + it++) + { + if (it->find(key) != it->end()) + { + return (*it)[key]; + } + } + return (*m_list.rbegin())[key]; + } + void push() + { + m_list.push_back(std::map< std::string, double >()); + } + void pop() + { + if (m_list.size() > 1) + { + m_list.pop_back(); + } + } + protected: + typedef std::list< std::map< std::string, double > > m_list_type; + m_list_type m_list; +}; + +#endif