Lumiera
0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
text-template-gen-node-binding.hpp
Go to the documentation of this file.
1
/*
2
TEXT-TEMPLATE-GEN-NODE-BINDING.hpp - data binding adapter for ETD
3
4
Copyright (C)
5
2024, Hermann Vosseler <Ichthyostega@web.de>
6
7
**Lumiera** is free software; you can redistribute it and/or modify it
8
under the terms of the GNU General Public License as published by the
9
Free Software Foundation; either version 2 of the License, or (at your
10
option) any later version. See the file COPYING for further details.
11
12
*/
13
14
47
#ifndef LIB_TEXT_TEMPLATE_GEN_NODE_BINDING_H
48
#define LIB_TEXT_TEMPLATE_GEN_NODE_BINDING_H
49
50
51
#include "
lib/diff/gen-node.hpp
"
52
#include "
lib/text-template.hpp
"
53
54
#include <string>
55
56
57
namespace
lib
{
58
59
using
std::string;
60
61
62
namespace
text_template {
63
64
/* ======= Data binding for GenNode (ETD) ======= */
65
72
template
<>
73
struct
DataSource<diff::GenNode>
74
{
75
using
Node
=
diff::GenNode
;
76
using
Rec
=
diff::Rec
;
77
78
Node
const
*
data_
;
79
DataSource*
parScope_
;
80
bool
isSubScope
() {
return
bool(parScope_); }
81
82
DataSource
(
Node
const
& root)
83
: data_{&root}
84
, parScope_{nullptr}
85
{ }
86
87
88
using
Value
= std::string;
89
using
Iter
=
Rec::scopeIter
;
90
91
Node
const
*
92
findNode
(
string
key)
93
{
94
if
(data_->
isNested
())
95
{
// standard case: Attribute lookup
96
Rec
const
& record = data_->
data
.
get
<
Rec
>();
97
if
(record.
hasAttribute
(key))
98
return
& record.
get
(key);
99
}
100
else
101
if
(
"value"
== key)
// special treatment for a »pseudo context«
102
return
data_;
// comprised only of a single value node
103
// ask parent scope...
104
if
(isSubScope())
105
return
parScope_->findNode (key);
106
107
return
nullptr
;
108
}
109
110
bool
111
contains
(
string
key)
112
{
113
return
bool(findNode (key));
114
}
115
116
Value
117
retrieveContent
(
string
key)
118
{
119
return
renderCompact (*findNode(key));
120
}
121
122
Iter
123
getSequence
(
string
key)
124
{
125
if
(not contains(key))
126
return
Iter
{};
127
Node
const
* node = findNode (key);
128
if
(not node->isNested())
129
return
Iter
{};
130
else
131
return
node->data.get<
Rec
>().scope();
132
}
133
134
DataSource
135
openContext
(
Iter
&
iter
)
136
{
137
REQUIRE (
iter
);
138
DataSource nested{*
this
};
139
nested.parScope_ =
this
;
140
nested.data_ = & *
iter
;
141
return
nested;
142
}
143
};
144
145
}
// namespace text_template
146
147
}
// namespace lib
148
#endif
/*LIB_TEXT_TEMPLATE_GEN_NODE_BINDING_H*/
lib::diff::DataCap::get
X & get()
Definition
gen-node.hpp:694
lib::diff::Record
object-like record of data.
Definition
record.hpp:142
lib::diff::Record::get
Access get(string key) const
Definition
record.hpp:245
lib::diff::Record::hasAttribute
bool hasAttribute(string key) const
Definition
record.hpp:233
lib::diff::Record::scopeIter
iter_stl::_SeqT< const Storage >::Range scopeIter
Definition
record.hpp:310
gen-node.hpp
Generic building block for tree shaped (meta)data structures.
lib::iter_stl
Definition
iter-adapter-stl.hpp:42
lib
Implementation namespace for support and library code.
Definition
common-services.cpp:55
lib::diff::GenNode
generic data element node within a tree
Definition
gen-node.hpp:224
lib::diff::GenNode::data
DataCap data
Definition
gen-node.hpp:258
lib::diff::GenNode::isNested
bool isNested() const
Definition
gen-node.hpp:813
lib::text_template::DataSource< diff::GenNode >::Iter
Rec::scopeIter Iter
Definition
text-template-gen-node-binding.hpp:89
lib::text_template::DataSource< diff::GenNode >::getSequence
Iter getSequence(string key)
Definition
text-template-gen-node-binding.hpp:123
lib::text_template::DataSource< diff::GenNode >::openContext
DataSource openContext(Iter &iter)
Definition
text-template-gen-node-binding.hpp:135
lib::text_template::DataSource< diff::GenNode >::data_
Node const * data_
Definition
text-template-gen-node-binding.hpp:78
lib::text_template::DataSource< diff::GenNode >::retrieveContent
Value retrieveContent(string key)
Definition
text-template-gen-node-binding.hpp:117
lib::text_template::DataSource< diff::GenNode >::findNode
Node const * findNode(string key)
Definition
text-template-gen-node-binding.hpp:92
lib::text_template::DataSource< diff::GenNode >::parScope_
DataSource * parScope_
Definition
text-template-gen-node-binding.hpp:79
lib::text_template::DataSource< diff::GenNode >::isSubScope
bool isSubScope()
Definition
text-template-gen-node-binding.hpp:80
lib::text_template::DataSource< diff::GenNode >::contains
bool contains(string key)
Definition
text-template-gen-node-binding.hpp:111
lib::text_template::DataSource< diff::GenNode >::Value
std::string Value
Definition
text-template-gen-node-binding.hpp:88
lib::text_template::DataSource< diff::GenNode >::DataSource
DataSource(Node const &root)
Definition
text-template-gen-node-binding.hpp:82
text-template.hpp
A minimalistic text templating engine with flexible data binding.
lib
text-template-gen-node-binding.hpp
Generated on Thu Dec 11 2025 for Lumiera by
1.9.8