The Sparta Modeling Framework
Loading...
Searching...
No Matches
CollectableTreeNode.hpp
Go to the documentation of this file.
1// <CollectableTreeNode> -*- C++ -*-
2
3
11#pragma once
12
13#include <string>
14#include <inttypes.h>
15
18#include "simdb/apps/argos/ArgosCollector.hpp"
19
20namespace sparta{
21namespace collection
22{
23
31 {
32 public:
41 CollectableTreeNode(sparta::TreeNode* parent, const std::string& name,
42 const std::string& group, uint32_t index,
43 const std::string& desc = "CollectableTreeNode <no desc>") :
44 sparta::TreeNode(parent, name, group, index, desc)
45 {
46 markHidden(); // Mark self as hidden from the default
47 // printouts (to reduce clutter)
48 }
49
56 CollectableTreeNode(sparta::TreeNode* parent, const std::string& name,
57 const std::string& desc= "CollectableTreeNode <no desc>") :
60 {}
61
64 {}
65
70 return dynamic_cast<const CollectableTreeNode*>(getParent()) != nullptr;
71 }
72
77 virtual void createSimDbEntryPoint(simdb::argos::ArgosCollector*) = 0;
78
84 virtual void serializeStructSchema(simdb::DatabaseManager*, std::set<std::string>& serialized_types) {
85 (void)serialized_types;
86 }
87
100 virtual std::string encodeCollectedType(bool human_readable = false) const = 0;
101
111 void startCollecting(Collector * collector) {
112 is_collected_ = true;
113 if (!isIterableCollectorBin()) {
114 setCollecting_(true, collector);
115 }
116 }
117
122 void stopCollecting(Collector * collector)
123 {
124 if (!isIterableCollectorBin()) {
125 setCollecting_(false, collector);
126 }
127 is_collected_ = false;
128 }
129
134 bool isCollected() const { return is_collected_; }
135
138 virtual void collect() = 0;
139
144 virtual void restartRecord() {}
145
154 virtual void closeRecord(const bool & simulation_ending = false) { (void) simulation_ending; }
155
156 protected:
157
162 virtual void setCollecting_(bool collect, Collector *) { (void) collect; }
163
167 simdb::argos::EntryPoint* entry_point_ = nullptr;
168
169 private:
170
175 bool is_collected_ = false;
176
177 };
178
179}
180}
Define a base Collector class.
Basic Node framework in sparta device tree composite pattern.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:204
static const group_idx_type GROUP_IDX_NONE
GroupIndex indicating that a node has no group index because it belongs to no group.
Definition TreeNode.hpp:302
void markHidden(bool hidden=true)
Marks this TreeNode hidden for the purposes of printint out nodes. This does not make the node inacce...
static constexpr char GROUP_NAME_NONE[]
Group name indicating that a node belongs to no group.
Definition TreeNode.hpp:313
virtual TreeNode * getParent()
Gets immediate parent of this node if one exists.
Definition TreeNode.hpp:964
An abstract type of TreeNode that has virtual calls to start collection on this node,...
virtual std::string encodeCollectedType(bool human_readable=false) const =0
Encode the collected data type in a way Argos python deserializers will understand:
virtual void serializeStructSchema(simdb::DatabaseManager *, std::set< std::string > &serialized_types)
Whether a scalar (Collectable) or container (IterableCollector), serialize struct-like data structure...
virtual void closeRecord(const bool &simulation_ending=false)
CollectableTreeNode(sparta::TreeNode *parent, const std::string &name, const std::string &group, uint32_t index, const std::string &desc="CollectableTreeNode <no desc>")
Construct.
virtual ~CollectableTreeNode()
Virtual destructor.
virtual void setCollecting_(bool collect, Collector *)
Indicate to sub-classes that collection has flipped.
simdb::argos::EntryPoint * entry_point_
Entry point into the SimDB collection system.
CollectableTreeNode(sparta::TreeNode *parent, const std::string &name, const std::string &desc="CollectableTreeNode <no desc>")
Construct.
void startCollecting(Collector *collector)
Method that tells this treenode that is now running collection.
virtual void createSimDbEntryPoint(simdb::argos::ArgosCollector *)=0
Collectable classes must be able to register themselves with the ArgosCollector.
bool isCollected() const
Determine whether or not this node has collection turned on or off.
void stopCollecting(Collector *collector)
Method that tells this treenode that is now not running collection.
bool isIterableCollectorBin() const
Check if this CollectableTreeNode is a Collectable inside an IterableCollector.
A non-templated base class that all Collectors should inherit from.
Definition Collector.hpp:23
Macros for handling exponential backoff.