88
99namespace rsl ::serializer::_repr_impl {
1010
11- struct SerializerBase {
12- template <typename T, typename V>
13- void descend (this T&& self, V&& value){
14- Meta<std::remove_cvref_t <T>>::descend (std::forward<T>(self), std::forward<V>(value));
11+ class Serializer {
12+ std::ostringstream out;
13+ bool separate = false ;
14+ std::size_t level = 0 ;
15+
16+ void print_indent () {
17+ // out << "\n";
18+ // out << std::string(2 * level, ' ');
19+ }
20+
21+ void print_separator () {
22+ if (separate) {
23+ out << " , " ;
24+ } else {
25+ separate = true ;
26+ }
27+ print_indent ();
28+ }
29+
30+ void increase_nesting () {
31+ separate = false ;
32+ out << ' {' ;
33+ ++level;
34+ }
35+
36+ void decrease_nesting () {
37+ --level;
38+ print_indent ();
39+ out << ' }' ;
40+ separate = true ;
1541 }
16- };
1742
18- class Serializer : SerializerBase{
19- std::size_t nesting_level = 0 ;
20- std::ostringstream out;
2143public:
2244 Serializer () = default ;
2345
46+ std::string finalize () const {
47+ return out.str ();
48+ }
49+
2450 template <has_members R, typename T>
25- void operator ()(R, T&& value) {
26- out << ' {' ;
27- ++nesting_level;
28- descend (std::forward<T>(value));
29- --nesting_level;
30- out << ' }' ;
51+ void operator ()(R meta, T&& value) {
52+ print_separator ();
53+
54+ out << identifier_of (R::info);
55+ increase_nesting ();
56+ meta.descend (*this , std::forward<T>(value));
57+ decrease_nesting ();
58+ }
59+
60+ template <is_iterable R, typename T>
61+ void operator ()(R meta, T&& value) {
62+ print_separator ();
63+ out << define_static_string (display_string_of (type_of (R::info)));
64+ increase_nesting ();
65+ meta.descend (*this , std::forward<T>(value));
66+ decrease_nesting ();
3167 }
3268
3369 template <typename R, typename T>
34- requires (std::is_scalar_v<T >)
70+ requires (std::is_arithmetic_v<std:: remove_cvref_t <T> >)
3571 void operator ()(R, T&& value) {
72+ print_separator ();
3673 out << value;
3774 }
3875};
3976
40- }
77+ } // namespace rsl::serializer::_repr_impl
0 commit comments