UnCoVer (Using Coverability for Verification)
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
xercesc_helpers.h
1 /***************************************************************************
2  * Copyright (C) 2014 by Jan Stückrath <jan.stueckrath@uni-due.de> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
18  ***************************************************************************/
19 
20 #ifndef XERCESC_HELPERS_H_
21 #define XERCESC_HELPERS_H_
22 
23 #include <xercesc/dom/DOM.hpp>
24 #include <xercesc/sax/SAXParseException.hpp>
25 #include <string>
26 
27 namespace uncover {
28  namespace io {
29 
34  template <class T>
35  class SafeXTString {
36 
37  public:
38 
43  SafeXTString (T* ptr) {stringPtr=ptr;}
44 
48  virtual ~SafeXTString() {xercesc::XMLString::release(&stringPtr);}
49 
55  T* getContent() {return stringPtr;}
56 
63  SafeXTString<T>& operator= (T* data) {xercesc::XMLString::release(&stringPtr); stringPtr = data; return *this;}
64 
72  friend std::ostream& operator<< (std::ostream& ost, SafeXTString<T>& data) { ost << data.stringPtr; return ost;}
73 
74  private:
75 
80 
81  };
82 
87  template <class T>
88  class SafeXRes {
89 
90  public:
91 
96  SafeXRes (T* ptr) {resPtr=ptr;}
97 
101  virtual ~SafeXRes() {resPtr->release();}
102 
108  T* getContent() {return resPtr;}
109 
114  T* operator->() {return resPtr;}
115 
116  private:
117 
121  T* resPtr;
122 
123  };
124 
130  extern std::string generateXerxesErrorMessage(const xercesc::XMLException& e);
131 
137  extern std::string generateXerxesErrorMessage(const xercesc::SAXParseException& e);
138 
139  }
140 }
141 
142 #endif /* XERCESC_HELPERS_H_ */
T * operator->()
Returns the pointer stored in this SafeXRes object.
Definition: xercesc_helpers.h:114
SafeXTString(T *ptr)
Generates a new SafeXTString with the specified (transcoded) string pointer as content.
Definition: xercesc_helpers.h:43
SafeXTString< T > & operator=(T *data)
Replaces the content of this container object with the given content.
Definition: xercesc_helpers.h:63
T * stringPtr
This pointer represent a string transcoded by Xercesc.
Definition: xercesc_helpers.h:79
T * getContent()
Returns the content stored in this SafeXRes object.
Definition: xercesc_helpers.h:108
T * resPtr
This pointer represent a releasable Xerces resource.
Definition: xercesc_helpers.h:121
virtual ~SafeXRes()
Destroys this SafeXRes object.
Definition: xercesc_helpers.h:101
This template provides a container which automatically release a given Xerces resource, when the pointer runs out of scope.
Definition: xercesc_helpers.h:88
std::string generateXerxesErrorMessage(const xercesc::XMLException &e)
Generates and returns a string representing the error message in the given exception.
Definition: xercesc_helpers.cpp:26
This template provides a container which automatically releases a transcoded string, when the pointer runs out of scope.
Definition: xercesc_helpers.h:35
T * getContent()
Returns the content stored in this SafeXTString object.
Definition: xercesc_helpers.h:55
SafeXRes(T *ptr)
Generates a new SafeXRes with the specified resource pointer as content.
Definition: xercesc_helpers.h:96
virtual ~SafeXTString()
Destroys this SafeXTString object.
Definition: xercesc_helpers.h:48