xoreos  0.0.5
variablecontainer.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/error.h"
26 
28 
29 namespace Aurora {
30 
31 namespace NWScript {
32 
34 }
35 
37 }
38 
40  return _variables.find(var) != _variables.end();
41 }
42 
44  VariableMap::iterator v = _variables.find(var);
45  if (v == _variables.end()) {
46  std::pair<VariableMap::iterator, bool> result;
47 
48  result = _variables.insert(std::make_pair(var, Variable(type)));
49 
50  v = result.first;
51  }
52 
53  return v->second;
54 }
55 
57  VariableMap::const_iterator v = _variables.find(var);
58  if (v == _variables.end())
59  throw Common::Exception("VariableContainer::getVariable(): No such variable \"%s\"", var.c_str());
60 
61  return v->second;
62 }
63 
65  _variables[var] = value;
66 }
67 
69  VariableMap::iterator v = _variables.find(var);
70  if (v != _variables.end())
71  _variables.erase(v);
72 }
73 
75  _variables.clear();
76 }
77 
78 } // End of namespace NWScript
79 
80 } // End of namespace Aurora
A class holding an UTF-8 string.
Definition: ustring.h:48
bool hasVariable(const Common::UString &var) const
Exception that provides a stack of explanations.
Definition: error.h:36
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Variable & getVariable(const Common::UString &var, Type type=kTypeVoid)
void removeVariable(const Common::UString &var)
An NWScript variable container.
void setVariable(const Common::UString &var, const Variable &value)