repr
0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
repr
Go to the documentation of this file.
1
#pragma once
2
#include <
string
>
3
4
#include <
librepr/customization.h
>
5
#include <
librepr/type_info.h
>
6
#include <
librepr/visit.h
>
7
#include <
librepr/visitors/repr.h
>
8
#include <
librepr/visitors/cpp.h
>
9
#include <
librepr/visitors/python.h
>
10
#include <
librepr/visitors/layout.h
>
11
12
namespace
librepr
{
15
struct
ReprWrapper
{
22
template
<
typename
T>
23
std::string
operator()
(T
const
&
obj
,
Options
options = {})
const
{
24
// TODO this could be static once msvc supports it
25
auto
visitor
=
ReprVisitor
{options};
26
librepr::visit
(
visitor
,
obj
);
27
return
visitor
.result.extract();
28
}
29
};
30
31
enum class
Language
{
CPP
,
Python
};
32
38
template
<
typename
T, Language language = Language::CPP>
39
std::string
code_for
() {
40
if
constexpr
(language ==
Language::Python
) {
41
auto
visitor
=
librepr::PythonVisitor
{};
42
librepr::visit<T>
(
visitor
);
43
return
visitor
.result.extract();
44
}
45
auto
visitor
=
librepr::CppVisitor
{};
46
librepr::visit<T>
(
visitor
);
47
return
visitor
.result.extract();
48
}
49
50
template
<
typename
T>
51
std::string
layout_of
() {
52
auto
visitor
=
librepr::LayoutVisitor
();
53
librepr::visit<T>
(
visitor
);
54
return
visitor
.result.extract();
55
}
56
}
// namespace librepr
57
58
inline
constexpr ::librepr::ReprWrapper
59
repr
{};
61
template
<
typename
T>
62
inline
constexpr ::librepr::TypeName<T>
nameof
{};
std::string
librepr::ReprVisitor
Definition
repr.h:20
cpp.h
customization.h
layout.h
librepr
Definition
ctvi/ctvi.h:9
librepr::code_for
std::string code_for()
Definition
repr:39
librepr::layout_of
std::string layout_of()
Definition
repr:51
librepr::Language
Language
Definition
repr:31
librepr::Language::CPP
@ CPP
librepr::Language::Python
@ Python
librepr::visit
void visit(V &&visitor)
Definition
visit.h:9
python.h
repr.h
repr
constexpr ::librepr::ReprWrapper repr
Definition
repr:59
nameof
constexpr ::librepr::TypeName< T > nameof
Definition
repr:62
string
librepr::CppVisitor
Definition
cpp.h:17
librepr::LayoutVisitor
Definition
layout.h:9
librepr::Options
Definition
options.h:7
librepr::PythonVisitor
Definition
python.h:26
librepr::ReprWrapper
Definition
repr:15
librepr::ReprWrapper::operator()
std::string operator()(T const &obj, Options options={}) const
Definition
repr:23
type_info.h
visit.h
include
repr
Generated by
1.9.8, using the excellent
Doxygen Awesome
Theme