-
Notifications
You must be signed in to change notification settings - Fork 10
/
Trigger.h
102 lines (84 loc) · 2.38 KB
/
Trigger.h
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
/*
Created by Paul Marinescu and George Candea
Copyright (C) 2009 EPFL (Ecole Polytechnique Federale de Lausanne)
This file is part of LFI (Library-level Fault Injector).
LFI 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.
LFI 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 LFI. If not, see http://www.gnu.org/licenses/.
EPFL
Dependable Systems Lab (DSLAB)
Room 330, Station 14
1015 Lausanne
Switzerland
*/
#include <libxml/tree.h>
#include <vector>
#include <string>
#include <map>
#include <memory>
using namespace std;
class Trigger
{
public:
virtual void Init(xmlNodePtr initData) {}
virtual bool Eval(const string* functionName, ...) = 0;
};
typedef Trigger* (*FactoryMethod)() ;
class RegEntry ;
class Class
{
public :
static Class forName( std::string s )
{
return( Class( s ) ) ;
}
Trigger* newInstance() ;
static Trigger* newI(std::string s)
{
return (Class(s).newInstance());
}
private :
std::string name ;
typedef std::map< std::string, FactoryMethod > FactoryMethodMap ;
static FactoryMethodMap* fmMap ;
friend class RegEntry ;
static void Register( std::string s, FactoryMethod m ) ;
Class( std::string s ) : name( s )
{
}
};
class RegEntry
{
public :
RegEntry( const char s[], FactoryMethod f )
{
Class::Register( s, f ) ;
}
};
template< class T, const char S[] > class Registered
{
public :
static Trigger* newInstance()
{
return( new T() ) ;
}
protected :
Registered()
{
const RegEntry& dummy = r ;
}
private :
static const RegEntry r ;
} ;
template< class T, const char S[] > const RegEntry
Registered< T, S > :: r = RegEntry( S, Registered< T, S >::newInstance ) ;
#define DEFINE_TRIGGER( C ) \
char C##Name__[] = #C ; \
class C : public Registered< C, C##Name__ >, public Trigger