NSCpp 2.0
NSCpp is a modern C++20 server/client framework designed to simplify network programming in C++. With robust support for both IPv4 and IPv6, as well as TCP and UDP communication protocols.
 
Loading...
Searching...
No Matches
Serializer.h
Go to the documentation of this file.
1
6
7#include <unordered_map>
8#include <string>
9#include <vector>
10#include <shared_mutex>
11#include <sstream>
12
13#ifndef _SERIALIZER_H
14#define _SERIALIZER_H
15
21void sanitizeString(const std::string& separator, std::string& value);
22
23class Serializer {
24public:
29 static Serializer& getInstance();
30
34 std::string getSeparator();
35
41 void setSeparator(const std::string& separator);
42
48 void add(const std::string& ID, const std::string& value);
49
58 void add(const std::string& ID, const std::string& value, size_t idx);
59
67 void edit(const std::string& ID, const std::string& value, size_t idx);
68
74 std::string get(const std::string& ID);
75
80 std::vector<std::string> split(const std::string& str);
81
86 void clear(const std::string& ID);
87
88protected:
97 std::string separator;
98
102 std::unordered_map<std::string, std::vector<std::string>> serializedStrings;
103
104private:
105 Serializer() = default;
106 ~Serializer() = default;
107
108 // Design to be used by multiple threads =>
109 std::shared_mutex mtx;
110
111 // We block the different way to copy or deplace it
112 Serializer(const Serializer&) = delete;
113 Serializer& operator=(const Serializer&) = delete;
114 Serializer(Serializer&&) = delete;
115 Serializer& operator=(Serializer&&) = delete;
116 };
117
118#endif //_SERIALIZER_H
void sanitizeString(const std::string &separator, std::string &value)
Project NSCpp.
std::string separator
This string virtually divide the serialized strings.
Definition Serializer.h:97
std::string getSeparator()
Return the separator of the Serializer.
void setSeparator(const std::string &separator)
Set the separator of the Serializer.
std::unordered_map< std::string, std::vector< std::string > > serializedStrings
Unordered map linking the ID of the serialized string and the serialized string.
Definition Serializer.h:102
std::string get(const std::string &ID)
Return the serialized string of the given ID.
static Serializer & getInstance()
Return the current instance of the object or create one if it does not exist.
void add(const std::string &ID, const std::string &value)
Add to the string (given by its ID) the sanitized version of the value, at the end.
void clear(const std::string &ID)
Clear the string given by the ID.
std::vector< std::string > split(const std::string &str)
Return a vector containing the strings obtained after a split with the separator.
void add(const std::string &ID, const std::string &value, size_t idx)
Add to the string (given by its ID) the sanitized version of the value at the given index,...
void edit(const std::string &ID, const std::string &value, size_t idx)
Edit the string (given by its ID) with the serialized version of the value at the given index.