LCOV - code coverage report
Current view: top level - home/snapwebsites/snapcpp/snapwebsites/snapdatabase/snapdatabase/data - xml.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2019-12-15 17:13:15 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2019  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/snapdatabase
       4             : // contact@m2osw.com
       5             : //
       6             : // This program is free software; you can redistribute it and/or modify
       7             : // it under the terms of the GNU General Public License as published by
       8             : // the Free Software Foundation; either version 2 of the License, or
       9             : // (at your option) any later version.
      10             : //
      11             : // This program is distributed in the hope that it will be useful,
      12             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : // GNU General Public License for more details.
      15             : //
      16             : // You should have received a copy of the GNU General Public License along
      17             : // with this program; if not, write to the Free Software Foundation, Inc.,
      18             : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             : #pragma once
      20             : 
      21             : 
      22             : /** \file
      23             :  * \brief Very simple XML parser.
      24             :  *
      25             :  * The definitions of the Snap! Database tables is done in XML files.
      26             :  * These classes are used to load and parse those files to use them
      27             :  * as the schema definition of the tables.
      28             :  */
      29             : 
      30             : // C++ lib
      31             : //
      32             : #include    <deque>
      33             : #include    <map>
      34             : #include    <memory>
      35             : #include    <ostream>
      36             : #include    <vector>
      37             : 
      38             : 
      39             : 
      40             : namespace snapdatabase
      41             : {
      42             : 
      43             : 
      44             : 
      45          33 : class xml_node
      46             :     : public std::enable_shared_from_this<xml_node>
      47             : {
      48             : public:
      49             :     typedef std::shared_ptr<xml_node>
      50             :                                     pointer_t;
      51             :     typedef std::map<std::string, pointer_t>
      52             :                                     map_t;
      53             :     typedef std::weak_ptr<xml_node> weak_pointer_t;
      54             :     typedef std::map<std::string, std::string>  
      55             :                                     attribute_map_t;
      56             :     typedef std::vector<pointer_t>  vector_t;
      57             :     typedef std::deque<pointer_t>   deque_t;
      58             : 
      59             :                                     xml_node(std::string const & name);
      60             : 
      61             :     std::string const &             tag_name() const;
      62             :     std::string                     text() const;
      63             :     void                            append_text(std::string const & text);
      64             :     attribute_map_t                 all_attributes() const;
      65             :     std::string                     attribute(std::string const & name) const;
      66             :     void                            set_attribute(std::string const & name, std::string const & value);
      67             :     void                            append_child(pointer_t n);
      68             : 
      69             :     pointer_t                       parent() const;
      70             :     pointer_t                       first_child() const;
      71             :     pointer_t                       last_child() const;
      72             :     pointer_t                       next() const;
      73             :     pointer_t                       previous() const;
      74             : 
      75             : private:
      76             :     std::string const               f_name;
      77             :     std::string                     f_text = std::string();
      78             :     attribute_map_t                 f_attributes = attribute_map_t();
      79             : 
      80             :     pointer_t                       f_next = pointer_t();
      81             :     weak_pointer_t                  f_previous = weak_pointer_t();
      82             : 
      83             :     pointer_t                       f_child = pointer_t();
      84             :     weak_pointer_t                  f_parent = weak_pointer_t();
      85             : };
      86             : 
      87             : std::ostream & operator << (std::ostream & out, xml_node const & n);
      88             : 
      89             : 
      90             : 
      91             : 
      92           7 : class xml
      93             : {
      94             : public:
      95             :     typedef std::shared_ptr<xml>    pointer_t;
      96             : 
      97             :                                     xml(std::string const & filename);
      98             : 
      99             :     xml_node::pointer_t             root();
     100             : 
     101             : private:
     102             :     xml_node::pointer_t             f_root = xml_node::pointer_t();
     103             : };
     104             : 
     105             : 
     106             : 
     107             : } // namespace snapdatabase
     108             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13