2014-04-28 21:09:25 +04:00
|
|
|
#pragma once
|
2010-01-30 07:26:05 +03:00
|
|
|
|
2011-09-03 08:10:36 +04:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <boost/unordered_map.hpp>
|
2010-01-30 07:26:05 +03:00
|
|
|
#include "value.h"
|
2013-04-19 02:34:14 +04:00
|
|
|
#include "typedefs.h"
|
2010-01-30 07:26:05 +03:00
|
|
|
|
|
|
|
class Context
|
|
|
|
{
|
2011-09-03 20:51:29 +04:00
|
|
|
public:
|
2014-04-05 08:40:23 +04:00
|
|
|
typedef std::vector<const Context*> Stack;
|
2013-04-09 08:28:16 +04:00
|
|
|
Context(const Context *parent = NULL);
|
|
|
|
virtual ~Context();
|
2011-09-03 20:51:29 +04:00
|
|
|
|
2014-03-16 07:10:45 +04:00
|
|
|
const Context *getParent() const { return this->parent; }
|
2013-04-09 08:28:16 +04:00
|
|
|
virtual Value evaluate_function(const std::string &name, const class EvalContext *evalctx) const;
|
2013-04-20 01:52:01 +04:00
|
|
|
virtual class AbstractNode *instantiate_module(const class ModuleInstantiation &inst, const EvalContext *evalctx) const;
|
2013-04-09 08:28:16 +04:00
|
|
|
|
2013-04-19 02:34:14 +04:00
|
|
|
void setVariables(const AssignmentList &args,
|
2013-04-09 08:28:16 +04:00
|
|
|
const class EvalContext *evalctx = NULL);
|
2011-09-03 20:51:29 +04:00
|
|
|
|
|
|
|
void set_variable(const std::string &name, const Value &value);
|
|
|
|
void set_constant(const std::string &name, const Value &value);
|
|
|
|
|
|
|
|
Value lookup_variable(const std::string &name, bool silent = false) const;
|
2014-05-23 00:24:26 +04:00
|
|
|
bool has_local_variable(const std::string &name) const;
|
2011-09-03 20:51:29 +04:00
|
|
|
|
|
|
|
void setDocumentPath(const std::string &path) { this->document_path = path; }
|
2013-04-09 08:28:16 +04:00
|
|
|
const std::string &documentPath() const { return this->document_path; }
|
2011-09-03 20:51:29 +04:00
|
|
|
std::string getAbsolutePath(const std::string &filename) const;
|
|
|
|
|
2010-01-30 07:26:05 +03:00
|
|
|
public:
|
|
|
|
|
2014-03-16 07:10:45 +04:00
|
|
|
protected:
|
|
|
|
const Context *parent;
|
2014-04-05 08:40:23 +04:00
|
|
|
Stack *ctx_stack;
|
2010-01-30 07:26:05 +03:00
|
|
|
|
2013-03-07 05:49:52 +04:00
|
|
|
typedef boost::unordered_map<std::string, Value> ValueMap;
|
2011-09-03 20:51:29 +04:00
|
|
|
ValueMap constants;
|
|
|
|
ValueMap variables;
|
|
|
|
ValueMap config_variables;
|
2013-04-09 08:28:16 +04:00
|
|
|
|
2013-04-24 17:17:25 +04:00
|
|
|
std::string document_path; // FIXME: This is a remnant only needed by dxfdim
|
2013-04-09 08:28:16 +04:00
|
|
|
|
|
|
|
public:
|
2014-04-05 08:40:23 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
virtual std::string dump(const class AbstractModule *mod, const ModuleInstantiation *inst);
|
2013-04-09 08:28:16 +04:00
|
|
|
#endif
|
2010-01-30 07:26:05 +03:00
|
|
|
};
|