nidas v1.2.3
XMLStringConverter.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_XMLSTRINGCONVERTER_H
28#define NIDAS_CORE_XMLSTRINGCONVERTER_H
29
30#include<xercesc/util/XMLString.hpp>
31
32namespace nidas { namespace core {
33
39public:
40
41 XMLStringConverter(const XMLCh* val) :
42 _str(),_cxstr(val),_xstr(0)
43 {
44 char* cstr = xercesc::XMLString::transcode(val);
45 _str = std::string(cstr ? cstr : "");
46 xercesc::XMLString::release(&cstr);
47 }
48
49 XMLStringConverter(const char* val) :
50 _str(val),_cxstr(0),
51 _xstr(xercesc::XMLString::transcode(val))
52 {
53 _cxstr = _xstr;
54 }
55
56 XMLStringConverter(const std::string& val) :
57 _str(val),_cxstr(0),
58 _xstr(xercesc::XMLString::transcode(val.c_str()))
59 {
60 _cxstr = _xstr;
61 }
62
64 if (_xstr) xercesc::XMLString::release(&_xstr);
65 }
66
70 operator const XMLCh*() const { return _cxstr; }
71
75 operator std::string() const
76 {
77 return _str;
78 }
79
80private:
81 std::string _str;
82 const XMLCh *_cxstr;
83 XMLCh *_xstr;
84
87
90
91};
92
93inline std::ostream& operator<<(std::ostream& target,
94 const XMLStringConverter& toDump)
95{
96 target << (std::string)toDump;
97 return target;
98}
99
100}} // namespace nidas namespace core
101
102#endif
Class providing conversions between string and XMLCh* using the Xerces-c transcode and release method...
Definition XMLStringConverter.h:38
XMLStringConverter & operator=(const XMLStringConverter &)
No assignment.
XMLStringConverter(const std::string &val)
Definition XMLStringConverter.h:56
XMLStringConverter(const XMLStringConverter &)
No copying.
XMLStringConverter(const XMLCh *val)
Definition XMLStringConverter.h:41
~XMLStringConverter()
Definition XMLStringConverter.h:63
std::string _str
Definition XMLStringConverter.h:81
XMLStringConverter(const char *val)
Definition XMLStringConverter.h:49
const XMLCh * _cxstr
Definition XMLStringConverter.h:82
XMLCh * _xstr
Definition XMLStringConverter.h:83
std::ostream & operator<<(std::ostream &out, const BadSampleFilter &bsf)
Stream the current rules for BadSampleFilter bsf to out.
Definition BadSampleFilter.cc:347
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