🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
Archive.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstUtil/Attribute.hpp"
25#include <string>
26
27AST_NAMESPACE_BEGIN
28
36template<typename T>
38{
39public:
40 const char* name() const { return name_; }
41 T& value() const { return value_; }
42
43 const char* name_;
44 T& value_;
45};
46
51template<typename T>
52NameValuePair<T> make_nvp(const char* name, T& val)
53{
54 return NameValuePair<T>{name, val};
55}
56
57
59class AST_UTIL_API Archive
60{
61public:
62 Archive() = default;
63 virtual ~Archive() = default;
64 virtual Archive& operator()(bool& val, const char* name=nullptr) = 0;
65 virtual Archive& operator()(int& val, const char* name=nullptr) = 0;
66 virtual Archive& operator()(double& val, const char* name=nullptr) = 0;
67 virtual Archive& operator()(std::string& val, const char* name=nullptr) = 0;
68 virtual Archive& operator()(Attribute& attr) {return *this;};
69public:
70 A_ALWAYS_INLINE Archive& operator&(bool& val) { return operator()(val); }
71 A_ALWAYS_INLINE Archive& operator&(int& val) { return operator()(val); }
72 A_ALWAYS_INLINE Archive& operator&(double& val) { return operator()(val); }
73 A_ALWAYS_INLINE Archive& operator&(std::string& val) { return operator()(val); }
74 A_ALWAYS_INLINE Archive& operator&(Attribute& attr) { return operator()(attr); }
75
76 A_ALWAYS_INLINE Archive& operator&(const NameValuePair<bool>& nvp) { return operator()(nvp.value(), nvp.name()); }
77 A_ALWAYS_INLINE Archive& operator&(const NameValuePair<int>& nvp) { return operator()(nvp.value(), nvp.name()); }
78 A_ALWAYS_INLINE Archive& operator&(const NameValuePair<double>& nvp) { return operator()(nvp.value(), nvp.name()); }
79 A_ALWAYS_INLINE Archive& operator&(const NameValuePair<std::string>& nvp) { return operator()(nvp.value(), nvp.name()); }
80};
81
84AST_NAMESPACE_END
归档基类,实现对象的序列化和反序列化等操作
定义 Archive.hpp:60
名值对
定义 Archive.hpp:38
NameValuePair< T > make_nvp(const char *name, T &val)
创建名值对
定义 Archive.hpp:52