Skip to content

Commit 01fc4e7

Browse files
Outsourced to src files
1 parent 4541411 commit 01fc4e7

5 files changed

Lines changed: 282 additions & 115 deletions

File tree

include/rfl/cereal/Reader.hpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ struct Reader {
4949
static constexpr bool has_custom_constructor =
5050
(requires(InputVarType var) { T::from_cereal_obj(var); });
5151

52-
bool is_empty(const InputVarType& _var) const noexcept {
53-
return _var.archive_ == nullptr;
54-
}
52+
bool is_empty(const InputVarType& _var) const noexcept;
5553

5654
template <class T>
5755
rfl::Result<T> to_basic_type(const InputVarType& _var) const noexcept {
@@ -82,23 +80,15 @@ struct Reader {
8280
}
8381

8482
rfl::Result<InputArrayType> to_array(
85-
const InputVarType& _var) const noexcept {
86-
return InputArrayType{_var.archive_};
87-
}
83+
const InputVarType& _var) const noexcept;
8884

8985
rfl::Result<InputObjectType> to_object(
90-
const InputVarType& _var) const noexcept {
91-
return InputObjectType{_var.archive_};
92-
}
86+
const InputVarType& _var) const noexcept;
9387

94-
rfl::Result<InputMapType> to_map(const InputVarType& _var) const noexcept {
95-
return InputMapType{_var.archive_};
96-
}
88+
rfl::Result<InputMapType> to_map(const InputVarType& _var) const noexcept;
9789

9890
rfl::Result<InputUnionType> to_union(
99-
const InputVarType& _var) const noexcept {
100-
return InputUnionType{_var.archive_};
101-
}
91+
const InputVarType& _var) const noexcept;
10292

10393
template <class ArrayReader>
10494
std::optional<Error> read_array(const ArrayReader& _array_reader,

include/rfl/cereal/Writer.hpp

Lines changed: 30 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,19 @@ class Writer {
3838
using OutputUnionType = CerealOutputUnion;
3939
using OutputVarType = CerealOutputVar;
4040

41-
Writer(CerealArchive* _archive) : archive_(_archive) {}
41+
Writer(CerealArchive* _archive);
4242

4343
~Writer() = default;
4444

45-
OutputArrayType array_as_root(const size_t _size) const {
46-
(*archive_)(::cereal::make_size_tag(_size));
47-
return OutputArrayType{};
48-
}
45+
OutputArrayType array_as_root(const size_t _size) const;
4946

50-
OutputMapType map_as_root(const size_t _size) const {
51-
(*archive_)(::cereal::make_size_tag(_size));
52-
return OutputMapType{};
53-
}
47+
OutputMapType map_as_root(const size_t _size) const;
5448

55-
OutputObjectType object_as_root(const size_t _size) const {
56-
return OutputObjectType{};
57-
}
49+
OutputObjectType object_as_root(const size_t _size) const;
5850

59-
OutputUnionType union_as_root() const { return OutputUnionType{}; }
51+
OutputUnionType union_as_root() const;
6052

61-
OutputVarType null_as_root() const { return OutputVarType{}; }
53+
OutputVarType null_as_root() const;
6254

6355
template <class T>
6456
OutputVarType value_as_root(const T& _var) const {
@@ -67,105 +59,57 @@ class Writer {
6759
}
6860

6961
OutputArrayType add_array_to_array(const size_t _size,
70-
OutputArrayType* _parent) const {
71-
(*archive_)(::cereal::make_size_tag(_size));
72-
return OutputArrayType{};
73-
}
62+
OutputArrayType* _parent) const;
7463

7564
OutputArrayType add_array_to_map(const std::string_view& _name,
7665
const size_t _size,
77-
OutputMapType* _parent) const {
78-
add_string_view(_name);
79-
(*archive_)(::cereal::make_size_tag(_size));
80-
return OutputArrayType{};
81-
}
66+
OutputMapType* _parent) const;
8267

8368
OutputArrayType add_array_to_object(const std::string_view& _name,
8469
const size_t _size,
85-
OutputObjectType* _parent) const {
86-
(*archive_)(::cereal::make_size_tag(_size));
87-
return OutputArrayType{};
88-
}
70+
OutputObjectType* _parent) const;
8971

9072
OutputArrayType add_array_to_union(const size_t _index, const size_t _size,
91-
OutputUnionType* _parent) const {
92-
(*archive_)(_index);
93-
(*archive_)(::cereal::make_size_tag(_size));
94-
return OutputArrayType{};
95-
}
73+
OutputUnionType* _parent) const;
9674

9775
OutputMapType add_map_to_array(const size_t _size,
98-
OutputArrayType* _parent) const {
99-
(*archive_)(::cereal::make_size_tag(_size));
100-
return OutputMapType{};
101-
}
76+
OutputArrayType* _parent) const;
10277

10378
OutputMapType add_map_to_map(const std::string_view& _name,
10479
const size_t _size,
105-
OutputMapType* _parent) const {
106-
(*archive_)(std::string(_name));
107-
(*archive_)(::cereal::make_size_tag(_size));
108-
return OutputMapType{};
109-
}
80+
OutputMapType* _parent) const;
11081

11182
OutputMapType add_map_to_object(const std::string_view& _name,
11283
const size_t _size,
113-
OutputObjectType* _parent) const {
114-
(*archive_)(::cereal::make_size_tag(_size));
115-
return OutputMapType{};
116-
}
84+
OutputObjectType* _parent) const;
11785

11886
OutputMapType add_map_to_union(const size_t _index, const size_t _size,
119-
OutputUnionType* _parent) const {
120-
(*archive_)(_index);
121-
(*archive_)(::cereal::make_size_tag(_size));
122-
return OutputMapType{};
123-
}
87+
OutputUnionType* _parent) const;
12488

12589
OutputObjectType add_object_to_array(const size_t _size,
126-
OutputArrayType* _parent) const {
127-
return OutputObjectType{};
128-
}
90+
OutputArrayType* _parent) const;
12991

13092
OutputObjectType add_object_to_map(const std::string_view& _name,
13193
const size_t _size,
132-
OutputMapType* _parent) const {
133-
add_string_view(_name);
134-
return OutputObjectType{};
135-
}
94+
OutputMapType* _parent) const;
13695

13796
OutputObjectType add_object_to_object(const std::string_view& _name,
13897
const size_t _size,
139-
OutputObjectType* _parent) const {
140-
return OutputObjectType{};
141-
}
98+
OutputObjectType* _parent) const;
14299

143100
OutputObjectType add_object_to_union(const size_t _index, const size_t _size,
144-
OutputUnionType* _parent) const {
145-
(*archive_)(_index);
146-
return OutputObjectType{};
147-
}
101+
OutputUnionType* _parent) const;
148102

149-
OutputUnionType add_union_to_array(OutputArrayType* _parent) const {
150-
return OutputUnionType{};
151-
}
103+
OutputUnionType add_union_to_array(OutputArrayType* _parent) const;
152104

153105
OutputUnionType add_union_to_map(const std::string_view& _name,
154-
OutputMapType* _parent) const {
155-
add_string_view(_name);
156-
return OutputUnionType{};
157-
}
106+
OutputMapType* _parent) const;
158107

159108
OutputUnionType add_union_to_object(const std::string_view& _name,
160-
OutputObjectType* _parent) const {
161-
return OutputUnionType{};
162-
}
109+
OutputObjectType* _parent) const;
163110

164111
OutputUnionType add_union_to_union(const size_t _index,
165-
OutputUnionType* _parent) const {
166-
(*archive_)(_index);
167-
return OutputUnionType{};
168-
}
112+
OutputUnionType* _parent) const;
169113

170114
template <class T>
171115
OutputVarType add_value_to_array(const T& _var, OutputArrayType*) const {
@@ -196,38 +140,25 @@ class Writer {
196140
return OutputVarType{};
197141
}
198142

199-
OutputVarType add_null_to_array(OutputArrayType* _parent) const {
200-
return OutputVarType{};
201-
}
143+
OutputVarType add_null_to_array(OutputArrayType* _parent) const;
202144

203145
OutputVarType add_null_to_map(const std::string_view& _name,
204-
OutputMapType* _parent) const {
205-
add_string_view(_name);
206-
return OutputVarType{};
207-
}
146+
OutputMapType* _parent) const;
208147

209148
OutputVarType add_null_to_object(const std::string_view& _name,
210-
OutputObjectType* _parent) const {
211-
return OutputVarType{};
212-
}
149+
OutputObjectType* _parent) const;
213150

214151
OutputVarType add_null_to_union(const size_t _index,
215-
OutputUnionType* _parent) const {
216-
(*archive_)(_index);
217-
return OutputVarType{};
218-
}
152+
OutputUnionType* _parent) const;
219153

220-
void end_array(OutputArrayType* _arr) const noexcept {}
154+
void end_array(OutputArrayType* _arr) const noexcept;
221155

222-
void end_map(OutputMapType* _map) const noexcept {}
156+
void end_map(OutputMapType* _map) const noexcept;
223157

224-
void end_object(OutputObjectType* _obj) const noexcept {}
158+
void end_object(OutputObjectType* _obj) const noexcept;
225159

226160
private:
227-
void add_string_view(const std::string_view& _str) const {
228-
(*archive_)(::cereal::make_size_tag(_str.size()));
229-
(*archive_)(::cereal::binary_data(_str.data(), _str.size()));
230-
}
161+
void add_string_view(const std::string_view& _str) const;
231162

232163
template <class T>
233164
void add_value(const T& _var) const noexcept {

src/reflectcpp_cereal.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ SOFTWARE.
2929
// Also, this speeds up compile time, compared to multiple separate .cpp files
3030
// compilation.
3131

32-
// Cereal is header-only, so this file is minimal
32+
#include "rfl/cereal/Reader.cpp"
33+
#include "rfl/cereal/Writer.cpp"

src/rfl/cereal/Reader.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2023-2024 Code17 GmbH
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
#include "rfl/cereal/Reader.hpp"
28+
29+
namespace rfl::cereal {
30+
31+
bool Reader::is_empty(const InputVarType& _var) const noexcept {
32+
return _var.archive_ == nullptr;
33+
}
34+
35+
rfl::Result<Reader::InputArrayType> Reader::to_array(
36+
const InputVarType& _var) const noexcept {
37+
return InputArrayType{_var.archive_};
38+
}
39+
40+
rfl::Result<Reader::InputObjectType> Reader::to_object(
41+
const InputVarType& _var) const noexcept {
42+
return InputObjectType{_var.archive_};
43+
}
44+
45+
rfl::Result<Reader::InputMapType> Reader::to_map(
46+
const InputVarType& _var) const noexcept {
47+
return InputMapType{_var.archive_};
48+
}
49+
50+
rfl::Result<Reader::InputUnionType> Reader::to_union(
51+
const InputVarType& _var) const noexcept {
52+
return InputUnionType{_var.archive_};
53+
}
54+
55+
} // namespace rfl::cereal

0 commit comments

Comments
 (0)