tetengo 1.8.2
A multipurpose library set
Loading...
Searching...
No Matches
encoder.hpp
Go to the documentation of this file.
1
7#if !defined(TETENGO_TEXT_ENCODER_HPP)
8#define TETENGO_TEXT_ENCODER_HPP
9
10#include <boost/core/noncopyable.hpp>
11
12
13namespace tetengo::text
14{
18 class encoder_base : private boost::noncopyable
19 {
20 public:
21 // constructors and destructor
22
26 virtual ~encoder_base() = 0;
27 };
28
29
35 template <typename Encoding>
36 class encoder : public encoder_base
37 {
38 public:
39 // types
40
42 using encoding_type = Encoding;
43
45 using string_type = typename encoding_type::string_type;
46
48 using string_view_type = typename encoding_type::string_view_type;
49
51 using encoded_string_type = typename encoding_type::encoded_string_type;
52
54 using encoded_string_view_type = typename encoding_type::encoded_string_view_type;
55
56
57 // static functions
58
64 [[nodiscard]] static const encoder& instance()
65 {
66 static const encoder singleton{};
67 return singleton;
68 }
69
70
71 // constructors and destructor
72
76 virtual ~encoder() = default;
77
78
79 // functions
80
88 [[nodiscard]] encoded_string_type encode(const string_view_type& string_) const
89 {
90 return encoding_type::instance().encode(string_);
91 }
92
100 [[nodiscard]] string_type decode(const encoded_string_view_type& encoded_string) const
101 {
102 return encoding_type::instance().decode(encoded_string);
103 }
104 };
105
106
107}
108
109
110#endif
An encoder base.
Definition encoder.hpp:19
virtual ~encoder_base()=0
Destroys the encoder base.
An encoder.
Definition encoder.hpp:37
string_type decode(const encoded_string_view_type &encoded_string) const
Decodes a string.
Definition encoder.hpp:100
typename encoding_type::encoded_string_type encoded_string_type
The encoded string type.
Definition encoder.hpp:51
Encoding encoding_type
The encoding type.
Definition encoder.hpp:42
static const encoder & instance()
Returns the instance.
Definition encoder.hpp:64
encoded_string_type encode(const string_view_type &string_) const
Encodes a string.
Definition encoder.hpp:88
virtual ~encoder()=default
Destroys the encoder.
typename encoding_type::string_type string_type
The string type.
Definition encoder.hpp:45
typename encoding_type::string_view_type string_view_type
The string view type.
Definition encoder.hpp:48
typename encoding_type::encoded_string_view_type encoded_string_view_type
The encoded string view type.
Definition encoder.hpp:54
A text library.