/
annotation.hpp
160 lines (130 loc) · 5.03 KB
/
annotation.hpp
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
153
154
155
156
157
158
159
160
// Copyright (c) 2019 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(PHYLANX_PRIMITIVES_ANNOTATION_JUN_18_2019_1002AM)
#define PHYLANX_PRIMITIVES_ANNOTATION_JUN_18_2019_1002AM
#include <phylanx/config.hpp>
#include <phylanx/execution_tree/primitives/primitive_argument_type.hpp>
#include <phylanx/ir/ranges.hpp>
#include <hpx/runtime/serialization/serialization_fwd.hpp>
#include <cstdint>
#include <iosfwd>
#include <string>
namespace phylanx { namespace execution_tree
{
////////////////////////////////////////////////////////////////////////////
struct annotation;
PHYLANX_EXPORT primitive_argument_type as_primitive_argument_type(
annotation&& ann);
PHYLANX_EXPORT primitive_argument_type as_primitive_argument_type(
annotation const& ann);
////////////////////////////////////////////////////////////////////////////
struct annotation
{
public:
annotation() = default;
explicit annotation(ir::range const& rhs)
: data_(rhs)
{
}
explicit annotation(ir::range&& rhs)
: data_(std::move(rhs))
{
}
template <typename... Ts>
annotation(char const* key, Ts&& ... ts)
: data_(key, as_primitive_argument_type(std::forward<Ts>(ts))...)
{
}
template <typename... Ts>
annotation(std::string const& key, Ts&& ... ts)
: data_(key, as_primitive_argument_type(std::forward<Ts>(ts))...)
{
}
annotation& operator=(ir::range const& rhs)
{
data_ = rhs;
return *this;
}
annotation& operator=(ir::range&& rhs)
{
data_ = std::move(rhs);
return *this;
}
////////////////////////////////////////////////////////////////////////
PHYLANX_EXPORT std::string get_type(std::string const& name = "",
std::string const& codename = "<unknown>") const;
PHYLANX_EXPORT ir::range get_data() const;
ir::range& get_range()
{
return data_;
}
ir::range const& get_range() const
{
return data_;
}
ir::range get_range_ref() const
{
return data_.ref();
}
PHYLANX_EXPORT bool find(std::string const& key, annotation& ann,
std::string const& name = "",
std::string const& codename = "<unknown>") const;
PHYLANX_EXPORT bool has_key(std::string const& key,
std::string const& name = "",
std::string const& codename = "<unknown>") const;
PHYLANX_EXPORT void add_annotation(std::string const& key,
ir::range&& data, std::string const& name,
std::string const& codename);
PHYLANX_EXPORT void add_annotation(annotation&& data,
std::string const& name, std::string const& codename);
PHYLANX_EXPORT void replace_annotation(annotation&& data,
std::string const& name, std::string const& codename);
PHYLANX_EXPORT void replace_annotation(std::string const& key,
annotation&& data, std::string const& name,
std::string const& codename);
PHYLANX_EXPORT bool get_if(std::string const& key,
execution_tree::annotation& ann, std::string const& name = "",
std::string const& codename = "<unknown>") const;
friend bool operator==(annotation const& lhs, annotation const& rhs)
{
return lhs.data_ == rhs.data_;
}
friend bool operator!=(annotation const& lhs, annotation const& rhs)
{
return !(lhs == rhs);
}
private:
ir::range data_;
friend class hpx::serialization::access;
PHYLANX_EXPORT void serialize(hpx::serialization::output_archive& ar,
unsigned);
PHYLANX_EXPORT void serialize(hpx::serialization::input_archive& ar,
unsigned);
};
////////////////////////////////////////////////////////////////////////////
PHYLANX_EXPORT std::ostream& operator<<(
std::ostream& os, annotation const& ann);
////////////////////////////////////////////////////////////////////////////
struct annotation_information
{
annotation_information() = default;
PHYLANX_EXPORT annotation_information(
std::string name, std::int64_t generation);
PHYLANX_EXPORT annotation_information(
annotation const& ann, std::string const& name,
std::string const& codename);
PHYLANX_EXPORT std::string generate_name() const;
PHYLANX_EXPORT annotation as_annotation() const;
private:
void extract_from_name();
public:
std::string name_;
std::int64_t generation_ = 0;
};
PHYLANX_EXPORT annotation_information extract_annotation_information(
annotation const& ann, std::string const& name,
std::string const& codename);
}}
#endif