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 metadata_[name] = boost::any(value);
59 template <
typename MetadataT>
60 const MetadataT & getMetadataValue(
const std::string & name)
const {
61 auto iter = metadata_.find(name);
62 if (iter == metadata_.end()) {
66 return boost::any_cast<const MetadataT &>(iter->second);
67 }
catch (
const boost::bad_any_cast &) {
68 throw SpartaException(
"Metadata named '")
69 << name <<
"' does exist, but is not of type '"
70 <<
typeid(MetadataT).name() <<
"'";
74 template <
typename MetadataT>
75 const MetadataT * tryGetMetadataValue(
const std::string & name)
const {
76 auto iter = metadata_.find(name);
77 if (iter == metadata_.end()) {
81 return &boost::any_cast<const MetadataT &>(iter->second);
82 }
catch (
const boost::bad_any_cast &) {
87 size_t getTotalNumLeaves()
const {
88 return total_num_leaves_;
97 archive_controller_ = controller;
99 void saveTo(
const std::string & dir);
103 void recursGetNumLeafChildren_(
106 if (node.getChildren().empty()) {
109 for (
const auto & child : node.getChildren()) {
110 num_leaves += child->getTotalNumLeaves();
118 template <
class Archive>
119 void serialize(Archive & ar,
const unsigned int) {
131 ar & total_num_leaves_;
134 if (!metadata_.empty()) {
147 auto iter = metadata_.find(
"trigger");
149 const app::TriggerKeyValues & source_kvs =
150 boost::any_cast<app::TriggerKeyValues&>(iter->second);
152 std::map<std::string, std::string> dest_kvs;
153 for (
const auto & kv : source_kvs) {
154 dest_kvs[kv.first] = kv.second;
164 std::map<std::string, std::string> source_kvs;
176 app::TriggerKeyValues dest_kvs;
177 for (
const auto & kv : source_kvs) {
178 dest_kvs[kv.first] = kv.second;
180 setMetadataValue(
"trigger", dest_kvs);
184 std::shared_ptr<ArchiveController> archive_controller_;
185 utils::ValidValue<size_t> total_num_leaves_;
186 app::NamedExtensions metadata_;