27 using boost::property_tree::ptree;
33 AttributeStore::AttributeStore(
const boost::property_tree::ptree& pt) : m_ptree(pt)
35 const string xcpt =
"AttributeStoreIndex::AttributeStoreIndex(const ptree&) : for type ";
37 for(
auto it = m_ptree.begin(); it != m_ptree.end(); it++){
38 const auto pt2 = it->second;
39 const auto name = pt2.get<
string>(
"name");
40 const auto type = pt2.get<
string>(
"type");
43 if ( IsAttribute<bool>(name) ) {
44 throw std::runtime_error(xcpt +
"bool, name already in index: " + name);
46 m_map_b[name] = make_pair(std::vector<bool>(), pt2.get<
bool>(
"default"));
48 }
else if( type ==
"int" ){
49 if ( IsAttribute<int>(name) ) {
50 throw std::runtime_error(xcpt +
"int, name already in index: " + name);
52 m_map_i[name] = make_pair(std::vector<int>(), pt2.get<
int>(
"default"));
54 }
else if( type ==
"double" ) {
55 if ( IsAttribute<int>(name) ) {
56 throw std::runtime_error(xcpt +
"double, name already in index: " + name);
58 m_map_d[name] = make_pair(std::vector<double>(), pt2.get<
double>(
"default"));
60 }
else if ( type ==
"string" ) {
61 if ( IsAttribute<string>(name) ) {
62 throw std::runtime_error(xcpt +
"string, name already in index: " + name);
64 m_map_s[name] = make_pair(std::vector<string>(), pt2.get<
string>(
"default"));
67 throw Exception( xcpt + type +
" is not a supported attribute type.");
76 for(
const auto& name : GetAttributeNames<bool>()) {
77 result.put(name, Container<bool>(name).at(pos));
79 for(
const auto& name : GetAttributeNames<int>()) {
80 result.put(name, Container<int>(name).at(pos));
82 for(
const auto& name : GetAttributeNames<double>()) {
83 result.put(name, Container<double>(name).at(pos));
85 for(
const auto& name : GetAttributeNames<string>()) {
86 result.put(name, Container<string>(name).at(pos));
96 for(
const auto& name : GetAttributeNames<bool>()) {
98 child.put(
"name", name);
99 child.put(
"type",
"bool");
100 child.put(
"default", GetDefaultValue<bool>(name));
101 result.add_child(
"attribute", child);
103 for(
const auto& name : GetAttributeNames<int>()) {
105 child.put(
"name", name);
106 child.put(
"type",
"int");
107 child.put(
"default", GetDefaultValue<int>(name));
108 result.add_child(
"attribute", child);
110 for(
const auto& name : GetAttributeNames<double>()) {
112 child.put(
"name", name);
113 child.put(
"type",
"double");
114 child.put(
"default", GetDefaultValue<double>(name));
115 result.add_child(
"attribute", child);
117 for(
const auto& name : GetAttributeNames<string>()) {
119 child.put(
"name", name);
120 child.put(
"type",
"string");
121 child.put(
"default", GetDefaultValue<double>(name));
122 result.add_child(
"attribute", child);
130 os <<
"AttributeStore index:" << endl;
132 for(
auto it = pt.begin(); it != pt.end(); it++){
133 const auto pt2 = it->second;
134 const auto name = pt2.get<
string>(
"name");
135 const auto type = pt2.get<
string>(
"type");
137 if( type ==
"bool" ){
138 os <<
"name: " << name <<
" type: bool " <<
" default value: " << pt2.get<
bool>(
"default") << endl;
139 }
else if( type ==
"int" ){
140 os <<
"name: " << name <<
" type: int " <<
" default value: " << pt2.get<
int>(
"default") << endl;
141 }
else if( type ==
"double" ) {
142 os <<
"name: " << name <<
" type: double" <<
" default value: " << pt2.get<
double>(
"default") << endl;
143 }
else if ( type ==
"string" ) {
144 os <<
"name: " << name <<
" type: string" <<
" default value: " << pt2.get<
string>(
"default") << endl;
146 throw Exception(
string(
"operator<<(ostream& os, const AttributeStore& a)") + type +
" is not a supported attribute type.");
150 os <<
"AttributeStore values for bool attributes:" << endl;
152 os <<
"name: " << name << endl;
153 for (
const auto e : a.
Container<
bool>(name)) {
159 os <<
"AttributeStore values for int attributes:" << endl;
161 os <<
"name: " << name << endl;
162 for (
const auto e : a.
Container<
int>(name)) {
168 os <<
"AttributeStore values for double attributes:" << endl;
170 os <<
"name: " << name << endl;
171 for (
const auto e : a.
Container<
double>(name)) {
177 os <<
"AttributeStore values for string attributes:" << endl;
179 os <<
"name: " << name << endl;
180 for (
const auto e : a.
Container<
string>(name)) {
Interface of AttributeStore.
boost::property_tree::ptree GetIndexPtree() const
Return original attribute ptree the AttributeStore was created from.
boost::property_tree::ptree GetAttributeValues(std::size_t pos) const
Return all attribute values at position i in the container in property tree format.
std::vector< T > & Container(const std::string &name)
Reference to the appropriate (type and name) attribute container.
Extremely simple Exception root class.
Namespace for the core simulator.
boost::property_tree::ptree GetIndexDump() const
Produces representation of index structure in a ptree descriptor.
Store and manage attributes.
std::vector< std::string > GetAttributeNames() const
Return a vector containing the names of attributes of type T.
Header file for Exception class.