🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
Variable.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstScript/Expr.hpp"
25#include "AstUtil/StringView.hpp"
26#include "AstUtil/SharedPtr.hpp"
27#include <string>
28
29AST_NAMESPACE_BEGIN
30
31class Value;
32
39class AST_SCRIPT_API Variable: public Expr
40{
41public:
42 AST_OBJECT(Variable)
43 AST_PROPERT(value)
44 AST_EXPR_EXTRA(Variable)
45
46 static Variable* New();
47
48 Variable(StringView name, Expr* expr=nullptr, bool bind = false);
49 Variable(Expr* expr=nullptr, bool bind = false);
50
53 Value* eval() const final;
54
58 errc_t setValue(Value* val) final;
59
63 errc_t setExpr(Expr* expr);
64
68 errc_t setBindExpr(Expr* expr);
69
73 errc_t setExpr(Value* value);
74
78 errc_t setExpr(StringView value);
79
83 errc_t setExpr(const std::string& value);
84
88 errc_t setExpr(const Quantity& quantity);
89
93 errc_t setExpr(double value);
94
98 errc_t setExpr(int value);
99
103 errc_t setExpr(bool value);
104
105 #ifndef SWIG
106 // 通过模板捕获所有其他类型并删除,防止隐式转换为 `bool` 类型
107 template<typename T>
108 errc_t setExpr(T value) = delete;
109 #endif
110
114 errc_t bind(Expr* expr);
115
116
120 std::string getExpression(Object* context=nullptr) const override{return name_;}
121public:
122 const std::string& name() const { return name_; }
123 const std::string& getName() const override { return name_; }
124 void setName(StringView name) override { name_ = std::string(name); }
125 Expr* expr() const { return expr_.get(); }
126PROPERTIES:
127 std::string value() const;
128 errc_t setValue(StringView value);
129protected:
130 std::string name_;
132 bool bind_;
133};
134
135
136AST_NAMESPACE_END
表达式基类
定义 Expr.hpp:39
virtual errc_t setValue(Value *val)
设置表达式的值
定义 Expr.hpp:60
virtual Value * eval() const =0
求值
对象基类,继承自该类的对象可以使用运行时类型信息相关功能,实现强弱引用计数、运行时元信息(属性访问、序列化等)等基础功能
定义 Object.hpp:86
const std::string & name() const
获取对象的名称
定义 Object.hpp:133
数量值
定义 Quantity.hpp:114
共享指针
定义 SharedPtr.hpp:33
值对象基类
定义 Value.hpp:43
变量
定义 Variable.hpp:40
const std::string & getName() const override
获取对象的名称
定义 Variable.hpp:123
SharedPtr< Expr > expr_
变量的值,或者绑定的表达式
定义 Variable.hpp:131
bool bind_
是否与表达式双向绑定
定义 Variable.hpp:132
std::string getExpression(Object *context=nullptr) const override
获取变量的表达式
定义 Variable.hpp:120
std::string name_
变量的名称
定义 Variable.hpp:130
void setName(StringView name) override
设置对象的名称
定义 Variable.hpp:124