27 #ifndef SCHNEK_BLOCK_HPP_ 28 #define SCHNEK_BLOCK_HPP_ 30 #include "blockparameters.hpp" 31 #include "blockdata.hpp" 32 #include "../util/unique.hpp" 35 #include <boost/algorithm/string.hpp> 42 typedef std::shared_ptr<Block> pBlock;
43 typedef std::list<pBlock> BlockList;
44 typedef std::shared_ptr<BlockList> pBlockList;
51 std::stack<int> depth;
54 void addChild(pBlock);
57 pBlock getRoot() {
return root; }
60 typedef std::shared_ptr<BlockTree> pBlockTree;
74 bool getData(std::string key, T* &data,
bool upward);
76 void registerHierarchy();
77 void preInitHierarchy();
79 void postInitHierarchy();
81 void setParent(pBlock parent_) { parent=parent_; }
85 virtual void registerData() {}
86 virtual void preInit() {}
87 virtual void init() {}
88 virtual void postInit() {}
89 BlockList getChildren() {
return BlockList(children); }
91 Block(pBlock parent_ = pBlock()) : parent(parent_) {}
94 void setContext(pBlockVariables context)
96 blockParameters.setContext(context);
99 pBlockVariables getLocalVariables()
101 return blockParameters.getContext();
104 pBlockVariables getVariables()
106 pBlockVariables vars = blockParameters.getContext();
107 while (vars->getParent()) vars = vars->getParent();
113 void addChild(pBlock child);
114 void evaluateParameters();
116 pBlock getParent() {
return parent; }
119 void addData(std::string key, T &data);
122 void retrieveData(std::string key, T* &data);
125 void retrieveData(std::string key, T &data);
129 void setName(
const std::string &name_) { name = name_; }
130 std::string getName() {
return name; }
136 bool Block::getData(std::string key, T* &data,
bool upward)
144 boost::iterator_range<std::string::iterator> dot = boost::find_first(key,
".");
147 std::string head = std::string(key.begin(), dot.begin());
148 std::string tail = std::string(dot.end(), key.end());
150 for(pBlock child: children)
152 if ((child->getName()==head) && child->getData(tail, data,
false)) ++count;
156 else if (count==1)
return true;
159 if (upward && parent)
160 return parent->getData(key, data,
true);
163 for(pBlock child: children)
165 if (child->getData(key,data,
false)) ++count;
173 void Block::addData(std::string key, T &data)
179 void Block::retrieveData(std::string key, T* &data)
182 if (getData(key, datap,
true)) {
185 else if (!getData(key, data,
true))
190 void Block::retrieveData(std::string key, T &data)
193 if (!getData(key, datap,
true))
201 #endif // SCHNEK_BLOCK_HPP_ Definition: unique.hpp:36
Definition: blockdata.hpp:42
static BlockData< T > & instance()
Definition: logger.hpp:90
Definition: blockparameters.hpp:149