added util/Scope.h
git-svn-id: svn://anubis/fart/branches/scene-file-scripting@328 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
cd2f565df3
commit
e2569c0a54
@ -9,6 +9,7 @@
|
|||||||
#include "parser/parser.h"
|
#include "parser/parser.h"
|
||||||
#include "parser/nodes.h"
|
#include "parser/nodes.h"
|
||||||
#include "util/Polygon.h"
|
#include "util/Polygon.h"
|
||||||
|
#include "util/Scope.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
55
util/Scope.h
Normal file
55
util/Scope.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
|
||||||
|
#ifndef SCOPE_H
|
||||||
|
#define SCOPE_H
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user