blob: fb767820c591867e606aa16e1b002299ee567d67 (
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
|
#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;
llist<strbuf> values;
__param_set (strbuf key) : key (key) { }
};
/*
* 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;
llist<__param_set> params;
};
/*
* A content line is the collection of all lines which share the same
* key.
*/
struct content_line {
strbuf key;
llist<__content_set> values;
inline void push_param_key (strbuf key) {
auto p = new __param_set(key);
this->values.cur()->params.push(p);
}
inline void push_param_value (strbuf* value) { this->values.cur()->params.cur()->values.push(value); }
inline strbuf* value() { return &this->values.cur()->value; }
};
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);
/*
* 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 1
/*
* 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 */
|