Commit 14ee991b035d376f2a44d98d2b28dcb246e498b2

Authored by knodlseder
1 parent 821ba737

initial version

include/GXmlDocument.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GXmlDocument.hpp - XML document node class definition *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GXmlDocument.hpp
  15 + * @brief XML document node class definition
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef GXMLDOCUMENT_HPP
  20 +#define GXMLDOCUMENT_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include <iostream>
  24 +#include "GXmlNode.hpp"
  25 +
  26 +
  27 +/***********************************************************************//**
  28 + * @class GXmlDocument
  29 + *
  30 + * @brief XML document node class interface defintion.
  31 + ***************************************************************************/
  32 +class GXmlDocument : public GXmlNode {
  33 +
  34 +public:
  35 + // Constructors and destructors
  36 + GXmlDocument(void);
  37 + GXmlDocument(const GXmlDocument& node);
  38 + ~GXmlDocument(void);
  39 +
  40 + // Operators
  41 + GXmlDocument& operator= (const GXmlDocument& node);
  42 +
  43 + // Methods
  44 + void clear(void);
  45 + void print(std::ostream& os, int indent = 0) const;
  46 + NodeType type(void) const { return NT_DOCUMENT; }
  47 +
  48 +protected:
  49 + // Protected methods
  50 + void init_members(void);
  51 + void copy_members(const GXmlDocument& node);
  52 + void free_members(void);
  53 + GXmlDocument* GXmlDocument::clone(void) const;
  54 +
  55 + // Protected data members
  56 +};
  57 +
  58 +#endif /* GXMLDOCUMENT_HPP */
include/GXmlElement.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GXmlElement.hpp - XML element node class definition *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GXmlElement.hpp
  15 + * @brief XML element node class definition
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef GXMLELEMENT_HPP
  20 +#define GXMLELEMENT_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include <string>
  24 +#include <iostream>
  25 +#include "GXml.hpp"
  26 +#include "GXmlNode.hpp"
  27 +
  28 +
  29 +/***********************************************************************//**
  30 + * @class GXmlElement
  31 + *
  32 + * @brief XML element node class interface defintion.
  33 + ***************************************************************************/
  34 +class GXmlElement : public GXmlNode {
  35 +
  36 + // Friend classes
  37 + friend class GXml;
  38 +
  39 +public:
  40 + // Constructors and destructors
  41 + GXmlElement(void);
  42 + GXmlElement(const GXmlElement& node);
  43 + GXmlElement(const std::string& segment);
  44 + ~GXmlElement(void);
  45 +
  46 + // Operators
  47 + GXmlElement& operator= (const GXmlElement& node);
  48 +
  49 + // Methods
  50 + void clear(void);
  51 + void print(std::ostream& os, int indent = 0) const;
  52 + NodeType type(void) const { return NT_ELEMENT; }
  53 + std::string name(void) const { return m_name; }
  54 + GXmlNode* parent(void) const { return m_parent; }
  55 + void parent(GXmlNode* node) { m_parent = node; }
  56 +
  57 +protected:
  58 + // Protected methods
  59 + void init_members(void);
  60 + void copy_members(const GXmlElement& node);
  61 + void free_members(void);
  62 + GXmlElement* GXmlElement::clone(void) const;
  63 + void parse_start(const std::string& segment);
  64 + void parse_stop(const std::string& segment);
  65 +
  66 + // Protected data members
  67 + std::string m_name; //!< Element name
  68 + GXmlNode* m_parent; //!< Pointer on parent node
  69 +};
  70 +
  71 +#endif /* GXMLELEMENT_HPP */
include/GXmlText.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GXmlText.hpp - XML text node class definition *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GXmlText.hpp
  15 + * @brief XML text node class definition
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef GXMLTEXT_HPP
  20 +#define GXMLTEXT_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include <string>
  24 +#include <iostream>
  25 +#include "GXmlNode.hpp"
  26 +
  27 +
  28 +/***********************************************************************//**
  29 + * @class GXmlText
  30 + *
  31 + * @brief XML text node class interface defintion.
  32 + ***************************************************************************/
  33 +class GXmlText : public GXmlNode {
  34 +
  35 +public:
  36 + // Constructors and destructors
  37 + GXmlText(void);
  38 + GXmlText(const GXmlText& node);
  39 + GXmlText(const std::string& text);
  40 + ~GXmlText(void);
  41 +
  42 + // Operators
  43 + GXmlText& operator= (const GXmlText& node);
  44 +
  45 + // Methods
  46 + void clear(void);
  47 + void print(std::ostream& os, int indent = 0) const;
  48 + NodeType type(void) const { return NT_TEXT; }
  49 +
  50 +protected:
  51 + // Protected methods
  52 + void init_members(void);
  53 + void copy_members(const GXmlText& node);
  54 + void free_members(void);
  55 + GXmlText* GXmlText::clone(void) const;
  56 +
  57 + // Protected data members
  58 + std::string m_text; //!< Text
  59 +};
  60 +
  61 +#endif /* GXMLTEXT_HPP */
src/xml/GException_xml.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GException_xml.cpp - XML exception handlers *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +
  14 +/* __ Includes ___________________________________________________________ */
  15 +#ifdef HAVE_CONFIG_H
  16 +#include <config.h>
  17 +#endif
  18 +#include "GException.hpp"
  19 +#include "GTools.hpp"
  20 +
  21 +
  22 +/***********************************************************************//**
  23 + * @brief XML syntax error
  24 + *
  25 + * @param[in] origin Method that throws the error.
  26 + * @param[in] segment XML segment for which syntax error was encountered.
  27 + * @param[in] message Optional error message.
  28 + ***************************************************************************/
  29 +GException::xml_syntax_error::xml_syntax_error(std::string origin,
  30 + std::string segment,
  31 + std::string message)
  32 +{
  33 + // Set origin and message
  34 + m_origin = origin;
  35 + m_message = "XML syntax error ("+message+") occured in "+segment;
  36 +
  37 + // Return
  38 + return;
  39 +}
src/xml/GXmlDocument.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GXmlDocument.cpp - XML document node class implementation *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GXmlDocument.cpp
  15 + * @brief XML document node class implementation
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <iostream>
  24 +#include "GXmlDocument.hpp"
  25 +
  26 +/* __ Method name definitions ____________________________________________ */
  27 +
  28 +/* __ Macros _____________________________________________________________ */
  29 +
  30 +/* __ Coding definitions _________________________________________________ */
  31 +
  32 +/* __ Debug definitions __________________________________________________ */
  33 +
  34 +
  35 +/*==========================================================================
  36 + = =
  37 + = Constructors/destructors =
  38 + = =
  39 + ==========================================================================*/
  40 +
  41 +/***********************************************************************//**
  42 + * @brief Void constructor
  43 + ***************************************************************************/
  44 +GXmlDocument::GXmlDocument(void) : GXmlNode()
  45 +{
  46 + // Initialise private members for clean destruction
  47 + init_members();
  48 +
  49 + // Return
  50 + return;
  51 +}
  52 +
  53 +
  54 +/***********************************************************************//**
  55 + * @brief Copy constructor
  56 + *
  57 + * @param[in] node Object from which the instance should be built.
  58 + ***************************************************************************/
  59 +GXmlDocument::GXmlDocument(const GXmlDocument& node) : GXmlNode(node)
  60 +{
  61 + // Initialise private members for clean destruction
  62 + init_members();
  63 +
  64 + // Copy members
  65 + copy_members(node);
  66 +
  67 + // Return
  68 + return;
  69 +}
  70 +
  71 +
  72 +/***********************************************************************//**
  73 + * @brief Destructor
  74 + ***************************************************************************/
  75 +GXmlDocument::~GXmlDocument(void)
  76 +{
  77 + // Free members
  78 + free_members();
  79 +
  80 + // Return
  81 + return;
  82 +}
  83 +
  84 +
  85 +/*==========================================================================
  86 + = =
  87 + = Operators =
  88 + = =
  89 + ==========================================================================*/
  90 +
  91 +/***********************************************************************//**
  92 + * @brief Assignment operator
  93 + *
  94 + * @param[in] node Object which should be assigned.
  95 + ***************************************************************************/
  96 +GXmlDocument& GXmlDocument::operator= (const GXmlDocument& node)
  97 +{
  98 + // Execute only if object is not identical
  99 + if (this != &node) {
  100 +
  101 + // Copy base class members
  102 + this->GXmlNode::operator=(node);
  103 +
  104 + // Free members
  105 + free_members();
  106 +
  107 + // Initialise private members for clean destruction
  108 + init_members();
  109 +
  110 + // Copy members
  111 + copy_members(node);
  112 +
  113 + } // endif: object was not identical
  114 +
  115 + // Return
  116 + return *this;
  117 +}
  118 +
  119 +
  120 +/*==========================================================================
  121 + = =
  122 + = Public methods =
  123 + = =
  124 + ==========================================================================*/
  125 +
  126 + /***********************************************************************//**
  127 + * @brief Clear object.
  128 + *
  129 + * This method properly resets the object to an initial state.
  130 + ***************************************************************************/
  131 +void GXmlDocument::clear(void)
  132 +{
  133 + // Free class members (base and derived classes, derived class first)
  134 + free_members();
  135 + this->GXmlNode::free_members();
  136 +
  137 + // Initialise members
  138 + this->GXmlNode::init_members();
  139 + init_members();
  140 +
  141 + // Return
  142 + return;
  143 +}
  144 +
  145 +
  146 +/***********************************************************************//**
  147 + * @brief Print node in output stream
  148 + *
  149 + * @param[in] os Output stream into which the node will be printed.
  150 + ***************************************************************************/
  151 +void GXmlDocument::print(std::ostream& os, int indent) const
  152 +{
  153 + // Put document header in output stream
  154 + for (int k = 0; k < indent; ++k)
  155 + os << " ";
  156 + os << "GXmlDocument::";
  157 +
  158 + // Put children in stream
  159 + for (int i = 0; i < size(); ++i) {
  160 + os << std::endl;
  161 + m_nodes[i]->print(os, indent);
  162 + }
  163 +
  164 + // Return
  165 + return;
  166 +}
  167 +
  168 +
  169 +/*==========================================================================
  170 + = =
  171 + = Private methods =
  172 + = =
  173 + ==========================================================================*/
  174 +
  175 +/***********************************************************************//**
  176 + * @brief Initialise class members
  177 + ***************************************************************************/
  178 +void GXmlDocument::init_members(void)
  179 +{
  180 + // Initialise members
  181 +
  182 + // Return
  183 + return;
  184 +}
  185 +
  186 +
  187 +/***********************************************************************//**
  188 + * @brief Copy class members
  189 + *
  190 + * @param[in] node Object from which members which should be copied.
  191 + ***************************************************************************/
  192 +void GXmlDocument::copy_members(const GXmlDocument& node)
  193 +{
  194 + // Copy attributes
  195 +
  196 + // Return
  197 + return;
  198 +}
  199 +
  200 +
  201 +/***********************************************************************//**
  202 + * @brief Delete class members
  203 + ***************************************************************************/
  204 +void GXmlDocument::free_members(void)
  205 +{
  206 + // Return
  207 + return;
  208 +}
  209 +
  210 +
  211 +/***********************************************************************//**
  212 + * @brief Clone class
  213 +***************************************************************************/
  214 +GXmlDocument* GXmlDocument::clone(void) const
  215 +{
  216 + return new GXmlDocument(*this);
  217 +}
  218 +
  219 +
  220 +/*==========================================================================
  221 + = =
  222 + = Friends =
  223 + = =
  224 + ==========================================================================*/
src/xml/GXmlElement.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GXmlElement.cpp - XML element node class implementation *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GXmlElement.cpp
  15 + * @brief XML element node class implementation
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <string>
  24 +#include <iostream>
  25 +#include "GException.hpp"
  26 +#include "GXmlElement.hpp"
  27 +
  28 +/* __ Method name definitions ____________________________________________ */
  29 +#define G_PARSE_START "GXmlElement::parse_start(std::string&)"
  30 +#define G_PARSE_STOP "GXmlElement::parse_stop(std::string&)"
  31 +
  32 +/* __ Macros _____________________________________________________________ */
  33 +
  34 +/* __ Coding definitions _________________________________________________ */
  35 +
  36 +/* __ Debug definitions __________________________________________________ */
  37 +
  38 +
  39 +/*==========================================================================
  40 + = =
  41 + = Constructors/destructors =
  42 + = =
  43 + ==========================================================================*/
  44 +
  45 +/***********************************************************************//**
  46 + * @brief Void constructor
  47 + ***************************************************************************/
  48 +GXmlElement::GXmlElement(void) : GXmlNode()
  49 +{
  50 + // Initialise private members for clean destruction
  51 + init_members();
  52 +
  53 + // Return
  54 + return;
  55 +}
  56 +
  57 +
  58 +/***********************************************************************//**
  59 + * @brief Copy constructor
  60 + *
  61 + * @param[in] node Object from which the instance should be built.
  62 + ***************************************************************************/
  63 +GXmlElement::GXmlElement(const GXmlElement& node) : GXmlNode(node)
  64 +{
  65 + // Initialise private members for clean destruction
  66 + init_members();
  67 +
  68 + // Copy members
  69 + copy_members(node);
  70 +
  71 + // Return
  72 + return;
  73 +}
  74 +
  75 +
  76 +/***********************************************************************//**
  77 + * @brief Segment constructor
  78 + *
  79 + * @param[in] segment XML segment from which instance is built.
  80 + ***************************************************************************/
  81 +GXmlElement::GXmlElement(const std::string& segment) : GXmlNode()
  82 +{
  83 + // Initialise private members for clean destruction
  84 + init_members();
  85 +
  86 + // Parse start element
  87 + parse_start(segment);
  88 +
  89 + // Return
  90 + return;
  91 +}
  92 +
  93 +
  94 +/***********************************************************************//**
  95 + * @brief Destructor
  96 + ***************************************************************************/
  97 +GXmlElement::~GXmlElement(void)
  98 +{
  99 + // Free members
  100 + free_members();
  101 +
  102 + // Return
  103 + return;
  104 +}
  105 +
  106 +
  107 +/*==========================================================================
  108 + = =
  109 + = Operators =
  110 + = =
  111 + ==========================================================================*/
  112 +
  113 +/***********************************************************************//**
  114 + * @brief Assignment operator
  115 + *
  116 + * @param[in] node Object which should be assigned.
  117 + ***************************************************************************/
  118 +GXmlElement& GXmlElement::operator= (const GXmlElement& node)
  119 +{
  120 + // Execute only if object is not identical
  121 + if (this != &node) {
  122 +
  123 + // Copy base class members
  124 + this->GXmlNode::operator=(node);
  125 +
  126 + // Free members
  127 + free_members();
  128 +
  129 + // Initialise private members for clean destruction
  130 + init_members();
  131 +
  132 + // Copy members
  133 + copy_members(node);
  134 +
  135 + } // endif: object was not identical
  136 +
  137 + // Return
  138 + return *this;
  139 +}
  140 +
  141 +
  142 +/*==========================================================================
  143 + = =
  144 + = Public methods =
  145 + = =
  146 + ==========================================================================*/
  147 +
  148 + /***********************************************************************//**
  149 + * @brief Clear object.
  150 + *
  151 + * This method properly resets the object to an initial state.
  152 + ***************************************************************************/
  153 +void GXmlElement::clear(void)
  154 +{
  155 + // Free class members (base and derived classes, derived class first)
  156 + free_members();
  157 + this->GXmlNode::free_members();
  158 +
  159 + // Initialise members
  160 + this->GXmlNode::init_members();
  161 + init_members();
  162 +
  163 + // Return
  164 + return;
  165 +}
  166 +
  167 +
  168 +/***********************************************************************//**
  169 + * @brief Print node in output stream
  170 + *
  171 + * @param[in] os Output stream into which the node will be printed.
  172 + ***************************************************************************/
  173 +void GXmlElement::print(std::ostream& os, int indent) const
  174 +{
  175 + // Put element name in output stream
  176 + for (int k = 0; k < indent; ++k)
  177 + os << " ";
  178 + os << "GXmlElement::" << m_name;
  179 +
  180 + // Put children in stream
  181 + for (int i = 0; i < size(); ++i) {
  182 + os << std::endl;
  183 + m_nodes[i]->print(os, indent+4);
  184 + }
  185 +
  186 + // Return
  187 + return;
  188 +}
  189 +
  190 +
  191 +/*==========================================================================
  192 + = =
  193 + = Private methods =
  194 + = =
  195 + ==========================================================================*/
  196 +
  197 +/***********************************************************************//**
  198 + * @brief Initialise class members
  199 + ***************************************************************************/
  200 +void GXmlElement::init_members(void)
  201 +{
  202 + // Initialise members
  203 + m_name.clear();
  204 + m_parent = NULL;
  205 +
  206 + // Return
  207 + return;
  208 +}
  209 +
  210 +
  211 +/***********************************************************************//**
  212 + * @brief Copy class members
  213 + *
  214 + * @param[in] node Object from which members which should be copied.
  215 + ***************************************************************************/
  216 +void GXmlElement::copy_members(const GXmlElement& node)
  217 +{
  218 + // Copy attributes
  219 + m_name = node.m_name;
  220 + m_parent = node.m_parent;
  221 +
  222 + // Return
  223 + return;
  224 +}
  225 +
  226 +
  227 +/***********************************************************************//**
  228 + * @brief Delete class members
  229 + ***************************************************************************/
  230 +void GXmlElement::free_members(void)
  231 +{
  232 + // Return
  233 + return;
  234 +}
  235 +
  236 +
  237 +/***********************************************************************//**
  238 + * @brief Clone class
  239 +***************************************************************************/
  240 +GXmlElement* GXmlElement::clone(void) const
  241 +{
  242 + return new GXmlElement(*this);
  243 +}
  244 +
  245 +
  246 +/***********************************************************************//**
  247 + * @brief Parse element start segment string
  248 + *
  249 + * @param[in] segement Segment string.
  250 + *
  251 + * @exception GException::xml_syntax_error
  252 + * XML syntax error.
  253 + *
  254 + * Parse the segment string and set class members based on the information
  255 + * that is found. The method also performs syntax checking.
  256 + ***************************************************************************/
  257 +void GXmlElement::parse_start(const std::string& segment)
  258 +{
  259 + // Get length of segment
  260 + int n = segment.length();
  261 +
  262 + // Check on existence of brackets
  263 + if (n < 2 || (segment.compare(0,1,"<") != 0) ||
  264 + (segment.compare(n-1,1,">") != 0))
  265 + throw GException::xml_syntax_error(G_PARSE_START, segment,
  266 + "tag brackets missing");
  267 +
  268 + // Extract element name
  269 + size_t pos = segment.find_first_of("\x20\x09\x0d\x0a>", 1);
  270 + if (pos == 1)
  271 + throw GException::xml_syntax_error(G_PARSE_START, segment,
  272 + "no whitespace allowed after '<'");
  273 + if (pos == std::string::npos)
  274 + throw GException::xml_syntax_error(G_PARSE_START, segment,
  275 + "element name not found");
  276 + m_name = segment.substr(1, pos-1);
  277 +
  278 + // Return
  279 + return;
  280 +}
  281 +
  282 +
  283 +/***********************************************************************//**
  284 + * @brief Parse element stop segment string
  285 + *
  286 + * @param[in] segement Segment string.
  287 + *
  288 + * @exception GException::xml_syntax_error
  289 + * XML syntax error.
  290 + *
  291 + * Parse the stop segment string and verify the syntax.
  292 + ***************************************************************************/
  293 +void GXmlElement::parse_stop(const std::string& segment)
  294 +{
  295 + // Get length of segment
  296 + int n = segment.length();
  297 +
  298 + // Check on existence of brackets
  299 + if (n < 3 || (segment.compare(0,2,"</") != 0) ||
  300 + (segment.compare(n-1,1,">") != 0))
  301 + throw GException::xml_syntax_error(G_PARSE_STOP, segment,
  302 + "incorrect or missing tag brackets");
  303 +
  304 + // Extract and verify element name
  305 + size_t pos = segment.find_first_of("\x20\x09\x0d\x0a>", 2);
  306 + if (pos == 2)
  307 + throw GException::xml_syntax_error(G_PARSE_STOP, segment,
  308 + "no whitespace allowed after '</'");
  309 + if (pos == std::string::npos)
  310 + throw GException::xml_syntax_error(G_PARSE_STOP, segment,
  311 + "element name not found");
  312 + std::string name = segment.substr(2, pos-2);
  313 + if (name != m_name)
  314 + throw GException::xml_syntax_error(G_PARSE_STOP, segment,
  315 + "invalid name in element stop tag"
  316 + " (found "+name+", expected "+m_name);
  317 +
  318 + // Verify that no further characters exist in element stop tag
  319 + size_t pos2 = segment.find_first_of("\x20\x09\x0d\x0a>", pos);
  320 + if (pos2 != n-1)
  321 + throw GException::xml_syntax_error(G_PARSE_STOP, segment,
  322 + "invalid characters found after element name");
  323 +
  324 + // Return
  325 + return;
  326 +}
  327 +
  328 +
  329 +/*==========================================================================
  330 + = =
  331 + = Friends =
  332 + = =
  333 + ==========================================================================*/
  334 +
src/xml/GXmlText.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GXmlText.cpp - XML text node class implementation *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GXmlText.cpp
  15 + * @brief XML text node class implementation
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <iostream>
  24 +#include "GXmlText.hpp"
  25 +
  26 +/* __ Method name definitions ____________________________________________ */
  27 +
  28 +/* __ Macros _____________________________________________________________ */
  29 +
  30 +/* __ Coding definitions _________________________________________________ */
  31 +
  32 +/* __ Debug definitions __________________________________________________ */
  33 +
  34 +
  35 +/*==========================================================================
  36 + = =
  37 + = Constructors/destructors =
  38 + = =
  39 + ==========================================================================*/
  40 +
  41 +/***********************************************************************//**
  42 + * @brief Void constructor
  43 + ***************************************************************************/
  44 +GXmlText::GXmlText(void) : GXmlNode()
  45 +{
  46 + // Initialise private members for clean destruction
  47 + init_members();
  48 +
  49 + // Return
  50 + return;
  51 +}
  52 +
  53 +
  54 +/***********************************************************************//**
  55 + * @brief Copy constructor
  56 + *
  57 + * @param[in] node Object from which the instance should be built.
  58 + ***************************************************************************/
  59 +GXmlText::GXmlText(const GXmlText& node) : GXmlNode(node)
  60 +{
  61 + // Initialise private members for clean destruction
  62 + init_members();
  63 +
  64 + // Copy members
  65 + copy_members(node);
  66 +
  67 + // Return
  68 + return;
  69 +}
  70 +
  71 +
  72 +/***********************************************************************//**
  73 + * @brief Text constructor
  74 + *
  75 + * @param[in] text Text for instance building.
  76 + ***************************************************************************/
  77 +GXmlText::GXmlText(const std::string& text) : GXmlNode()
  78 +{
  79 + // Initialise private members for clean destruction
  80 + init_members();
  81 +
  82 + // Set text
  83 + m_text = text;
  84 +
  85 + // Return
  86 + return;
  87 +}
  88 +
  89 +
  90 +/***********************************************************************//**
  91 + * @brief Destructor
  92 + ***************************************************************************/
  93 +GXmlText::~GXmlText(void)
  94 +{
  95 + // Free members
  96 + free_members();
  97 +
  98 + // Return
  99 + return;
  100 +}
  101 +
  102 +
  103 +/*==========================================================================
  104 + = =
  105 + = Operators =
  106 + = =
  107 + ==========================================================================*/
  108 +
  109 +/***********************************************************************//**
  110 + * @brief Assignment operator
  111 + *
  112 + * @param[in] node Object which should be assigned.
  113 + ***************************************************************************/
  114 +GXmlText& GXmlText::operator= (const GXmlText& node)
  115 +{
  116 + // Execute only if object is not identical
  117 + if (this != &node) {
  118 +
  119 + // Copy base class members
  120 + this->GXmlNode::operator=(node);
  121 +
  122 + // Free members
  123 + free_members();
  124 +
  125 + // Initialise private members for clean destruction
  126 + init_members();
  127 +
  128 + // Copy members
  129 + copy_members(node);
  130 +
  131 + } // endif: object was not identical
  132 +
  133 + // Return
  134 + return *this;
  135 +}
  136 +
  137 +
  138 +/*==========================================================================
  139 + = =
  140 + = Public methods =
  141 + = =
  142 + ==========================================================================*/
  143 +
  144 + /***********************************************************************//**
  145 + * @brief Clear object.
  146 + *
  147 + * This method properly resets the object to an initial state.
  148 + ***************************************************************************/
  149 +void GXmlText::clear(void)
  150 +{
  151 + // Free class members (base and derived classes, derived class first)
  152 + free_members();
  153 + this->GXmlNode::free_members();
  154 +
  155 + // Initialise members
  156 + this->GXmlNode::init_members();
  157 + init_members();
  158 +
  159 + // Return
  160 + return;
  161 +}
  162 +
  163 +
  164 +/***********************************************************************//**
  165 + * @brief Print node in output stream
  166 + *
  167 + * @param[in] os Output stream into which the node will be printed.
  168 + ***************************************************************************/
  169 +void GXmlText::print(std::ostream& os, int indent) const
  170 +{
  171 + // Put node in output stream
  172 + os << "=== GXmlText ===" << std::endl;
  173 + os << m_text;
  174 +
  175 + // Return
  176 + return;
  177 +}
  178 +
  179 +
  180 +/*==========================================================================
  181 + = =
  182 + = Private methods =
  183 + = =
  184 + ==========================================================================*/
  185 +
  186 +/***********************************************************************//**
  187 + * @brief Initialise class members
  188 + ***************************************************************************/
  189 +void GXmlText::init_members(void)
  190 +{
  191 + // Initialise members
  192 + m_text.clear();
  193 +
  194 + // Return
  195 + return;
  196 +}
  197 +
  198 +
  199 +/***********************************************************************//**
  200 + * @brief Copy class members
  201 + *
  202 + * @param[in] node Object from which members which should be copied.
  203 + ***************************************************************************/
  204 +void GXmlText::copy_members(const GXmlText& node)
  205 +{
  206 + // Copy attributes
  207 + m_text = node.m_text;
  208 +
  209 + // Return
  210 + return;
  211 +}
  212 +
  213 +
  214 +/***********************************************************************//**
  215 + * @brief Delete class members
  216 + ***************************************************************************/
  217 +void GXmlText::free_members(void)
  218 +{
  219 + // Return
  220 + return;
  221 +}
  222 +
  223 +
  224 +/***********************************************************************//**
  225 + * @brief Clone class
  226 +***************************************************************************/
  227 +GXmlText* GXmlText::clone(void) const
  228 +{
  229 + return new GXmlText(*this);
  230 +}
  231 +
  232 +
  233 +/*==========================================================================
  234 + = =
  235 + = Friends =
  236 + = =
  237 + ==========================================================================*/
  238 +