summaryrefslogtreecommitdiff
path: root/test/core/model/TestDomain.hpp
blob: ec63216bd5bfbe143914086151fa7b6eeec4607a (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
/*
    Ousía
    Copyright (C) 2014, 2015  Benjamin Paaßen, Andreas Stöckel

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _MODEL_TEST_DOMAIN_HPP_
#define _MODEL_TEST_DOMAIN_HPP_

#include <core/model/Domain.hpp>
#include <core/model/Typesystem.hpp>

namespace ousia {
namespace model {

/**
 * This constructs the "book" domain for test purposes. The structure of the
 * domain is fairly simple and can be seen from the construction itself.
 */
static Rooted<Domain> constructBookDomain(Manager &mgr,
                                          Handle<SystemTypesystem> sys,
                                          Logger &logger)
{
	// Start with the Domain itself.
	Rooted<Domain> domain{new Domain(mgr, sys, "book")};
	// Set up the cardinalities we'll need.
	Variant::cardinalityType single;
	single.merge({1});
	Variant::cardinalityType any;
	any.merge(Range<size_t>::typeRange());

	// Set up the "book" node.
	Rooted<StructuredClass> book{new StructuredClass(
	    mgr, "book", domain, single, {nullptr}, {nullptr}, false, true)};

	// The structure field of it.
	Rooted<FieldDescriptor> book_field{new FieldDescriptor(mgr, book)};

	// From there on the "section".
	Rooted<StructuredClass> section{
	    new StructuredClass(mgr, "section", domain, any)};
	book_field->addChild(section);

	// And the field of it.
	Rooted<FieldDescriptor> section_field{new FieldDescriptor(mgr, section)};

	// We also add the "paragraph", which is transparent.
	Rooted<StructuredClass> paragraph{new StructuredClass(
	    mgr, "paragraph", domain, any, {nullptr}, {nullptr}, true)};
	section_field->addChild(paragraph);
	book_field->addChild(paragraph);

	// And the field of it.
	Rooted<FieldDescriptor> paragraph_field{
	    new FieldDescriptor(mgr, paragraph)};

	// We append "subsection" to section.
	Rooted<StructuredClass> subsection{
	    new StructuredClass(mgr, "subsection", domain, any)};
	section_field->addChild(subsection);

	// And the field of it.
	Rooted<FieldDescriptor> subsection_field{
	    new FieldDescriptor(mgr, subsection)};

	// and we add the paragraph to subsections fields
	subsection_field->addChild(paragraph);

	// Finally we add the "text" node, which is transparent as well.
	Rooted<StructuredClass> text{new StructuredClass(
	    mgr, "text", domain, any, {nullptr}, {nullptr}, true)};
	paragraph_field->addChild(text);

	// ... and has a primitive field.
	Rooted<FieldDescriptor> text_field{new FieldDescriptor(
	    mgr, text, domain->getTypesystems()[0]->getTypes()[0], "content",
	    false)};

	return domain;
}
}
}

#endif /* _TEST_DOMAIN_HPP_ */