-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattributelistimpl.hpp
70 lines (52 loc) · 1.94 KB
/
attributelistimpl.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef ATTRIBUTELISTIMPL_HPP
#define ATTRIBUTELISTIMPL_HPP
#include <xercesc/sax/AttributeList.hpp>
#include <map>
#include <memory>
#include "attributeimpl.hpp"
namespace XERCES_CPP_NAMESPACE {
class AttributeListImpl: public AttributeList
{
public:
AttributeListImpl();
XMLSize_t getLength() const override {
return attributes.size();
}
const XMLCh *getName(const XMLSize_t index) const override {
const AttributeImpl *a{ai(index)};
return a ? a->name() : nullptr;
}
const XMLCh *getType(const XMLSize_t index) const override {
const AttributeImpl *a{ai(index)};
return a ? a->type() : nullptr;
}
const XMLCh *getValue(const XMLSize_t index) const override {
const AttributeImpl *a{ai(index)};
return a ? a->value() : nullptr;
}
const XMLCh *getType(const XMLCh *name) const override {
auto iter{attributes.find(StrX(name).localForm())};
return ((iter != attributes.end()) ? iter->second.get()->type() : nullptr);
}
const XMLCh *getValue(const XMLCh *name) const override {
return getValue(StrX(name).localForm());
}
const XMLCh *getValue(const char *name) const override {
auto iter{attributes.find(name)};
return ((iter != attributes.end()) ? iter->second.get()->value() : nullptr);
}
typedef std::shared_ptr<AttributeImpl> attribute_ptr_t;
void add(const char *name, const char *value) {
attributes.emplace(name, attribute_ptr_t(new AttributeImpl(name, value)));
}
private:
typedef std::map<std::string, attribute_ptr_t> attribute_map_t;
const AttributeImpl *ai(XMLSize_t index) const {
attribute_map_t::const_iterator iter{attributes.begin()};
std::advance(iter, index);
return (iter != attributes.end()) ? iter->second.get() : nullptr;
}
attribute_map_t attributes;
};
} // end namespace XERCES_CPP_NAMESPACE //
#endif // ATTRIBUTELISTIMPL_HPP