🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
Value.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstScript/Expr.hpp"
25#include "AstScript/ScriptAPI.hpp"
26#include "AstUtil/OrderedMap.hpp"
27#include <map>
28
29AST_NAMESPACE_BEGIN
30
31
32class ValDict;
33using ValueMapType = OrderedMap<std::string, SharedPtr<Value>>;
34using NamedValueVector = std::vector<std::pair<std::string, SharedPtr<Value>>>;
35
42class AST_SCRIPT_API Value: public Expr
43{
44public:
45 static Value& NullValue();
46
47 using Expr::Expr;
48 ~Value() override = default;
49
51 Value* eval() const final{return const_cast<Value*>(this);}
52
54 errc_t setValue(Value*) final{return eErrorReadonly;}
55public:
56 void insert(const std::string& name, Value* value);
57 template<typename T>
58 void insert(const std::string& name, T value)
59 {
60 insert(name, aNewValue(value));
61 }
62 Value& operator[](const std::string& name);
63 const Value& operator[](const std::string& name) const;
64 Value& operator[](const char* name);
65 const Value& operator[](const char* name) const;
66 Value& operator[](size_t index);
67 const Value& operator[](size_t index) const;
68
69 bool isNull() const;
70 bool isBool() const;
71 bool isInt() const;
72 bool isDouble() const;
73 bool isQuantity() const;
74 bool isString() const;
75
76 std::string toString() const;
77 Quantity toQuantity() const;
78 double toDouble() const;
79 int toInt() const;
80 bool toBool() const;
81
82 operator std::string() const;
83 operator Quantity() const;
84 operator double() const;
85 operator int() const;
86 operator bool() const;
87
88 ValDict* toValDict() const;
89 const NamedValueVector& items() const;
90
91 const Value& operator>>(bool& val) const;
92 const Value& operator>>(int& val) const;
93 const Value& operator>>(double& val) const;
94
95private:
96
97};
98
99AST_NAMESPACE_END
表达式基类
定义 Expr.hpp:39
值对象基类
定义 Value.hpp:43
Value * eval() const final
求值表达式
定义 Value.hpp:51
errc_t setValue(Value *) final
设置值
定义 Value.hpp:54