#include <string>
#include <sstream>
#include <boost/bind.hpp>
+#include <cstring> // for strcmp
#include <simgear/props/props.hxx>
return output;
}
+ if (name == "table") {
+ SGInterpTable* tab = new SGInterpTable(expression);
+ if (!tab) {
+ SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression: malformed table");
+ return 0;
+ }
+
+ // find input expression - i.e a child not named 'entry'
+ const SGPropertyNode* inputNode = NULL;
+ for (int i=0; (i<expression->nChildren()) && !inputNode; ++i) {
+ if (strcmp(expression->getChild(i)->getName(), "entry") == 0) {
+ continue;
+ }
+
+ inputNode = expression->getChild(i);
+ }
+
+ if (!inputNode) {
+ SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression: no input found");
+ return 0;
+ }
+
+ SGSharedPtr<SGExpression<T> > inputExpression;
+ inputExpression = SGReadIExpression<T>(inputRoot, inputNode);
+ if (!inputExpression) {
+ SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
+ return 0;
+ }
+
+ return new SGInterpTableExpression<T>(inputExpression, tab);
+ }
+
return 0;
}
}
return new SGTanhExpression<T>(inputExpression);
}
-
-// if (name == "table") {
-// }
+
// if (name == "step") {
// }
// if (name == "condition") {
return true;
}
-Parser::ParserMap ExpressionParser::_parserTable;
-
void ExpressionParser::addExpParser(const string& token, exp_parser parsefn)
{
- _parserTable.insert(std::make_pair(token, parsefn));
+ ParserMapSingleton::instance()
+ ->_parserTable.insert(std::make_pair(token, parsefn));
}
Expression* valueParser(const SGPropertyNode* exp, Parser* parser)
parser->readChildren(exp, children);
vector<Expression*>::iterator notBool =
find_if(children.begin(), children.end(),
- bind(&Expression::getType, _1) != BOOL);
+ boost::bind(&Expression::getType, _1) != BOOL);
if (notBool != children.end())
throw("non boolean operand to logical expression");
Logicop *expr = new Logicop;
//XXX error checkint
vector<VariableBinding>::iterator itr
= find_if(bindings.begin(), bindings.end(),
- bind(&VariableBinding::name, _1) == name);
+ boost::bind(&VariableBinding::name, _1) == name);
if (itr != bindings.end())
return itr->location;
int result = bindings.size();
using namespace boost;
vector<VariableBinding>::const_iterator itr
= find_if(bindings.begin(), bindings.end(),
- bind(&VariableBinding::name, _1) == name);
+ boost::bind(&VariableBinding::name, _1) == name);
if (itr != bindings.end()) {
result = *itr;
return true;