xoreos  0.0.5
functioncontext.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 <cassert>
26 
29 
30 namespace Aurora {
31 
32 namespace NWScript {
33 
35  _currentScript(0), _defaultCount(0), _paramsSpecified(0) {
36 
37 }
38 
40  *this = ctx;
41 }
42 
44 }
45 
47  _name = ctx._name;
48  _signature = ctx._signature;
49  _caller = ctx._caller;
50  _triggerer = ctx._triggerer;
51  _return = ctx._return;
56 
57  return *this;
58 }
59 
61  return _name;
62 }
63 
64 void FunctionContext::setSignature(const Signature &signature) {
65  _parameters.clear();
66 
67  if (signature.empty()) {
69  return;
70  }
71 
72  _parameters.reserve(signature.size() - 1);
73 
74  Signature::const_iterator s = signature.begin();
75 
76  _return.setType(*s);
77 
78  for (++s; s != signature.end(); ++s)
79  _parameters.push_back(Variable(*s));
80 }
81 
83  assert(defaults.size() <= _parameters.size());
84 
85  size_t start = _parameters.size() - defaults.size();
86 
87  for (size_t i = 0; i < defaults.size(); i++, start++) {
88  Variable &param = _parameters[start];
89  const Variable &def = defaults[i];
90 
91  assert(param.getType() == def.getType());
92 
93  param = def;
94  }
95 
96  _defaultCount = defaults.size();
97 }
98 
100  return _parameters.size() - _defaultCount;
101 }
102 
104  return _parameters.size();
105 }
106 
108  _paramsSpecified = params;
109 }
110 
112  return _paramsSpecified;
113 }
114 
116  return _signature;
117 }
118 
120  return *_caller;
121 }
122 
124  _caller = obj;
125 }
126 
128  _caller = obj;
129 }
130 
132  return *_triggerer;
133 }
134 
136  _triggerer = obj;
137 }
138 
140  _triggerer = obj;
141 }
142 
144  return _return;
145 }
146 
148  return _return;
149 }
150 
152  return _parameters;
153 }
154 
156  return _parameters;
157 }
158 
160  _currentScript = script;
161 }
162 
164  return _currentScript;
165 }
166 
168  if (!_currentScript)
169  return 0;
170 
171  return &_currentScript->getEnvironment();
172 }
173 
176  if (!_currentScript)
177  return kStringEmpty;
178 
179  return _currentScript->getName();
180 }
181 
182 } // End of namespace NWScript
183 
184 } // End of namespace Aurora
const Signature & getSignature() const
VariableContainer & getEnvironment()
Return the script&#39;s environment variables.
Definition: ncsfile.cpp:298
std::vector< class Variable > Parameters
Definition: types.h:54
size_t _paramsSpecified
The number of parameters specified (not defaulted).
A class holding an UTF-8 string.
Definition: ustring.h:48
Context of an NWScript function.
ObjectReference _triggerer
The triggering person.
An NCS, BioWare&#39;s NWN Compile Script.
Definition: ncsfile.h:86
FunctionContext & operator=(const FunctionContext &ctx)
const Common::UString & getScriptName() const
std::vector< Type > Signature
Definition: types.h:52
const Common::UString & getName() const
void setCurrentScript(NCSFile *script=0)
VariableContainer * getCurrentEnvironment() const
Handling BioWare&#39;s NWN Compiled Scripts.
void setType(Type type)
Definition: variable.cpp:98
size_t _defaultCount
The number of default values.
Parameters _parameters
The function&#39;s parameters.
NCSFile * _currentScript
The script executing this function.
ObjectReference _caller
The calling object.
Variable _return
The function&#39;s return value.
void setSignature(const Signature &signature)
const Common::UString & getName() const
Definition: ncsfile.cpp:294
Signature _signature
The function&#39;s signature.
void setDefaults(const Parameters &defaults)
FunctionContext(const Common::UString &name="")
static const Common::UString kStringEmpty