-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDbTree.hh
78 lines (70 loc) · 1.67 KB
/
DbTree.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef _DB_TREE_HH_
#define _DB_TREE_HH_
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include "DbVal.hh"
namespace Yang
{
namespace Ast
{
class InteriorNode;
}
}
struct CStrLess {
bool operator() (const char* l, const char* r) const {
return strcmp(l, r) < 0;
}
};
class Type;
typedef std::map<const char*, Type*, CStrLess> Types;
struct DbValLess {
bool operator() (const DbVal* l, const DbVal* r) const {
return *l < *r;
}
};
class Key;
typedef std::map<const DbVal*, Key*, DbValLess> Keys;
class Key
{
public:
Key();
Key(const DbVal* key, const Type* parent);
void add(Type* ty);
const DbVal* getKey() const;
Type* findOrCreate(const std::string& s,
Yang::Ast::InteriorNode* schemaRef);
Type* find(const std::string& s);
std::vector<Vals>& getLeafs();
void replace(const std::vector<Vals>& leafs);
void print() const;
Yang::Ast::InteriorNode& getSchemaObj();
protected:
const DbVal* _key;
std::vector<Vals> _leafs;
Types _types;
const Type* _parent;
};
class Type
{
public:
Type(const std::string& t,
const Key* parent,
Yang::Ast::InteriorNode* schemaRef);
void add(Key* key);
Key* findOrCreate(const DbVal* k, const Type* parent);
Key* find(const DbVal* k);
const char* getType() const;
Keys& getKeys();
void print() const;
Yang::Ast::InteriorNode& getSchemaObj() {
return *_schemaRef;
}
protected:
std::string _type;
Yang::Ast::InteriorNode* _schemaRef;
Keys _keys;
const Key* _parent;
};
#endif