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 Class Reference

#include <Serializer.h>

Public Member Functions

std::string getSeparator ()
 Return the separator of the Serializer.
 
void setSeparator (const std::string &separator)
 Set the separator of the Serializer.
 
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 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, or at the end.
 
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.
 
std::string get (const std::string &ID)
 Return the serialized string of the given ID.
 
std::vector< std::string > split (const std::string &str)
 Return a vector containing the strings obtained after a split with the separator.
 
void clear (const std::string &ID)
 Clear the string given by the ID.
 

Static Public Member Functions

static SerializergetInstance ()
 Return the current instance of the object or create one if it does not exist.
 

Protected Attributes

std::string separator
 This string virtually divide the serialized strings.
 
std::unordered_map< std::string, std::vector< std::string > > serializedStrings
 Unordered map linking the ID of the serialized string and the serialized string.
 

Member Function Documentation

◆ add() [1/2]

void Serializer::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.

Parameters
IDSerialized string's ID.
valueValue to append to the serialized string.

◆ add() [2/2]

void Serializer::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, or at the end.

Same behaviour as add without index if the given slot is higher than the number of slots in the string.

This method have an higher time complexity than the other one in case of insertion inside the string.

Parameters
IDSerialized string's ID.
valueValue to insert in the serialized string.
idxIndex at which the value should be insert.

◆ clear()

void Serializer::clear ( const std::string & ID)

Clear the string given by the ID.

Parameters
IDSerialized string's ID to clear.

◆ edit()

void Serializer::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.

If there is no value at this index, insert the value at the end.

Parameters
IDSerialized string's ID.
valueValue to insert in the serialized string.
idxIndex at which the value should be edit.

◆ get()

std::string Serializer::get ( const std::string & ID)

Return the serialized string of the given ID.

Warning
Build the string with the separator at each run.
Parameters
IDDesired serialized string's ID.

◆ getInstance()

static Serializer & Serializer::getInstance ( )
static

Return the current instance of the object or create one if it does not exist.

This class is a Singleton.

◆ getSeparator()

std::string Serializer::getSeparator ( )

Return the separator of the Serializer.

◆ setSeparator()

void Serializer::setSeparator ( const std::string & separator)

Set the separator of the Serializer.

Automatically called by the Server/Client upon creation.

Parameters
separatorThe separator that should be used by the Serializer.

◆ split()

std::vector< std::string > Serializer::split ( const std::string & str)

Return a vector containing the strings obtained after a split with the separator.

Parameters
strThe string to split using the separator.

Member Data Documentation

◆ separator

std::string Serializer::separator
protected

This string virtually divide the serialized strings.

E.g.: STR1 = "ABC" STR2 = "CBA" sep = "/" ==> "ABC/CBA" (when STR1 is concatened with STR2)

◆ serializedStrings

std::unordered_map<std::string, std::vector<std::string> > Serializer::serializedStrings
protected

Unordered map linking the ID of the serialized string and the serialized string.


The documentation for this class was generated from the following file: