The Sparta Modeling Framework
Loading...
Searching...
No Matches
MetaTreeNode.hpp
Go to the documentation of this file.
1// <MetaTreeNode.hpp> -*- C++ -*-
2
3
9#pragma once
10
11#include <memory>
16
17
18namespace sparta {
19namespace app {
20
31{
35 class FactoryIF
36 {
37 public:
38 virtual ParameterBase* create() const = 0;
39
40 virtual ~FactoryIF()
41 {;}
42 };
43
47 template <typename T>
48 class Factory : public FactoryIF
49 {
50 std::string name_;
51 T def_val_;
52 std::string docstring_;
53
54 public:
55 Factory(const std::string& name, const T& def_val, const std::string& docstring)
56 : name_(name),
57 def_val_(def_val),
58 docstring_(docstring)
59 {;}
60
64 ParameterBase* create() const override { return new Parameter<T>(name_, def_val_, docstring_); }
65 };
66
72 std::shared_ptr<FactoryIF> fact_;
73
74public:
75
79 template <typename T>
80 ParameterTemplate(const std::string& name, const T& def_val, const std::string& docstring)
81 : fact_(new Factory<T>(name, def_val, docstring))
82 {;}
83
84 ParameterTemplate(const std::string& name, const char* def_val, const std::string& docstring)
85 : fact_(new Factory<std::string>(name, def_val, docstring))
86 {;}
87
88 ParameterTemplate(const ParameterTemplate&) = default;
89 ParameterTemplate(ParameterTemplate&&) = default;
90
91 ParameterTemplate& operator=(const ParameterTemplate&) = default;
92
97 ParameterBase* create() const { return fact_->create(); }
98};
99
101{
102
103 class ParameterSet : public sparta::ParameterSet
104 {
105 std::vector<ParameterBase*> owned_params_;
106
107 public:
108
112 ParameterSet(TreeNode *n, const std::list<ParameterTemplate>& plist)
114 {
115 for(auto& pt: plist){
116 ParameterBase* pb = pt.create();
117 addParameter_(pb);
118 owned_params_.push_back(pb);
119 }
120 }
121
127 {;}
128
129 ~ParameterSet()
130 {
131 for(ParameterBase*& p : owned_params_){
132 delete p;
133 p = nullptr;
134 }
135 }
136
137 // Built-in parameters
138
139 PARAMETER (std::string, architecture, "NONE", "Name of architecture being simulated")
140 PARAMETER (bool, is_final_config, false, "True if this config was generated using --write-final-config. "
141 "This value is checked during --read-final-config to validate we are "
142 "loading a full config.")
143
144 } params_;
145
146public:
147
154 MetaTreeNode(app::Simulation* sim, GlobalTreeNode* search_scope, const std::list<ParameterTemplate>& plist)
155 : RootTreeNode("meta", "Meta-Data gloabl node", sim, search_scope),
156 params_(this, plist)
157 {
158 }
159};
160
161} // namespace app
162} // naemspace sparta
A set of sparta::Parameters per sparta::ResourceTreeNode.
#define PARAMETER(type, name, def, doc)
Parameter declaration.
Individual Parameter interface base class, container class, and global helpers methods.
A simple time-based, event precedence based scheduler.
Basic Node framework in sparta device tree composite pattern.
TreeNode which represents some "global" namespace of the device tree, containing only RootTreeNodes,...
Non-templated base class for generic parameter access and iteration.
Generic container of Parameters.
ParameterSet()=delete
Default constructor disabled.
void addParameter_(sparta::ParameterBase *p)
Add a parameter to the parameter set. \temp This will be removed.
Parameter instance, templated to contain only a specific type.
TreeNode which represents the root ("top") of a device tree.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
MetaTreeNode(app::Simulation *sim, GlobalTreeNode *search_scope, const std::list< ParameterTemplate > &plist)
Constructor with only a simulator and search scope.
ParameterTemplate providing factory implementation for each data type.
ParameterBase * create() const
Crete an instance of the parameter base on this template using "new".
ParameterTemplate(const std::string &name, const T &def_val, const std::string &docstring)
Create the template. Specify the type of def_val explicitly when invoking this function.
Simulator which builds a sparta DeviceTree.
Macros for handling exponential backoff.