1 #include "xercesc/sax2/SAX2XMLReader.hpp" 2 #include <xercesc/sax2/XMLReaderFactory.hpp> 3 #include "xercesc/sax2/DefaultHandler.hpp" 4 #include "xercesc/sax2/Attributes.hpp" 6 #include <xercesc/framework/MemBufInputSource.hpp> 13 std::unique_ptr<SAX2XMLReader>
parser;
18 if (m_parser !=
nullptr)
45 enum { md_Idle, md_Parameter, md_Data } m_mode;
49 std::vector<std::string>&
items,
51 : m_dataEncoding(encoding), m_items(items), m_parameters(parameters) {
53 xc_Parameter = XMLString::transcode(
"Parameter");
54 xc_Data = XMLString::transcode(
"Data");
55 xc_name = XMLString::transcode(
"name");
56 xc_type = XMLString::transcode(
"type");
57 xc_elements = XMLString::transcode(
"elements");
58 xc_encoding = XMLString::transcode(
"encoding");
70 void startElement(
const XMLCh*
const uri,
71 const XMLCh*
const localname,
72 const XMLCh*
const qname,
73 const Attributes& attrs)
override;
74 void endElement(
const XMLCh*
const uri,
const XMLCh*
const localname,
const XMLCh*
const qname)
override;
75 void characters(
const XMLCh*
const chars,
const XMLSize_t length)
override;
76 void ignorableWhitespace(
const XMLCh*
const chars,
const XMLSize_t length)
override;
82 char* tool = XMLString::transcode(val);
87 XMLCh *xc_Parameter, *xc_Data, *xc_name, *xc_type, *xc_elements, *xc_encoding;
98 const XMLCh*
const localname,
99 const XMLCh*
const qname,
100 const Attributes& attrs) {
101 if (m_mode != md_Idle)
103 if (!XMLString::compareIString(localname, xc_Parameter)) {
105 if (!cvt2String(attrs.getValue(xc_name), m_pname))
108 if (!cvt2String(attrs.getValue(xc_type), m_ptype))
111 m_mode = md_Parameter;
113 }
else if (!XMLString::compareIString(localname, xc_Data)) {
116 if (!cvt2String(attrs.getValue(xc_elements), strElements))
118 n_elements = atoi(strElements.c_str());
121 cvt2String(attrs.getValue(xc_encoding), m_dataEncoding);
128 const XMLCh*
const localname,
129 const XMLCh*
const qname) {
130 if (m_mode == md_Idle)
133 if (m_mode == md_Parameter) {
134 m_parameters[m_pname] = m_text;
135 }
else if (m_mode == md_Data) {
138 for (std::string::iterator
q = m_text.begin();
q != m_text.end();
q++) {
142 m_items.push_back(entry);
152 if (m_mode == md_Idle)
157 if (m_mode == md_Idle)
160 while (offset < length) {
162 for (i = 0; i < length - offset && i < 255; i++)
163 m_workx[i] = chars[i + offset];
165 XMLString::transcode(m_workx, m_workc, 511);
172 std::map<std::string, std::string>&
parameters,
173 std::vector<std::string>&
items,
179 if (m_parser ==
nullptr) {
181 m_parser->parser = std::unique_ptr<xercesc::SAX2XMLReader>(xercesc::XMLReaderFactory::createXMLReader());
184 MemBufInputSource
src((
const unsigned char*)xmlDocument.c_str(), xmlDocument.length(),
"hcal::PatternReader");
185 m_parser->parser->setContentHandler(&handler);
186 m_parser->parser->parse(
src);
193 std::map<std::string, std::string>&
parameters,
194 std::vector<uint32_t>&
data) {
195 std::vector<std::string>
items;
198 this->
parse(xmlDocument, parameters, items, encoding);
200 if (encoding ==
"dec")
202 if (encoding ==
"hex")
206 for (std::vector<std::string>::const_iterator
i = items.begin();
i != items.end();
i++)
207 data.push_back(strtol(
i->c_str(),
nullptr, formatting));
void parse(const std::string &xmlDocument, std::map< std::string, std::string > ¶meters, std::vector< std::string > &items, std::string &encoding)
bool cvt2String(const XMLCh *val, std::string &ou)
std::vector< std::string > & m_items
void characters(const XMLCh *const chars, const XMLSize_t length) override
std::string & m_dataEncoding
std::unique_ptr< SAX2XMLReader > parser
ConfigurationDBHandler(std::map< std::string, std::string > ¶meters, std::vector< std::string > &items, std::string &encoding)
void ignorableWhitespace(const XMLCh *const chars, const XMLSize_t length) override
std::map< std::string, std::string > & m_parameters
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) override
char data[epos_bytes_allocation]
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
~ConfigurationDBHandler() override