as2js: /home/snapwebsites/snapcpp/contrib/as2js/lib/db.h Source File

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

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly