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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
* base_actions.h
*
*
* Created by Andreas Vox on 02.06.06.
* Copyright 2006 under GPL2. All rights reserved.
*
*/
#ifndef BASE_ACTIONS_H
#define BASE_ACTIONS_H
/*****
Defines the following actions:
Attribute<D>( name, def) - -> D
Attribute<D>( name ) - -> D
*RefAttribute<D>( name ) - -> D
*Get<O,D>( gen<O>, fun ) - -> D
*Set<O,D>( gen<O>, fun, gen<D> ) - -> -
*Top<D>( n ) - -> D
*Bottom<D>( n ) - -> D
*WithText<O,D>( gen<O>, fun ) - -> -
*Invoke<O, F, A1, ...>(fun, a1, ...) O -> O
*InvokeLater<O, F, A1, ...>(fun, a1, ...) O -> O
*Call<F,A1, ..., An>(fun, a1, ..., an) - -> -
*CallLater<F,A1, ..., An>(fun, a1, ..., an) - -> -
*Filter<D,E> ( gen<D>, fun ) - -> E
*Combine<D,E,F> ( gen<D>, gen<D>, fun) - -> F
*****/
/**
* Converts an attribute to an object of type Data_Type and pushes it onto the stack.
*/
template<class Data_Type>
class Attribute_body : public Generator_body<Data_Type>
{
public:
Attribute_body(const Xml_string& name)
: name_(name), default_(NULL)
{}
Attribute_body(const Xml_string& name, const Data_Type& def)
: name_(name), default_(new Data_Type(def))
{}
~Attribute_body()
{
if (default_)
delete default_;
}
void begin(const Xml_string&, Xml_attr)
{
if (attr.contains(name_))
dig->push(new Data_Type(attr[name_]));
else if (default_)
dig->push(new Data_Type(default_));
else
dig->push(NULL);
}
private:
const Xml_string name_;
const Data_Type* default_;
};
template <class Type>
struct Attribute : public MakeGenerator<Attribute_body<Type>, const Xml_string&, const Type&>
{
Attribute(const Xml_string& name)
: MakeGenerator<Attribute_body<Type>, const Xml_string&>::MakeGenerator(name) {}
Attribute(const Xml_string& name, const Type& def)
: MakeGenerator<Attribute_body<Type>, const Xml_string&, const Type&>::MakeGenerator(name, def) {}
};
/*
template<class Functor>
class Call0 : public Action
{
public:
Call0(Functor f) : fun(f)
{}
void begin(const std::string, std::map<std::string,std::string> attr)
{
fun();
}
private:
Functor fun;
};
template<class Functor, class Arg1>
class Call1 : public Action
{
public:
Call1(Functor f, Generator<Arg1> a1) : fun(f), arg1(a1)
{}
void begin(const std::string, std::map<std::string,std::string> attr)
{
fun(arg1->eval(digester(), tag, attr));
}
private:
Functor fun;
Generator<Arg1> arg1;
};
template<class Functor, class Arg1, class Arg2>
class Call2 : public Action
{
public:
Call2(Functor f, Generator<Arg1>* a1, Generator<Arg2>* a2) : fun(f), arg1(a1), arg2(a2)
{}
void begin(const std::string, std::map<std::string,std::string> attr)
{
fun(arg1->eval(digester(), tag, attr),
arg2->eval(digester(), tag, attr));
}
private:
Functor fun;
Generator<Arg1> arg1;
Generator<Arg2> arg2;
};
/* Baustelle
template<class Obj_Type, class Data_Type>
class Invoke : public Action
{
public:
Invoke(void (Obj_Type::*inv)(Data_Type&)) : set_(set) {}
void end(const std::string);
private:
void (Obj_Type::*set_)(Data_Type&);
};
*/
#endif
|