Reflection for RapidJSON
0.0.17
Reflection for serializing/deserializing with RapidJSON
Toggle main menu visibility
Loading...
Searching...
No Matches
codefactory.h
Go to the documentation of this file.
1
#ifndef REFLECTIVE_RAPIDJSON_CODE_FACTORY_H
2
#define REFLECTIVE_RAPIDJSON_CODE_FACTORY_H
3
4
#include "
./codegenerator.h
"
5
6
#include <functional>
7
#include <iosfwd>
8
#include <memory>
9
#include <string>
10
#include <vector>
11
12
namespace
clang
{
13
class
CompilerInstance;
14
}
// namespace clang
15
16
namespace
ReflectiveRapidJSON
{
17
18
class
Consumer
;
19
class
Visitor
;
20
27
class
CodeFactory
{
28
friend
class
Consumer
;
29
friend
class
Visitor
;
30
31
public
:
32
CodeFactory
(std::string_view applicationPath,
const
std::vector<const char *> &sourceFiles,
const
std::vector<std::string_view> &clangOptions,
33
std::ostream &os);
34
~CodeFactory
();
35
36
const
std::vector<std::unique_ptr<CodeGenerator>> &
generators
()
const
;
37
template
<
typename
GeneratorType,
typename
... Args>
void
addGenerator
(Args &&...args);
38
template
<
typename
GeneratorType,
typename
... Args>
auto
bindGenerator
(Args &&...args);
39
40
bool
run
();
41
clang::CompilerInstance *
compilerInstance
();
42
void
setCompilerInstance
(clang::CompilerInstance *
compilerInstance
);
43
bool
isErrorResilient
()
const
;
44
void
setErrorResilient
(
bool
errorResilient);
45
46
private
:
47
struct
ToolInvocation
;
48
49
void
addDeclaration(clang::Decl *decl);
50
bool
generate()
const
;
51
std::vector<std::string> makeClangArgs()
const
;
52
53
std::string_view m_applicationPath;
54
const
std::vector<const char *> &m_sourceFiles;
55
const
std::vector<std::string_view> &m_clangOptions;
56
std::ostream &m_os;
57
std::vector<std::unique_ptr<CodeGenerator>> m_generators;
58
std::unique_ptr<ToolInvocation> m_toolInvocation;
59
clang::CompilerInstance *m_compilerInstance;
60
bool
m_errorResilient;
61
};
62
67
template
<
typename
GeneratorType,
typename
... Args>
void
CodeFactory::addGenerator
(Args &&...args)
68
{
69
m_generators.emplace_back(std::make_unique<GeneratorType>(*
this
, std::forward<Args>(args)...));
70
}
71
72
namespace
Detail
{
76
template
<
typename
T> std::reference_wrapper<const T>
wrapReferences
(
const
T &val)
77
{
78
return
std::cref(val);
79
}
80
84
template
<
typename
T> std::reference_wrapper<T>
wrapReferences
(T &val)
85
{
86
return
std::ref(val);
87
}
88
92
template
<
typename
T> T &&
wrapReferences
(T &&val)
93
{
94
return
std::forward<T>(val);
95
}
96
}
// namespace Detail
97
104
template
<
typename
GeneratorType,
typename
... Args>
auto
CodeFactory::bindGenerator
(Args &&...args)
105
{
106
return
std::bind(&
CodeFactory::addGenerator<GeneratorType, Args...>
,
this
,
Detail::wrapReferences
(std::forward<Args>(args)...));
107
}
108
112
inline
const
std::vector<std::unique_ptr<CodeGenerator>> &
CodeFactory::generators
()
const
113
{
114
return
m_generators;
115
}
116
121
inline
clang::CompilerInstance *
CodeFactory::compilerInstance
()
122
{
123
return
m_compilerInstance;
124
}
125
130
inline
void
CodeFactory::setCompilerInstance
(clang::CompilerInstance *
compilerInstance
)
131
{
132
m_compilerInstance =
compilerInstance
;
133
}
134
138
inline
bool
CodeFactory::isErrorResilient
()
const
139
{
140
return
m_errorResilient;
141
}
142
146
inline
void
CodeFactory::setErrorResilient
(
bool
errorResilient)
147
{
148
m_errorResilient = errorResilient;
149
}
150
151
}
// namespace ReflectiveRapidJSON
152
153
#endif
// REFLECTIVE_RAPIDJSON_CODE_FACTORY_H
ReflectiveRapidJSON::CodeFactory::isErrorResilient
bool isErrorResilient() const
Returns whether most errors will be turned into warnings (by default false).
Definition
codefactory.h:138
ReflectiveRapidJSON::CodeFactory::generators
const std::vector< std::unique_ptr< CodeGenerator > > & generators() const
Returns the added generators.
Definition
codefactory.h:112
ReflectiveRapidJSON::CodeFactory::Consumer
friend class Consumer
Definition
codefactory.h:28
ReflectiveRapidJSON::CodeFactory::run
bool run()
Reads (relevant) AST elements using Clang and generates code.
Definition
codefactory.cpp:90
ReflectiveRapidJSON::CodeFactory::bindGenerator
auto bindGenerator(Args &&...args)
Returns a function which instantiates a code generator of the specified type and adds it to the curre...
Definition
codefactory.h:104
ReflectiveRapidJSON::CodeFactory::setCompilerInstance
void setCompilerInstance(clang::CompilerInstance *compilerInstance)
Assigns the compiler instance.
Definition
codefactory.h:130
ReflectiveRapidJSON::CodeFactory::addGenerator
void addGenerator(Args &&...args)
Instantiates a code generator of the specified type and adds it to the current instance.
Definition
codefactory.h:67
ReflectiveRapidJSON::CodeFactory::compilerInstance
clang::CompilerInstance * compilerInstance()
Returns the compiler instance.
Definition
codefactory.h:121
ReflectiveRapidJSON::CodeFactory::setErrorResilient
void setErrorResilient(bool errorResilient)
Sets whether most errors will be turned into warnings (by default false).
Definition
codefactory.h:146
ReflectiveRapidJSON::CodeFactory::CodeFactory
CodeFactory(std::string_view applicationPath, const std::vector< const char * > &sourceFiles, const std::vector< std::string_view > &clangOptions, std::ostream &os)
Constructs a new instance.
Definition
codefactory.cpp:35
ReflectiveRapidJSON::CodeFactory::Visitor
friend class Visitor
Definition
codefactory.h:29
ReflectiveRapidJSON::Consumer
The Consumer class is passed to FrontendAction for handling occurrences of different elements of the ...
Definition
consumer.h:24
ReflectiveRapidJSON::Visitor
The Visitor class is used to traverse the elements of a translation unit.
Definition
visitor.h:15
codegenerator.h
ReflectiveRapidJSON::Detail
Definition
codefactory.h:72
ReflectiveRapidJSON::Detail::wrapReferences
std::reference_wrapper< const T > wrapReferences(const T &val)
Wraps const references using std::cref() for use with std::bind().
Definition
codefactory.h:76
ReflectiveRapidJSON
Definition
codegenerator.h:15
clang
Definition
codegenerator.h:8
ReflectiveRapidJSON::CodeFactory::ToolInvocation
Definition
codefactory.cpp:17
Generated on
for Reflection for RapidJSON by
1.18.0