Debian Codegraph @

tools/repository.hpp

raw symbols SCIP
1 #ifndef REPOSITORY_HPP
2 #define REPOSITORY_HPP
3
4 #include "common.hpp"
5
6 #include <map>
7 #include <memory>
8 #include <string>
9
10 #include <boost/property_tree/ptree.hpp>
11 namespace pt = boost::property_tree;
12
13 // ptree helpers
14 template<typename T = std::string, typename... Args>
15 static T
16 get_attribute(const pt::ptree &node, const std::string &attr, Args... args)
17 {
18 static auto prefix = PT_ATTR + '.';
19 return node.get<T>(prefix + attr, args...);
20 }
21
22 inline std::string
23 get_name(const pt::ptree &node)
24 {
25 return get_attribute(node, AT_NAME);
26 }
27
28 inline std::string
29 get_name(const pt::ptree &node, std::nothrow_t)
30 {
31 return get_attribute(node, AT_NAME, "");
32 }
33
34 enum TYPE_TRAITS {
35 // basic/fundamental glib defined type
36 TYPE_BASIC = 1 << 0,
37 // type passed by value (integral, enum, etc)
38 TYPE_VALUE = 1 << 1,
39 // enum, bitfield type
40 TYPE_ENUM = 1 << 2,
41 // class type (string, object, record)
42 TYPE_CLASS = 1 << 3,
43 // gobject
44 TYPE_OBJECT = 1 << 4,
45 // boxed
46 TYPE_BOXED = 1 << 5,
47 // callback
48 TYPE_CALLBACK = 1 << 6,
49 // containers
50 TYPE_ARRAY = 1 << 7,
51 TYPE_LIST = 1 << 8,
52 TYPE_MAP = 1 << 9,
53 TYPE_CONTAINER = TYPE_ARRAY | TYPE_LIST | TYPE_MAP,
54 TYPE_VARARGS = 1 << 10,
55 // predefined
56 TYPE_PREDEFINED = 1 << 11,
57 // typedef (no forward class declare)
58 TYPE_TYPEDEF = 1 << 12
59 };
60
61 // some info on (argument) type
62 struct TypeInfo
63 {
64 TypeInfo() = default;
65 TypeInfo(const std::string &_gir, const std::string &_cpp,
66 const std::string &_c, const std::string &_argtype, int _flags)
67 : girname(_gir), cpptype(_cpp), dtype(_c), argtype(_argtype),
68 flags(_flags), pdepth(flags & (TYPE_CLASS | TYPE_CONTAINER) ? 1 : 0)
69 {}
70 // always qualified (if not predefined glib type)
71 std::string girname;
72 // always qualified (see below) as it might be used in class context
73 // (so to avoid lookup conflicts with parent classes in other ns,
74 // e.g. injected-class-name)
75 std::string cpptype;
76 // c:type taken from class/record definition
77 std::string dtype;
78 // c type as used in argument (no cv qualification)
79 std::string argtype;
80 // combination of flags above
81 int flags = 0;
82 // number of pointer indirections
83 int pdepth = 0;
84 };
85
86 class Repository
87 {
88 Repository() = default;
89 friend class RepositoryPriv;
90
91 Repository(const Repository &other) = delete;
92 Repository &operator=(const Repository &other) = delete;
93
94 public:
95 typedef std::map<std::string, std::string> subst_c_types;
96 typedef std::string key_type;
97 struct mapped_type
98 {
99 typedef pt::ptree::value_type tree_type;
100 std::unique_ptr<tree_type> tree;
101 std::unique_ptr<TypeInfo> info;
102 };
103
104 static std::shared_ptr<Repository> new_(subst_c_types m);
105
106 // set namespace used for unqualified girname
107 void set_ns(const std::string _ns);
108
109 // qualify girname, optionally wrt relative base
110 std::string qualify(
111 const std::string &girname, const std::string &base = "") const;
112
113 void add(const key_type &girname, const mapped_type::tree_type &n);
114
115 void discard(const key_type &girname);
116
117 const mapped_type::tree_type &tree(const std::string &girname) const;
118
119 const mapped_type *lookup(const std::string &girname) const;
120
121 // check for duplicate definition for ctype
122 // if ctype already claimed, returns non-empty claiming cpptype
123 std::string check_odr(const std::string &cpptype, const std::string &ctype);
124 };
125
126 #endif // REPOSITORY_HPP