🛰️航天仿真算法库 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
118 bool isBind() const { return bind_; }
119
123 std::string getExpression(Object* context=nullptr) const override{return getName();}
124
127 std::string getInnerExpression() const;
128public:
129 const std::string& name() const { return getName(); }
130 const std::string& desc() const { return desc_; }
131 void setDesc(StringView desc) { desc_ = std::string(desc); }
132 Expr* expr() const { return expr_.get(); }
133PROPERTIES:
134 std::string value() const;
135 errc_t setValue(StringView value);
136protected:
137 std::string desc_;
139 bool bind_;
140};
141
142
143AST_NAMESPACE_END
表达式基类
定义 Expr.hpp:40
virtual errc_t setValue(Value *val)
设置表达式的值
定义 Expr.hpp:56
virtual Value * eval() const =0
求值
const std::string & getName() const override
获取对象名称
定义 ObjectNamed.hpp:48
对象基类,继承自该类的对象可以使用运行时类型信息相关功能,实现强弱引用计数、运行时元信息(属性访问、序列化等)等基础功能
定义 Object.hpp:95
const std::string & name() const
获取对象的名称
定义 Object.hpp:135
数量值
定义 Quantity.hpp:114
共享指针
定义 SharedPtr.hpp:33
值对象基类
定义 Value.hpp:43
变量
定义 Variable.hpp:40
std::string desc_
变量的描述
定义 Variable.hpp:137
SharedPtr< Expr > expr_
变量的值,或者绑定的表达式
定义 Variable.hpp:138
bool bind_
是否与表达式双向绑定
定义 Variable.hpp:139
bool isBind() const
是否与表达式双向绑定
定义 Variable.hpp:118
std::string getExpression(Object *context=nullptr) const override
获取变量的表达式
定义 Variable.hpp:123