blob: 21f66063561f47dd24eec9fbad9ce49ecdf960bb (
plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#ifndef VCAL_H
#define VCAL_H
#include <string>
#include <utility>
#include <vector>
#include <list>
#include <iostream>
#include "trie.h"
#include "strbuf.h"
#include "linked_list.h"
struct __param_set {
strbuf key;
std::list<strbuf> values;
__param_set (strbuf key) : key (key) { this->key.cap(); }
void push_value (strbuf val) {
this->values.push_back(val);
this->values.back().cap();
}
};
/*
* A content set is a single instance of a content line, having a
* specific value and it's own (possible) set of parameters.
*/
struct __content_set {
strbuf value;
std::list<__param_set*> params;
__content_set (strbuf value) : value(value) { this->value.cap(); }
void push_param_key (strbuf key) {
this->params.push_back (new __param_set(key));
}
void push_param_value (strbuf val) {
this->params.back()->push_value(val);
}
};
/*
* A content line is the collection of all lines which share the same
* key.
*/
struct content_line {
strbuf key;
// llist<__content_set> values;
std::list<__content_set*> values;
void push_value (strbuf str) {
this->values.push_back(new __content_set(str));
}
};
struct vcomponent {
std::string filename;
std::string type;
vcomponent* parent = nullptr;
trie<content_line> clines;
std::vector<vcomponent> components;
vcomponent(const std::string& type) : vcomponent(type, nullptr) { };
vcomponent(const std::string& type, const std::string& filename);
void add_content_line (content_line* c) {
clines.push(c->key.c_str(), c);
}
/*
* Resolves a collision in some form of structure (probably a hash-map
* or a trie). If dest is NULL just return new_. Otherwise mutates dest
* to have the correct form, and returns it. Destroying new_ in the
* process.
*/
vcomponent* operator= (vcomponent* other);
content_line* operator[] (const char* key)
{ return this->clines[key]; }
void push_back(const vcomponent& child)
{ this->components.push_back(child); }
};
std::ostream& operator<<(std::ostream&, vcomponent*);
#if 0
/*
* Helper macros for accessing fields in
* content_line, content_set, and param_set
*
* TODO find a better way to do self.
*/
/* ptr -> ptr */
#define CLINE_KEY(c) (&(c)->first)
#define CLINE_CUR_CSET(c) (&((c)->second.cur->value))
/* content_set */
#define CLINE_CUR(c) ((c)->second.cur())
/* strbuf */
#define CLINE_CUR_VAL(c) (& CLINE_CUR(c)->first)
/* LLIST(param_set) */
#define CLINE_CUR_PARAMS(c) (& CLINE_CUR(c)->second)
/* strbuf */
#define CLINE_CUR_PARAM_KEY(c) (CLINE_CUR_PARAMS(c)->cur->value->first)
/* strbuf */
#define CLINE_CUR_PARAM_VAL(c) (CLINE_CUR_PARAMS(c)->cur->value->second.cur->value)
#endif
#endif /* VCAL_H */
|