44 size_t num_leaves = 0;
45 recursGetNumLeafChildren_(*
this, num_leaves);
46 total_num_leaves_ = num_leaves;
54 template <
typename MetadataT>
55 void setMetadataValue(
const std::string & name,
const MetadataT & value) {
56 boost::any any_value(value);
57 metadata_[name] = any_value;
60 template <
typename MetadataT>
61 const MetadataT & getMetadataValue(
const std::string & name)
const {
62 auto iter = metadata_.find(name);
63 if (iter == metadata_.end()) {
67 return boost::any_cast<const MetadataT &>(iter->second);
68 }
catch (
const boost::bad_any_cast &) {
69 throw SpartaException(
"Metadata named '")
70 << name <<
"' does exist, but is not of type '"
71 <<
typeid(MetadataT).name() <<
"'";
75 template <
typename MetadataT>
76 const MetadataT * tryGetMetadataValue(
const std::string & name)
const {
77 auto iter = metadata_.find(name);
78 if (iter == metadata_.end()) {
82 return &boost::any_cast<const MetadataT &>(iter->second);
83 }
catch (
const boost::bad_any_cast &) {
88 size_t getTotalNumLeaves()
const {
89 return total_num_leaves_;
98 archive_controller_ = controller;
100 void saveTo(
const std::string & dir);
104 void recursGetNumLeafChildren_(
107 if (node.getChildren().empty()) {
110 for (
const auto & child : node.getChildren()) {
111 num_leaves += child->getTotalNumLeaves();
119 template <
class Archive>
120 void serialize(Archive & ar,
const unsigned int) {
132 ar & total_num_leaves_;
135 if (!metadata_.empty()) {
148 auto iter = metadata_.find(
"trigger");
150 const app::TriggerKeyValues & source_kvs =
151 boost::any_cast<app::TriggerKeyValues&>(iter->second);
153 std::map<std::string, std::string> dest_kvs;
154 for (
const auto & kv : source_kvs) {
155 dest_kvs[kv.first] = kv.second;
165 std::map<std::string, std::string> source_kvs;
177 app::TriggerKeyValues dest_kvs;
178 for (
const auto & kv : source_kvs) {
179 dest_kvs[kv.first] = kv.second;
181 setMetadataValue(
"trigger", dest_kvs);
185 std::shared_ptr<ArchiveController> archive_controller_;
186 utils::ValidValue<size_t> total_num_leaves_;
187 app::NamedExtensions metadata_;