DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
serialization_document_elements.h
1 /*********************************************************************************************************************************************/
2 /* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3 /* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4 /* document analysis. Offline processing possible for security and confidentiality */
5 /* */
6 /* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7 /* Project homepage: https://github.com/docwire/docwire */
8 /* */
9 /* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DocWire-Commercial */
10 /*********************************************************************************************************************************************/
11 
12 #ifndef DOCWIRE_SERIALIZATION_DOCUMENT_ELEMENTS_H
13 #define DOCWIRE_SERIALIZATION_DOCUMENT_ELEMENTS_H
14 
15 #include "attributes.h"
16 #include "document_elements.h"
17 #include "serialization_base.h"
18 #include "serialization_filesystem.h" // IWYU pragma: keep
19 
20 namespace docwire::serialization
21 {
22 
26 template <typename T>
27 concept with_styling = requires(T t) { t.styling; };
28 
32 template <with_styling T>
33 struct serializer<T> {
34  value full(const T& val) const { return object{{{"styling", full(val.styling)}}}; }
35  value typed_summary(const T& val) const { return decorate_with_typeid(full(val), type_name::pretty<T>()); }
36 };
37 
38 template <> struct serializer<document::text>
39 {
40  value full(const document::text& text) const
41  {
42  return object{{{"text", text.text}}};
43  }
44  value typed_summary(const document::text& text) const { return decorate_with_typeid(full(text), type_name::pretty<document::text>()); }
45 };
46 
47 template <> struct serializer<document::link>
48 {
49  value full(const document::link& link) const
50  {
51  return object{{
52  {"url", serialization::full(link.url)},
53  {"styling", serialization::full(link.styling)}
54  }};
55  }
56  value typed_summary(const document::link& link) const { return decorate_with_typeid(full(link), type_name::pretty<document::link>()); }
57 };
58 
59 template <> struct serializer<document::image>
60 {
61  value full(const document::image& image) const
62  {
63  return object{{
64  {"alt", serialization::full(image.alt)},
65  {"styling", serialization::full(image.styling)}
66  }};
67  }
68  value typed_summary(const document::image& image) const { return decorate_with_typeid(serialization::full(image), type_name::pretty<document::image>()); }
69 };
70 
71 template <> struct serializer<document::style>
72 {
73  value full(const document::style& style) const
74  {
75  return object{{{"css_text", style.css_text}}};
76  }
77  value typed_summary(const document::style& style) const { return decorate_with_typeid(serialization::full(style), type_name::pretty<document::style>()); }
78 };
79 
80 template <> struct serializer<document::list>
81 {
82  value full(const document::list& list) const
83  {
84  return object{{
85  {"type", serialization::full(list.type)},
86  {"styling", serialization::full(list.styling)}
87  }};
88  }
89  value typed_summary(const document::list& list) const { return decorate_with_typeid(serialization::full(list), type_name::pretty<document::list>()); }
90 };
91 
92 template <> struct serializer<document::comment>
93 {
94  value full(const document::comment& comment) const
95  {
96  return object{{
97  {"author", serialization::full(comment.author)},
98  {"time", serialization::full(comment.time)},
99  {"comment", serialization::full(comment.comment)}
100  }};
101  }
102  value typed_summary(const document::comment& comment) const { return decorate_with_typeid(full(comment), type_name::pretty<document::comment>()); }
103 };
104 
105 template <>
106 struct serializer<attributes::styling>
107 {
108  value full(const attributes::styling& styling) const
109  {
110  return object{{
111  {"classes", serialization::full(styling.classes)},
112  {"id", serialization::full(styling.id)},
113  {"style", serialization::full(styling.style)}
114  }};
115  }
116  value typed_summary(const attributes::styling& styling) const { return decorate_with_typeid(serialization::full(styling), type_name::pretty<attributes::styling>()); }
117 };
118 
119 } // namespace docwire::serialization
120 
121 #endif // DOCWIRE_SERIALIZATION_DOCUMENT_ELEMENTS_H
Provides a generic, concept-based serialization framework.
value decorate_with_typeid(const value &base_val, const std::string &typeid_str)
Helper to decorate a serialized value with a typeid string.
requires(std::is_arithmetic_v< T > &&!value_alternative< T >) struct serializer< T >
Specialization for arithmetic types (integers, floats).
std::variant< std::nullptr_t, bool, std::int64_t, std::uint64_t, double, std::string, array, object > value
A variant type representing any serialized value.
concept with_styling
Concept for types that have a styling member.
value full(const T &value)
Serializes a value of type T into a docwire::serialization::value.
Represents CSS-like styling information for document elements.
Definition: attributes.h:34
std::vector< std::string > classes
List of CSS classes.
Definition: attributes.h:36
std::string id
Unique identifier for the element.
Definition: attributes.h:38
std::string style
Inline style string.
Definition: attributes.h:40
std::optional< std::string > alt
Optional alternative text for the image.
Primary template for the serializer.