nidas v1.2.3
XDOM.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2004, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27#ifndef NIDAS_CORE_XDOM_H
28#define NIDAS_CORE_XDOM_H
29
30#include "XMLStringConverter.h"
31
32#include <xercesc/dom/DOMElement.hpp>
33#include <xercesc/dom/DOMAttr.hpp>
34#include <xercesc/dom/DOMTypeInfo.hpp>
35
36#include <string>
37#include <map>
38
39namespace nidas { namespace core {
40
46public:
47 XDOMElement(const xercesc::DOMElement*e) :
50 _nodetype( e->getSchemaTypeInfo() ? (std::string)XMLStringConverter(e->getSchemaTypeInfo()->getTypeName()) : "")
51 {
52 }
53
54 XDOMElement(xercesc::DOMElement*e) :
57 {
58 }
59
64 const std::string& getAttributeValue(const std::string& aname) {
65 std::map<std::string,std::string>::const_iterator ai = _attrs.find(aname);
66 if (ai == _attrs.end()) {
67 XMLStringConverter cname(aname.c_str());
68
69 // returns empty string if attribute does not have a
70 // specified or default value.
71 XMLStringConverter aval(_elemConst->getAttribute((const XMLCh*)cname));
72
73 std::pair<const std::string,const std::string>
74 p(aname,aval);
75 _attrs.insert(p);
76 ai = _attrs.find(aname);
77 }
78 return ai->second;
79 }
80 void setAttributeValue(const std::string& name,const std::string& val)
81 {
84 if (_elemNonConst)
85 _elemNonConst->setAttribute((const XMLCh*)aname,(const XMLCh*)aval);
86 _attrs[name] = val;
87 }
88 const std::string& getNodeName() const { return _nodename; }
89
90 const std::string& getNodeType() const {return _nodetype; }
91
92 const xercesc::DOMElement* getElement() const { return _elemConst; }
93
94private:
95 const xercesc::DOMElement* _elemConst;
96
97 xercesc::DOMElement* _elemNonConst;
98
99 std::map<std::string,std::string> _attrs;
100
101 std::string _nodename;
102
103 std::string _nodetype;
104
107
110};
111
116class XDOMAttr {
117public:
118 XDOMAttr(const xercesc::DOMAttr*a) :
119 _attr(a),
122 {
123 }
124 const std::string& getName() const { return _name; }
125 const std::string& getValue() const { return _value; }
126protected:
127 const xercesc::DOMAttr* _attr;
128 std::string _name;
129 std::string _value;
130
131private:
134
137};
138
139}} // namespace nidas namespace core
140
141#endif
Class providing convienence methods to access the string attributes of a DOMAttr.
Definition XDOM.h:116
const std::string & getValue() const
Definition XDOM.h:125
const std::string & getName() const
Definition XDOM.h:124
std::string _value
Definition XDOM.h:129
std::string _name
Definition XDOM.h:128
XDOMAttr(const xercesc::DOMAttr *a)
Definition XDOM.h:118
XDOMAttr & operator=(const XDOMAttr &)
No assignment.
XDOMAttr(const XDOMAttr &)
No copying.
const xercesc::DOMAttr * _attr
Definition XDOM.h:127
Wrapper class providing convienence methods to access the string attributes of a DOMElement.
Definition XDOM.h:45
const std::string & getAttributeValue(const std::string &aname)
Definition XDOM.h:64
const xercesc::DOMElement * getElement() const
Definition XDOM.h:92
void setAttributeValue(const std::string &name, const std::string &val)
Definition XDOM.h:80
XDOMElement(xercesc::DOMElement *e)
Definition XDOM.h:54
std::string _nodetype
Definition XDOM.h:103
XDOMElement(const xercesc::DOMElement *e)
Definition XDOM.h:47
const std::string & getNodeType() const
Definition XDOM.h:90
std::string _nodename
Definition XDOM.h:101
XDOMElement & operator=(const XDOMElement &)
No assignment.
const std::string & getNodeName() const
Definition XDOM.h:88
XDOMElement(const XDOMElement &)
No copying.
xercesc::DOMElement * _elemNonConst
Definition XDOM.h:97
std::map< std::string, std::string > _attrs
Definition XDOM.h:99
const xercesc::DOMElement * _elemConst
Definition XDOM.h:95
Class providing conversions between string and XMLCh* using the Xerces-c transcode and release method...
Definition XMLStringConverter.h:38
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31