Rapicorn - Experimental UI Toolkit - Source Code  13.07.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
xmlnode.hh
Go to the documentation of this file.
00001  // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __RAPICORN_XMLNODE_HH__
00003 #define __RAPICORN_XMLNODE_HH__
00004 
00005 #include <rcore/markup.hh>
00006 #include <rcore/objects.hh>
00007 
00008 namespace Rapicorn {
00009 
00010 class XmlNode : public virtual ReferenceCountable, public virtual DataListContainer {
00011   String                name_; // element name
00012   XmlNode              *parent_;
00013   StringVector          attribute_names_;
00014   StringVector          attribute_values_;
00015   String                file_;
00016   uint                  line_, char_;
00017 protected:
00018   explicit              XmlNode         (const String&, uint, uint, const String&);
00019   uint64                flags           () const;
00020   void                  flags           (uint64 flags);
00021   virtual              ~XmlNode         ();
00022   static void           set_parent      (XmlNode *c, XmlNode *p);
00023 public:
00024   typedef const vector<XmlNode*>     ConstNodes;
00025   typedef ConstNodes::const_iterator ConstChildIter;
00026   String                name            () const                { return name_; }
00027   XmlNode*              parent          () const                { return parent_; }
00028   const StringVector&   list_attributes () const                { return attribute_names_; }
00029   const StringVector&   list_values     () const                { return attribute_values_; }
00030   bool                  set_attribute   (const String   &name,
00031                                          const String   &value,
00032                                          bool            replace = true);
00033   String                get_attribute   (const String   &name,
00034                                          bool            case_insensitive = false) const;
00035   bool                  has_attribute   (const String   &name,
00036                                          bool            case_insensitive = false) const;
00037   bool                  del_attribute   (const String   &name);
00038   String                parsed_file     () const                { return file_; }
00039   uint                  parsed_line     () const                { return line_; }
00040   uint                  parsed_char     () const                { return char_; }
00041   /* text node */
00042   virtual String        text            () const = 0;
00043   bool                  istext          () const                { return name_.size() == 0; }
00044   /* parent node */
00045   virtual ConstNodes&   children        () const = 0;
00046   ConstChildIter        children_begin  () const { return children().begin(); }
00047   ConstChildIter        children_end    () const { return children().end(); }
00048   const XmlNode*        first_child     (const String   &element_name) const;
00049   virtual bool          add_child       (XmlNode        &child) = 0;
00050   virtual bool          del_child       (XmlNode        &child) = 0;
00051   void                  steal_children  (XmlNode        &parent);
00052   /* hints */
00053   void                  break_after     (bool            newline_after_tag);
00054   bool                  break_after     () const;
00055   void                  break_within    (bool            newlines_around_chidlren);
00056   bool                  break_within    () const;
00057   String                xml_string      (uint64          indent = 0, bool include_outer = true, uint64 recursion_depth = -1) const;
00058   /* nodes */
00059   static XmlNode*       create_text     (const String   &utf8text,
00060                                          uint            line,
00061                                          uint            _char,
00062                                          const String   &file);
00063   static XmlNode*       create_parent   (const String   &element_name,
00064                                          uint            line,
00065                                          uint            _char,
00066                                          const String   &file);
00067   /* IO */
00068   static XmlNode*       parse_xml       (const String   &input_name,
00069                                          const char     *utf8data,
00070                                          ssize_t         utf8data_len,
00071                                          MarkupParser::Error *error,
00072                                          const String   &roottag = "");
00073   static String         xml_escape      (const String   &input);
00074 };
00075 
00076 } // Rapicorn
00077 
00078 #endif  /* __RAPICORN_XMLNODE_HH__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines