Blame include/cppunit/tools/XmlElement.h

Packit 8c9aa0
#ifndef CPPUNIT_TOOLS_XMLELEMENT_H
Packit 8c9aa0
#define CPPUNIT_TOOLS_XMLELEMENT_H
Packit 8c9aa0
Packit 8c9aa0
#include <cppunit/Portability.h>
Packit 8c9aa0
Packit 8c9aa0
#if CPPUNIT_NEED_DLL_DECL
Packit 8c9aa0
#pragma warning( push )
Packit 8c9aa0
#pragma warning( disable: 4251 )  // X needs to have dll-interface to be used by clients of class Z
Packit 8c9aa0
#endif
Packit 8c9aa0
Packit 8c9aa0
#include <deque>
Packit 8c9aa0
#include <string>
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
CPPUNIT_NS_BEGIN
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
class XmlElement;
Packit 8c9aa0
Packit 8c9aa0
#if CPPUNIT_NEED_DLL_DECL
Packit 8c9aa0
//  template class CPPUNIT_API std::deque<XmlElement *>;
Packit 8c9aa0
#endif
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/*! \brief A XML Element.
Packit 8c9aa0
 * 
Packit 8c9aa0
 * A XML element has:
Packit 8c9aa0
 * - a name, specified on construction,
Packit 8c9aa0
 * - a content, specified on construction (may be empty),
Packit 8c9aa0
 * - zero or more attributes, added with addAttribute(),
Packit 8c9aa0
 * - zero or more child elements, added with addElement().
Packit 8c9aa0
 */
Packit 8c9aa0
class CPPUNIT_API XmlElement
Packit 8c9aa0
{
Packit 8c9aa0
public:
Packit 8c9aa0
  /*! \brief Constructs an element with the specified name and string content.
Packit 8c9aa0
   * \param elementName Name of the element. Must not be empty.
Packit 8c9aa0
   * \param content Content of the element.
Packit 8c9aa0
   */
Packit 8c9aa0
  XmlElement( std::string elementName,
Packit 8c9aa0
              std::string content ="" );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Constructs an element with the specified name and numeric content.
Packit 8c9aa0
   * \param elementName Name of the element. Must not be empty.
Packit 8c9aa0
   * \param numericContent Content of the element.
Packit 8c9aa0
   */
Packit 8c9aa0
  XmlElement( std::string elementName,
Packit 8c9aa0
              int numericContent );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Destructs the element and its child elements.
Packit 8c9aa0
   */
Packit 8c9aa0
  virtual ~XmlElement();
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Returns the name of the element.
Packit 8c9aa0
   * \return Name of the element.
Packit 8c9aa0
   */
Packit 8c9aa0
  std::string name() const;
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Returns the content of the element.
Packit 8c9aa0
   * \return Content of the element.
Packit 8c9aa0
   */
Packit 8c9aa0
  std::string content() const;
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Sets the name of the element.
Packit 8c9aa0
   * \param name New name for the element.
Packit 8c9aa0
   */
Packit 8c9aa0
  void setName( const std::string &name );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Sets the content of the element.
Packit 8c9aa0
   * \param content New content for the element.
Packit 8c9aa0
   */
Packit 8c9aa0
  void setContent( const std::string &content );
Packit 8c9aa0
Packit 8c9aa0
  /*! \overload void setContent( const std::string &content )
Packit 8c9aa0
   */
Packit 8c9aa0
  void setContent( int numericContent );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Adds an attribute with the specified string value.
Packit 8c9aa0
   * \param attributeName Name of the attribute. Must not be an empty.
Packit 8c9aa0
   * \param value Value of the attribute.
Packit 8c9aa0
   */
Packit 8c9aa0
  void addAttribute( std::string attributeName,
Packit 8c9aa0
                     std::string value );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Adds an attribute with the specified numeric value.
Packit 8c9aa0
   * \param attributeName Name of the attribute. Must not be empty.
Packit 8c9aa0
   * \param numericValue Numeric value of the attribute.
Packit 8c9aa0
   */
Packit 8c9aa0
  void addAttribute( std::string attributeName,
Packit 8c9aa0
                     int numericValue );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Adds a child element to the element.
Packit 8c9aa0
   * \param element Child element to add. Must not be \c NULL.
Packit 8c9aa0
   */
Packit 8c9aa0
  void addElement( XmlElement *element );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Returns the number of child elements.
Packit 8c9aa0
   * \return Number of child elements (element added with addElement()).
Packit 8c9aa0
   */
Packit 8c9aa0
  int elementCount() const;
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Returns the child element at the specified index.
Packit 8c9aa0
   * \param index Zero based index of the element to return.
Packit 8c9aa0
   * \returns Element at the specified index. Never \c NULL.
Packit 8c9aa0
   * \exception std::invalid_argument if \a index < 0 or index >= elementCount().
Packit 8c9aa0
   */
Packit 8c9aa0
  XmlElement *elementAt( int index ) const;
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Returns the first child element with the specified name.
Packit 8c9aa0
   * \param name Name of the child element to return.
Packit 8c9aa0
   * \return First child element found which is named \a name.
Packit 8c9aa0
   * \exception std::invalid_argument if there is no child element with the specified
Packit 8c9aa0
   *            name.
Packit 8c9aa0
   */
Packit 8c9aa0
  XmlElement *elementFor( const std::string &name ) const;
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Returns a XML string that represents the element.
Packit 8c9aa0
   * \param indent String of spaces representing the amount of 'indent'.
Packit 8c9aa0
   * \return XML string that represents the element, its attributes and its
Packit 8c9aa0
   *         child elements.
Packit 8c9aa0
   */
Packit 8c9aa0
  std::string toString( const std::string &indent = "" ) const;
Packit 8c9aa0
Packit 8c9aa0
private:
Packit 8c9aa0
  typedef std::pair<std::string,std::string> Attribute;
Packit 8c9aa0
Packit 8c9aa0
  std::string attributesAsString() const;
Packit 8c9aa0
  std::string escape( std::string value ) const;
Packit 8c9aa0
Packit 8c9aa0
private:
Packit 8c9aa0
  std::string m_name;
Packit 8c9aa0
  std::string m_content;
Packit 8c9aa0
Packit 8c9aa0
  typedef std::deque<Attribute> Attributes;
Packit 8c9aa0
  Attributes m_attributes;
Packit 8c9aa0
Packit 8c9aa0
  typedef std::deque<XmlElement *> Elements;
Packit 8c9aa0
  Elements m_elements;
Packit 8c9aa0
};
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
CPPUNIT_NS_END
Packit 8c9aa0
Packit 8c9aa0
#if CPPUNIT_NEED_DLL_DECL
Packit 8c9aa0
#pragma warning( pop )
Packit 8c9aa0
#endif
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
#endif  // CPPUNIT_TOOLS_XMLELEMENT_H