LCOV - code coverage report
Current view: top level - lib - db.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 3 100.0 %
Date: 2014-11-22 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #ifndef AS2JS_DB_H
       2             : #define AS2JS_DB_H
       3             : /* db.h -- written by Alexis WILKE for Made to Order Software Corp. (c) 2005-2014 */
       4             : 
       5             : /*
       6             : 
       7             : Copyright (c) 2005-2014 Made to Order Software Corp.
       8             : 
       9             : http://snapwebsites.org/project/as2js
      10             : 
      11             : Permission is hereby granted, free of charge, to any
      12             : person obtaining a copy of this software and
      13             : associated documentation files (the "Software"), to
      14             : deal in the Software without restriction, including
      15             : without limitation the rights to use, copy, modify,
      16             : merge, publish, distribute, sublicense, and/or sell
      17             : copies of the Software, and to permit persons to whom
      18             : the Software is furnished to do so, subject to the
      19             : following conditions:
      20             : 
      21             : The above copyright notice and this permission notice
      22             : shall be included in all copies or substantial
      23             : portions of the Software.
      24             : 
      25             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
      26             : ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
      27             : LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
      28             : FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
      29             : EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
      30             : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
      31             : WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      32             : ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      33             : SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      34             : SOFTWARE.
      35             : 
      36             : */
      37             : 
      38             : #include    "as2js/json.h"
      39             : 
      40             : 
      41             : namespace as2js
      42             : {
      43             : 
      44             : // The database uses a JSON object defined as:
      45             : //
      46             : // {
      47             : //   "<package_name>": {
      48             : //     "<element name>": {
      49             : //       "type": <type>,
      50             : //       "filename": <filename>,
      51             : //       "line": <line>
      52             : //     },
      53             : //     // ... repeat for each element ...
      54             : //   },
      55             : //   // ... repeat for each package ...
      56             : // };
      57             : //
      58             : // The old database was one line per element as in:
      59             : // <package name> <element name> <type> <filename> <line>
      60             : 
      61             : 
      62          13 : class Database
      63             : {
      64             : public:
      65             :     typedef std::shared_ptr<Database>   pointer_t;
      66             : 
      67        3113 :     class Element
      68             :     {
      69             :     public:
      70             :         typedef std::shared_ptr<Element>      pointer_t;
      71             : 
      72             :                                     Element(String const& element_name, JSON::JSONValue::pointer_t element);
      73             : 
      74             :         void                        set_type(String const& type);
      75             :         void                        set_filename(String const& filename);
      76             :         void                        set_line(Position::counter_t line);
      77             : 
      78             :         String                      get_element_name() const;
      79             :         String                      get_type() const;
      80             :         String                      get_filename() const;
      81             :         Position::counter_t         get_line() const;
      82             : 
      83             :     private:
      84             :         String const                f_element_name;
      85             :         String                      f_type;
      86             :         String                      f_filename;
      87             :         Position::zcounter_t        f_line;
      88             : 
      89             :         JSON::JSONValue::pointer_t  f_element;
      90             :     };
      91             :     typedef std::map<String, Element::pointer_t>    element_map_t;
      92             :     typedef std::vector<Element::pointer_t>         element_vector_t;
      93             : 
      94         106 :     class Package
      95             :     {
      96             :     public:
      97             :         typedef std::shared_ptr<Package>        pointer_t;
      98             : 
      99             :                                     Package(String const& package_name, JSON::JSONValue::pointer_t package);
     100             : 
     101             :         String                      get_package_name() const;
     102             : 
     103             :         element_vector_t            find_elements(String const& pattern) const;
     104             :         Element::pointer_t          get_element(String const& element_name) const;
     105             :         Element::pointer_t          add_element(String const& element_name);
     106             : 
     107             :     private:
     108             :         String const                f_package_name;
     109             : 
     110             :         JSON::JSONValue::pointer_t  f_package;
     111             :         element_map_t               f_elements;
     112             :     };
     113             :     typedef std::map<String, Package::pointer_t>    package_map_t;
     114             :     typedef std::vector<Package::pointer_t>         package_vector_t;
     115             : 
     116             :     bool                        load(String const& filename);
     117             :     void                        save() const;
     118             : 
     119             :     package_vector_t            find_packages(String const& pattern) const;
     120             :     Package::pointer_t          get_package(String const& package_name) const;
     121             :     Package::pointer_t          add_package(String const& package_name);
     122             : 
     123             :     static bool                 match_pattern(String const& name, String const& pattern);
     124             : 
     125             : private:
     126             :     String                      f_filename;
     127             :     JSON::pointer_t             f_json;
     128             :     JSON::JSONValue::pointer_t  f_value; // json
     129             : 
     130             :     package_map_t               f_packages;
     131             : };
     132             : 
     133             : 
     134             : 
     135             : }
     136             : // namespace as2js
     137             : #endif
     138             : // #ifndef AS2JS_DB_H
     139             : 
     140             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.10