19 #ifndef avro_NodeConcepts_hh__
20 #define avro_NodeConcepts_hh__
24 #include "Exception.hh"
49 template<
typename Attribute>
51 static const bool hasAttribute =
false;
57 void add(
const Attribute & ) {
61 throw Exception(
"This type does not have attribute");
64 const Attribute &get(
size_t = 0)
const {
68 throw Exception(
"This type does not have attribute");
71 Attribute &get(
size_t = 0) {
75 throw Exception(
"This type does not have attribute");
79 template<
typename Attribute>
81 static const bool hasAttribute =
true;
96 void add(
const Attribute &attr) {
100 const Attribute &get(
size_t index = 0)
const {
102 throw Exception(
"SingleAttribute has only 1 value");
107 Attribute &get(
size_t index = 0) {
109 throw Exception(
"SingleAttribute has only 1 value");
120 template<
typename Attribute>
122 static const bool hasAttribute =
true;
132 attrs_.push_back(rhs.attr_);
139 size_t size()
const {
140 return attrs_.size();
143 void add(
const Attribute &attr) {
144 attrs_.push_back(attr);
147 const Attribute &get(
size_t index = 0)
const {
148 return attrs_.at(index);
151 Attribute &get(
size_t index) {
152 return attrs_.at(index);
156 std::vector<Attribute> attrs_;
162 bool lookup(
const std::string &name,
size_t &index)
const {
163 throw Exception(
"Name index does not exist");
166 bool add(const ::std::string &name,
size_t) {
167 throw Exception(
"Name index does not exist");
173 using IndexMap = std::map<std::string, size_t>;
175 bool lookup(
const std::string &name,
size_t &index)
const {
176 auto iter = map_.find(name);
177 if (iter == map_.end()) {
180 index = iter->second;
184 bool add(const ::std::string &name,
size_t index) {
186 auto lb = map_.lower_bound(name);
187 if (lb == map_.end() || map_.key_comp()(name, lb->first)) {
188 map_.insert(lb, IndexMap::value_type(name, index));