aboutsummaryrefslogtreecommitdiff
path: root/vcal.h
blob: bb30e4828226f935d37008d7a44fef336a33fa0b (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
#ifndef VCAL_H
#define VCAL_H

#include <string>
#include <utility>
#include <vector>
#include <list>
#include <iostream>

#include "trie.h"


typedef std::pair<strbuf, std::list<strbuf> > param_set;
typedef std::pair<strbuf, std::list<param_set> > content_set;
typedef std::pair<strbuf, std::list<content_set> > content_line;

#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->value)
/* 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

	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)
			: type(type) , filename(filename) { };

	~vcomponent();


/*
 * 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[] (char* key) {
		return this->clines[key];
	}

	void push_back(const vcomponent& child)
		{ this->components.push_back(child); }
};

std::ostream& operator<<(std::ostream&, vcomponent*);

#endif /* VCAL_H */