Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
Loading...
Searching...
No Matches

Description


Serializers of diverse types to/from serial channels.

In Elementa, a serializer is a class able to serialize/deserialize another class, which is called the serializable class. This separation of concepts allows us to define several serialization formats for the same serializable class, and also to define serializations on primitive types that have none.

There are two ways of defining serializers: either derive from Serializer<> (creating a new serializer for some class) or derive the serializable class from Serializable (embedding the serializer directly into the serializable class).

See also
Serial channels
Author
Juan-Antonio Fernandez-Madrigal. http://jafma.net
Date
2018-2020
Collaboration diagram for Serializers:

Classes

class  elementa::base::SzerError
 Base class for all errors thrown by serializers. More...
 
class  elementa::base::Serializer< Sble, ReturnDeserType, ReturnSerType >
 Base abstract class / interface for any serializer. More...
 
class  elementa::base::Serializable< DeserReturnType, SerReturnType >
 Base class for any object that includes an implicit serializer. More...
 
class  elementa::base::Szer_Char
 Serializer of a single char. Not very useful, but sometimes it is needed. More...
 
class  elementa::base::Szer_String
 Serializer of std::string into fixed or non-fixed size. More...
 
class  elementa::base::Szer_NatBin< NatType >
 Serializer of natural numbers in fixed or non-fixed size. More...
 
class  elementa::base::Szer_IntText
 Serializer of integer numbers as text in fixed or non-fixed size. More...
 
class  elementa::base::Szer_RealText
 Serializer of real numbers as text in fixed or dynamic size. More...
 
class  elementa::base::Szer_StringToken
 Serializer of a std::string as a token (useful for lexers). More...
 

Typedefs

template<class Sble , class DeserReturnType = void, class SerReturnType = void>
using elementa::base::ClassSzer = ClassSzer_< Sble, DeserReturnType, SerReturnType >
 Objects of this class act as Serializer's for Serializable objects. More...
 

Functions

template<class DeserReturnType , class SerReturnType >
OutSerChelementa::base::operator<< (OutSerCh &chout, const Serializable< DeserReturnType, SerReturnType > &o)
 Operator for serializing Serializable objects directly on a channel. More...
 
template<class DeserReturnType , class SerReturnType >
InSerChelementa::base::operator>> (InSerCh &chin, Serializable< DeserReturnType, SerReturnType > &o)
 Operator for deserializing Serializable objects directly from a channel. More...
 
void elementa::base::Szer_NatBin< NatType >::ser (OutSerCh &chout, const NatType &obj)
 Serialization of the object into CHOUT. More...
 
void elementa::base::Szer_NatBin< NatType >::deser (InSerCh &chin, NatType &obj)
 Deserializes the number from CHIN. More...
 

Class Documentation

◆ elementa::base::SzerError

class elementa::base::SzerError

Base class for all errors thrown by serializers.

Note
- All exceptions thrown by the code in the classes and routines of this file are of type SzerError directly (without deriving from it).

Definition at line 82 of file serializers.h.

Inheritance diagram for elementa::base::SzerError:
Collaboration diagram for elementa::base::SzerError:

Public Types

Types, consts., etc.
using StdBase = std::runtime_error
 

Public Member Functions

 SzerError (const std::string &explanation)
 
Launching methods
virtual ExcasERR (const std::string &context) noexcept
 Transform it to be thrown as ERR with the given context. More...
 
virtual ExcasEXC (const std::string &place, const RTTextWithEnum::Combination &flags={RTTextWith::kAll_}) noexcept
 Transform it to be thrown as EXC with the given place and flags. More...
 
Catching methods
const char * what (void) const noexcept override
 Return the complete message. It will live as long as this exception. More...
 
const char * explanation (void) const noexcept
 Return the explanation only. It will live as long as this exception. More...
 
const char * context (void) const noexcept
 Return the place (EXC) or context (ERR) only. Will live as long as this. More...
 

Member Typedef Documentation

◆ StdBase

using elementa::base::Exc::StdBase = std::runtime_error
inherited

Definition at line 119 of file exceptions.h.

Constructor & Destructor Documentation

◆ SzerError()

elementa::base::SzerError::SzerError ( const std::string &  explanation)
inline

Definition at line 86 of file serializers.h.

Member Function Documentation

◆ asERR()

virtual Exc & elementa::base::Exc::asERR ( const std::string &  context)
virtualnoexceptinherited

◆ asEXC()

virtual Exc & elementa::base::Exc::asEXC ( const std::string &  place,
const RTTextWithEnum::Combination &  flags = {RTTextWith::kAll_} 
)
virtualnoexceptinherited

Transform it to be thrown as EXC with the given place and flags.

The flags are explained in debugging.h, runtime_src_place() function.

Referenced by elementa::base::Szer_Char::deser(), and elementa::base::Szer_NatBin< NatType >::deser().

◆ what()

const char * elementa::base::Exc::what ( void  ) const
inlineoverridenoexceptinherited

Return the complete message. It will live as long as this exception.

The message will be one-line except if the explanation or place/context contain some CR.

Definition at line 161 of file exceptions.h.

◆ explanation()

const char * elementa::base::Exc::explanation ( void  ) const
inlinenoexceptinherited

Return the explanation only. It will live as long as this exception.

Definition at line 164 of file exceptions.h.

◆ context()

const char * elementa::base::Exc::context ( void  ) const
inlinenoexceptinherited

Return the place (EXC) or context (ERR) only. Will live as long as this.

Definition at line 167 of file exceptions.h.

◆ elementa::base::Serializer

class elementa::base::Serializer
template<class Sble, class ReturnDeserType = void, class ReturnSerType = void>
class elementa::base::Serializer< Sble, ReturnDeserType, ReturnSerType >

Base abstract class / interface for any serializer.

New serializers must derive from this and be named "Szer_<sertype><mode>", where "sertype" is the type being serialized and "mode" the way the serializer works.

"ReturnSerType" and "ReturnDeserType" can be used for specifying return types for the serializer methods different from void (e.g., returning the total number of bytes deserialized in the deser() method).

The ser() and deser() methods throw an unimplemented error here for saving effort in writing derived serializers: they may provide just one serialization direction if they wish.

Usage:

  • Doing serializations:
Szer_One{}.ser(ch,obj); // serializes the object into the channel
Szer_One{}.deser(ch,obj); // deserializes from the channel into OBJ
  • A serializer S2 can be based on the code of another one S1 in two ways:

    • Through composition: S2 can create internally an S1 object and use it. This is common when S1 serializes objects of a class that are components (members) of objects of the class that S2 serializes.
    • Through inheritance: S2 can derive from S1. In that way, both serialize the same classes of objects, but S2 changes the serialization of S1 (or reuses it) by overriding the ser() / deser() methods.

    NOTE-1: Violation of the "unimplemented by default" rule: If S2 does not implement some of these methods but S1 does, the method will no longer be unimplemented (the one of S1 will be called). In that case you need to explicitly throw an unimplemented exception in the method of S2.

    NOTE-2: Parallel hierarchies of serializers and serializables: If S1 is a base of serializers for serializable objects that derive from some object base A, and S1 is to be used polymorphically (i.e., we need to refer to szers derived from S1 as S1 * or S1 &), S1 must inherit from Serializer; also, derived serializers from S1 (intended for serializations of classes derived from A) must declare the ser() / deser() methods with parameters of type A, not of the classes derived from A, since otherwise those declarations would not be proper overridings (actually, the declared methods should have the "override" keyword to detect possible problems in this sense); finally, inside the methods, dynamic_cast<> has to be used for getting the particular class derived from A. On the other hand, if S1 is not to be used polymorphically, the inheritance from Serializer can be dropped from S1 and put instead in each derived serializer, which then can declare the methods with the particular classes derived from A, not requiring any dynamic_cast.

  • Serializable classes can also have inheritance; their serializers behave as follows:
    • A serializer of a class A can be used directly on objects of type A and on objects of types derived from A (although only the A part of the latter will be serialized).
    • A serializer for a class B derived from class A can be defined as a new serializer, as though class B were not derived from A nor using any existing serializer for A.
    • Also, a serializer of a class B derived from A can reuse the code of a serializer of class A, but only through composition (see above), since doing it through inheritance from the existing serializer would define a serializer for A, not for B.
Note
- This base class is thread-safe, but derived ones are not assured to be.
- In common use, serializer objects may be created and destroyed frequently, thus it is convenient that derived classes do little work at their constructors.

Definition at line 188 of file serializers.h.

Public Types

using SType = Sble
 To access the Sble type parameter of this type. More...
 
using RDeserType = Sble
 To access the ReturnDeserType type parameter of this type. More...
 
using RSerType = Sble
 To access the ReturnSerType type parameter of this type. More...
 

Public Member Functions

virtual ReturnSerType ser (OutSerCh &chout, const Sble &obj)
 Serializes an object, writing the resulting chars into CHOUT. More...
 
virtual ReturnDeserType deser (InSerCh &chin, Sble &obj)
 Deserializes an object from a sequence of chars in CHIN. More...
 

Member Typedef Documentation

◆ SType

template<class Sble , class ReturnDeserType = void, class ReturnSerType = void>
using elementa::base::Serializer< Sble, ReturnDeserType, ReturnSerType >::SType = Sble

To access the Sble type parameter of this type.

Definition at line 193 of file serializers.h.

◆ RDeserType

template<class Sble , class ReturnDeserType = void, class ReturnSerType = void>
using elementa::base::Serializer< Sble, ReturnDeserType, ReturnSerType >::RDeserType = Sble

To access the ReturnDeserType type parameter of this type.

Definition at line 196 of file serializers.h.

◆ RSerType

template<class Sble , class ReturnDeserType = void, class ReturnSerType = void>
using elementa::base::Serializer< Sble, ReturnDeserType, ReturnSerType >::RSerType = Sble

To access the ReturnSerType type parameter of this type.

Definition at line 199 of file serializers.h.

Member Function Documentation

◆ ser()

template<class Sble , class ReturnDeserType = void, class ReturnSerType = void>
virtual ReturnSerType elementa::base::Serializer< Sble, ReturnDeserType, ReturnSerType >::ser ( OutSerCh chout,
const Sble &  obj 
)
inlinevirtual

Serializes an object, writing the resulting chars into CHOUT.

Must throw if any error during serialization, including channel errors (in that case, the channel can be left in the state it was when the error occurred).

Reimplemented in elementa::base::Szer_Char, elementa::base::Szer_IntText, elementa::base::Szer_RealText, elementa::base::Szer_NatBin< NatType >, elementa::base::Szer_StringToken, and elementa::base::Szer_String.

Definition at line 206 of file serializers.h.

References ELE_CODE_UNIMPLEMENTED.

◆ deser()

template<class Sble , class ReturnDeserType = void, class ReturnSerType = void>
virtual ReturnDeserType elementa::base::Serializer< Sble, ReturnDeserType, ReturnSerType >::deser ( InSerCh chin,
Sble &  obj 
)
inlinevirtual

Deserializes an object from a sequence of chars in CHIN.

Must change the content of OBJ with the result. Throw if any error during serialization, including channel errors (in that case, the channel and the object are left in the state they were at the moment of the error).

Reimplemented in elementa::base::Szer_Char, elementa::base::Szer_IntText, elementa::base::Szer_RealText, elementa::base::Szer_NatBin< NatType >, elementa::base::Szer_StringToken, and elementa::base::Szer_String.

Definition at line 214 of file serializers.h.

References ELE_CODE_UNIMPLEMENTED.

◆ elementa::base::Serializable

class elementa::base::Serializable
template<class DeserReturnType = void, class SerReturnType = void>
class elementa::base::Serializable< DeserReturnType, SerReturnType >

Base class for any object that includes an implicit serializer.

Note
- Any serializable class can provide one or all of the methods.
- Serializable objects cannot maintain any state on the serialization process.
- Serializable objects cannot use location tracking.
- If you need any of these features, define a separate Serializer.
- Serializable classes constructors can include an initialization of some data needed for serializations; that must be done in the constructor of the class.

Definition at line 250 of file serializers.h.

Public Member Functions

virtual SerReturnType serme (OutSerCh &chout) const
 Method to serialize the object into CHOUT. More...
 
virtual DeserReturnType deserme (InSerCh &chin)
 Method to deserialize the object from CHOUT. More...
 

Member Function Documentation

◆ serme()

template<class DeserReturnType = void, class SerReturnType = void>
virtual SerReturnType elementa::base::Serializable< DeserReturnType, SerReturnType >::serme ( OutSerCh chout) const
inlinevirtual

Method to serialize the object into CHOUT.

Note that the method must be const.

Definition at line 256 of file serializers.h.

References ELE_CODE_UNIMPLEMENTED.

Referenced by elementa::base::operator<<().

◆ deserme()

template<class DeserReturnType = void, class SerReturnType = void>
virtual DeserReturnType elementa::base::Serializable< DeserReturnType, SerReturnType >::deserme ( InSerCh chin)
inlinevirtual

Method to deserialize the object from CHOUT.

Definition at line 260 of file serializers.h.

References ELE_CODE_UNIMPLEMENTED.

Referenced by elementa::base::operator>>().

◆ elementa::base::Szer_Char

class elementa::base::Szer_Char

Serializer of a single char. Not very useful, but sometimes it is needed.

Definition at line 387 of file serializers.h.

Inheritance diagram for elementa::base::Szer_Char:
Collaboration diagram for elementa::base::Szer_Char:

Public Types

using SType = char
 To access the Sble type parameter of this type. More...
 
using RDeserType = char
 To access the ReturnDeserType type parameter of this type. More...
 
using RSerType = char
 To access the ReturnSerType type parameter of this type. More...
 

Public Member Functions

void ser (OutSerCh &chout, const char &c)
 Serializes an object, writing the resulting chars into CHOUT. More...
 
void deser (InSerCh &chin, char &c)
 Deserializes an object from a sequence of chars in CHIN. More...
 

Member Typedef Documentation

◆ SType

using elementa::base::Serializer< char , void , void >::SType = char
inherited

To access the Sble type parameter of this type.

Definition at line 193 of file serializers.h.

◆ RDeserType

using elementa::base::Serializer< char , void , void >::RDeserType = char
inherited

To access the ReturnDeserType type parameter of this type.

Definition at line 196 of file serializers.h.

◆ RSerType

using elementa::base::Serializer< char , void , void >::RSerType = char
inherited

To access the ReturnSerType type parameter of this type.

Definition at line 199 of file serializers.h.

Member Function Documentation

◆ ser()

void elementa::base::Szer_Char::ser ( OutSerCh chout,
const char &  obj 
)
inlinevirtual

Serializes an object, writing the resulting chars into CHOUT.

Must throw if any error during serialization, including channel errors (in that case, the channel can be left in the state it was when the error occurred).

Reimplemented from elementa::base::Serializer< char >.

Definition at line 391 of file serializers.h.

References ELE_CODE_PLACE, and elementa::base::serch_isgood().

◆ deser()

void elementa::base::Szer_Char::deser ( InSerCh chin,
char &  obj 
)
inlinevirtual

Deserializes an object from a sequence of chars in CHIN.

Must change the content of OBJ with the result. Throw if any error during serialization, including channel errors (in that case, the channel and the object are left in the state they were at the moment of the error).

Reimplemented from elementa::base::Serializer< char >.

Definition at line 394 of file serializers.h.

References elementa::base::Exc::asEXC(), ELE_CODE_PLACE, and elementa::base::serch_isexhausted().

◆ elementa::base::Szer_String

class elementa::base::Szer_String

Serializer of std::string into fixed or non-fixed size.

For fixed size, the string is serialized occupying that size. For non-fixed size, the string is serialized as long as it is into the channel.

Note
- The processing made by this szer is thread-safe, but the class is not necessarily because of the serial channels involved, that may be non - thread-safe.
- If you need to serialize a string with its exact length (non-fixed size) but without a final endmark character, use a fixed size Szer_String with a size equal to the size of the string. Obviously, for deserializing such a string you will also need a Szer_String with the same fixed size, since no endmarker will exist.
- It is not defined as template class with the SIZE as parameter, and thus have a slightly more efficient implementation, since then the user should have that size as constexpr, which is not always the case.

Definition at line 426 of file serializers.h.

Inheritance diagram for elementa::base::Szer_String:
Collaboration diagram for elementa::base::Szer_String:

Public Types

using SType = std::string
 To access the Sble type parameter of this type. More...
 
using RDeserType = std::string
 To access the ReturnDeserType type parameter of this type. More...
 
using RSerType = std::string
 To access the ReturnSerType type parameter of this type. More...
 

Public Member Functions

 Szer_String (SerChSize size=0, char c=' ')
 Constructor both for fixed (SIZE>0) and dynamic sized (SIZE==0) strings. More...
 
void ser (OutSerCh &chout, const std::string &s)
 Serialization of a string into CHOUT. More...
 
void deser (InSerCh &chin, std::string &s)
 Deserializes the string from CHIN. More...
 
SerChSize sersize (void) const
 Return the size for which the serializer was created. More...
 

Member Typedef Documentation

◆ SType

using elementa::base::Serializer< std::string , void , void >::SType = std::string
inherited

To access the Sble type parameter of this type.

Definition at line 193 of file serializers.h.

◆ RDeserType

using elementa::base::Serializer< std::string , void , void >::RDeserType = std::string
inherited

To access the ReturnDeserType type parameter of this type.

Definition at line 196 of file serializers.h.

◆ RSerType

using elementa::base::Serializer< std::string , void , void >::RSerType = std::string
inherited

To access the ReturnSerType type parameter of this type.

Definition at line 199 of file serializers.h.

Constructor & Destructor Documentation

◆ Szer_String()

elementa::base::Szer_String::Szer_String ( SerChSize  size = 0,
char  c = ' ' 
)
inline

Constructor both for fixed (SIZE>0) and dynamic sized (SIZE==0) strings.

See the meaning of SIZE and C in ser() and deser() methods.

Definition at line 432 of file serializers.h.

Member Function Documentation

◆ ser()

void elementa::base::Szer_String::ser ( OutSerCh chout,
const std::string &  s 
)
virtual

Serialization of a string into CHOUT.

If the serializer works with fixed size, the serializations will occupy that size always (filling with C if shorter). If the serializer works with dynamic size, the serializations will occupy the size of the serialized string exactly. Only if that string is empty, an endmarker character equal to C is serialized.

Reimplemented from elementa::base::Serializer< std::string >.

Referenced by elementa::adts::graphs::Szer_GraphML< Vertex, Edge >::ser().

◆ deser()

void elementa::base::Szer_String::deser ( InSerCh chin,
std::string &  s 
)
virtual

Deserializes the string from CHIN.

If the deserializer works with fixed size, the object receiving the result will be .resize()-d to that size and then filled with exactly SIZE chars read from CHIN. If the deserializer works with dynamic size, the object receiving the result will be .clear()-ed and then each deserialized char will be .push_back() to it, until the C char is detected (it will not be included in the result).

Reimplemented from elementa::base::Serializer< std::string >.

◆ sersize()

SerChSize elementa::base::Szer_String::sersize ( void  ) const
inline

Return the size for which the serializer was created.

Definition at line 455 of file serializers.h.

◆ elementa::base::Szer_NatBin

class elementa::base::Szer_NatBin
template<typename NatType>
class elementa::base::Szer_NatBin< NatType >

Serializer of natural numbers in fixed or non-fixed size.

This serializer encodes positive numbers or 0 in binary form, as if they were in memory.

For fixed size, the number is serialized occupying the given size, filling with bytes = 0 if needed. For non-fixed size, the number is serialized with the needed length. In that case, the deserializer is not implemented (deserialization can only be done in fixed-size mode).

Note
- The processing made by this szer is thread-safe, but the class is not necessarily because of the serial channels involved, that may be non thread-safe.
- The serialization is done in little endian order, independently on the target machine for which the library is compiled.
- It is not defined as template class with the SIZE as parameter, and thus have a slightly more efficient implementation, since then the user should have that size as constexpr, which is not always the case.

Definition at line 492 of file serializers.h.

Inheritance diagram for elementa::base::Szer_NatBin< NatType >:
Collaboration diagram for elementa::base::Szer_NatBin< NatType >:

Public Types

using SType = NatType
 To access the Sble type parameter of this type. More...
 
using RDeserType = NatType
 To access the ReturnDeserType type parameter of this type. More...
 
using RSerType = NatType
 To access the ReturnSerType type parameter of this type. More...
 

Public Member Functions

 Szer_NatBin (SerChSize size=sizeof(NatType))
 Constructor for fixed size (SIZE > 0) or dynamic size (SIZE == 0). More...
 
void ser (OutSerCh &chout, const NatType &obj)
 Serialization of the object into CHOUT. More...
 
void deser (InSerCh &chin, NatType &obj)
 Deserializes the number from CHIN. More...
 
SerChSize sersize (void) const
 Return the size for which the serializer was created. More...
 

Member Typedef Documentation

◆ SType

using elementa::base::Serializer< NatType , void , void >::SType = NatType
inherited

To access the Sble type parameter of this type.

Definition at line 193 of file serializers.h.

◆ RDeserType

using elementa::base::Serializer< NatType , void , void >::RDeserType = NatType
inherited

To access the ReturnDeserType type parameter of this type.

Definition at line 196 of file serializers.h.

◆ RSerType

using elementa::base::Serializer< NatType , void , void >::RSerType = NatType
inherited

To access the ReturnSerType type parameter of this type.

Definition at line 199 of file serializers.h.

Constructor & Destructor Documentation

◆ Szer_NatBin()

template<typename NatType >
elementa::base::Szer_NatBin< NatType >::Szer_NatBin ( SerChSize  size = sizeof(NatType))
inline

Constructor for fixed size (SIZE > 0) or dynamic size (SIZE == 0).

Definition at line 497 of file serializers.h.

Member Function Documentation

◆ sersize()

template<typename NatType >
SerChSize elementa::base::Szer_NatBin< NatType >::sersize ( void  ) const
inline

Return the size for which the serializer was created.

Definition at line 507 of file serializers.h.

◆ elementa::base::Szer_IntText

class elementa::base::Szer_IntText

Serializer of integer numbers as text in fixed or non-fixed size.

This serializer encodes integers in text form.

For fixed size, the number is serialized occupying the entire size, filling with characters == ' ' if needed. For dynamic size, the number is serialized as long as it is needed. In that case, the deserializer is not implemented (deserialization can only be done in fixed-size mode).

Note
- The processing made by this szer is thread-safe, but the class is not necessarily because of the serial channels involved, that may be non thread-safe.

Definition at line 540 of file serializers.h.

Inheritance diagram for elementa::base::Szer_IntText:
Collaboration diagram for elementa::base::Szer_IntText:

Public Types

using SType = LongestInt
 To access the Sble type parameter of this type. More...
 
using RDeserType = LongestInt
 To access the ReturnDeserType type parameter of this type. More...
 
using RSerType = LongestInt
 To access the ReturnSerType type parameter of this type. More...
 

Public Member Functions

 Szer_IntText (SerChSize size=sizeof(LongestInt))
 Constructor for fixed size (SIZE > 0) or dynamic size (SIZE == 0). More...
 
void ser (OutSerCh &chout, const LongestInt &obj)
 Serialization of the object into CHOUT. More...
 
void deser (InSerCh &chin, LongestInt &obj)
 Deserializes the object from CHIN. More...
 
SerChSize sersize (void) const
 Return the size for which the serializer was created. More...
 

Member Typedef Documentation

◆ SType

using elementa::base::Serializer< LongestInt , void , void >::SType = LongestInt
inherited

To access the Sble type parameter of this type.

Definition at line 193 of file serializers.h.

◆ RDeserType

using elementa::base::Serializer< LongestInt , void , void >::RDeserType = LongestInt
inherited

To access the ReturnDeserType type parameter of this type.

Definition at line 196 of file serializers.h.

◆ RSerType

using elementa::base::Serializer< LongestInt , void , void >::RSerType = LongestInt
inherited

To access the ReturnSerType type parameter of this type.

Definition at line 199 of file serializers.h.

Constructor & Destructor Documentation

◆ Szer_IntText()

elementa::base::Szer_IntText::Szer_IntText ( SerChSize  size = sizeof(LongestInt))
inline

Constructor for fixed size (SIZE > 0) or dynamic size (SIZE == 0).

Definition at line 545 of file serializers.h.

Member Function Documentation

◆ ser()

void elementa::base::Szer_IntText::ser ( OutSerCh chout,
const LongestInt obj 
)
virtual

Serialization of the object into CHOUT.

Reimplemented from elementa::base::Serializer< LongestInt >.

Referenced by elementa::adts::graphs::Szer_GraphCompactText< Vertex, Edge >::ser().

◆ deser()

void elementa::base::Szer_IntText::deser ( InSerCh chin,
LongestInt obj 
)
virtual

Deserializes the object from CHIN.

Reimplemented from elementa::base::Serializer< LongestInt >.

◆ sersize()

SerChSize elementa::base::Szer_IntText::sersize ( void  ) const
inline

Return the size for which the serializer was created.

Definition at line 555 of file serializers.h.

◆ elementa::base::Szer_RealText

class elementa::base::Szer_RealText

Serializer of real numbers as text in fixed or dynamic size.

This serializer encodes reals in text form.

For fixed size, the number is serialized occupying the entire size, filling with characters == ' ' if needed. For dynamic size, the number is serialized as long as it is needed. In that case, the deserializer is not implemented (deserialization can only be done in fixed-size mode).

Note
- The processing made by this szer is thread-safe, but the class is not necessarily because of the serial channels involved, that may be non thread-safe.

Definition at line 582 of file serializers.h.

Inheritance diagram for elementa::base::Szer_RealText:
Collaboration diagram for elementa::base::Szer_RealText:

Public Types

using SType = LongestReal
 To access the Sble type parameter of this type. More...
 
using RDeserType = LongestReal
 To access the ReturnDeserType type parameter of this type. More...
 
using RSerType = LongestReal
 To access the ReturnSerType type parameter of this type. More...
 

Public Member Functions

 Szer_RealText (SerChSize size=sizeof(LongestReal))
 Constructor. More...
 
void ser (OutSerCh &chout, const LongestReal &obj)
 Serialization of the object into CHOUT. More...
 
void deser (InSerCh &chin, LongestReal &obj)
 Deserializes the object from CHIN. More...
 
SerChSize sersize (void) const
 Return the size for which the serializer was created. More...
 

Member Typedef Documentation

◆ SType

using elementa::base::Serializer< LongestReal , void , void >::SType = LongestReal
inherited

To access the Sble type parameter of this type.

Definition at line 193 of file serializers.h.

◆ RDeserType

using elementa::base::Serializer< LongestReal , void , void >::RDeserType = LongestReal
inherited

To access the ReturnDeserType type parameter of this type.

Definition at line 196 of file serializers.h.

◆ RSerType

using elementa::base::Serializer< LongestReal , void , void >::RSerType = LongestReal
inherited

To access the ReturnSerType type parameter of this type.

Definition at line 199 of file serializers.h.

Constructor & Destructor Documentation

◆ Szer_RealText()

elementa::base::Szer_RealText::Szer_RealText ( SerChSize  size = sizeof(LongestReal))
inline

Constructor.

Definition at line 587 of file serializers.h.

Member Function Documentation

◆ ser()

void elementa::base::Szer_RealText::ser ( OutSerCh chout,
const LongestReal obj 
)
virtual

Serialization of the object into CHOUT.

Reimplemented from elementa::base::Serializer< LongestReal >.

◆ deser()

void elementa::base::Szer_RealText::deser ( InSerCh chin,
LongestReal obj 
)
virtual

Deserializes the object from CHIN.

Reimplemented from elementa::base::Serializer< LongestReal >.

◆ sersize()

SerChSize elementa::base::Szer_RealText::sersize ( void  ) const
inline

Return the size for which the serializer was created.

Definition at line 597 of file serializers.h.

◆ elementa::base::Szer_StringToken

class elementa::base::Szer_StringToken

Serializer of a std::string as a token (useful for lexers).

In de-serialization, this class reads the first character from the channel and then read more characters as long as they are of the same type: either separators or non-separators; when a different type of character is found, it pushes it back and ends, changing the object (a string) to the token read.

The only exception to this behavior is when the de-serializer finds the first mark of a multiline or uniline comment (if provided by the user): in that case it reads the entire comment (including enclosed marks) and return that. Comments are not dealt with if their enclosing marks are not provided.

The deserializer returns the type of the token read.

In serialization, it just calls a Szer_String with dynamic size (the one of the string) or does nothing if the string is empty. It does not check whether the string consists only of separators or non-separators or comment marks.

In both cases, this serializer is case-sensitive.

Note
- The deserializer stop deserializing when finding end of channel, without throwing the end-of-channel exception (may return an empty string if nothing have been read).
- The deserializer does not produce any SzerError.

Definition at line 636 of file serializers.h.

Inheritance diagram for elementa::base::Szer_StringToken:
Collaboration diagram for elementa::base::Szer_StringToken:

Public Types

using SType = std::string
 To access the Sble type parameter of this type. More...
 
using RDeserType = std::string
 To access the ReturnDeserType type parameter of this type. More...
 
using RSerType = std::string
 To access the ReturnSerType type parameter of this type. More...
 

Public Member Functions

 ELE_CLASS_ENUM (Type, kSeparators, kNonSeparators, kMultiComment, kUniComment, kNone)
 Types of tokens that can be de-serialized.
 
 Szer_StringToken (const std::string &multilinecomm="/* */", const std::string &unilinecomm="// \n", const std::string &seps="\n\t \f\r\v\x00")
 Constructor associating the szer to some separators. More...
 
void ser (OutSerCh &chout, const std::string &obj)
 Serialization of the object into CHOUT. More...
 
int deser (InSerCh &chin, std::string &obj)
 Deserializes the next token from CHIN. More...
 

Member Typedef Documentation

◆ SType

using elementa::base::Serializer< std::string , int , void >::SType = std::string
inherited

To access the Sble type parameter of this type.

Definition at line 193 of file serializers.h.

◆ RDeserType

using elementa::base::Serializer< std::string , int , void >::RDeserType = std::string
inherited

To access the ReturnDeserType type parameter of this type.

Definition at line 196 of file serializers.h.

◆ RSerType

using elementa::base::Serializer< std::string , int , void >::RSerType = std::string
inherited

To access the ReturnSerType type parameter of this type.

Definition at line 199 of file serializers.h.

Constructor & Destructor Documentation

◆ Szer_StringToken()

elementa::base::Szer_StringToken::Szer_StringToken ( const std::string &  multilinecomm = "/* */",
const std::string &  unilinecomm = "// \n",
const std::string &  seps = "\n\t \f\r\v\x00" 
)

Constructor associating the szer to some separators.

The enclosing marks of a multiline comment are in MULTILINECOMM, separated by a single space -that cannot be part of any enclosing mark-. The same occurs with UNILINECOMM for uniline comments. If any of these parameters is missing or empty, that type of comment is not dealt with.

Member Function Documentation

◆ ser()

void elementa::base::Szer_StringToken::ser ( OutSerCh chout,
const std::string &  obj 
)
virtual

Serialization of the object into CHOUT.

Reimplemented from elementa::base::Serializer< std::string, int >.

◆ deser()

int elementa::base::Szer_StringToken::deser ( InSerCh chin,
std::string &  obj 
)
virtual

Deserializes the next token from CHIN.

Return its type (see enum above) cast into int. Clear OBJ before deserializing.

Reimplemented from elementa::base::Serializer< std::string, int >.

Typedef Documentation

◆ ClassSzer

template<class Sble , class DeserReturnType = void, class SerReturnType = void>
using elementa::base::ClassSzer = typedef ClassSzer_<Sble,DeserReturnType,SerReturnType>

#include <elementa/base/serial_channels/serializers.h>

Objects of this class act as Serializer's for Serializable objects.

An object of this class calls the implicit serialization of a class SBLE that is derived from Serializable through an interface compatible with the one of Serializer.

Notice that, if the serializable class makes some initialization of the serialization process in its constructor, the initialized data that is used here is the one of the OBJ argument.

Definition at line 369 of file serializers.h.

Function Documentation

◆ operator<<()

template<class DeserReturnType , class SerReturnType >
OutSerCh & elementa::base::operator<< ( OutSerCh chout,
const Serializable< DeserReturnType, SerReturnType > &  o 
)

#include <elementa/base/serial_channels/serializers.h>

Operator for serializing Serializable objects directly on a channel.

If the serializable class return anything in serme(), that value is discarded.

Definition at line 277 of file serializers.h.

References elementa::base::Serializable< DeserReturnType, SerReturnType >::serme().

◆ operator>>()

template<class DeserReturnType , class SerReturnType >
InSerCh & elementa::base::operator>> ( InSerCh chin,
Serializable< DeserReturnType, SerReturnType > &  o 
)

#include <elementa/base/serial_channels/serializers.h>

Operator for deserializing Serializable objects directly from a channel.

If the serializable class return anything in deserme(), that value is discarded.

Definition at line 290 of file serializers.h.

References elementa::base::Serializable< DeserReturnType, SerReturnType >::deserme().

◆ ser()

template<typename NatType >
void elementa::base::Szer_NatBin< NatType >::ser ( OutSerCh chout,
const NatType &  obj 
)
virtual

#include <elementa/base/serial_channels/serializers.h>

Serialization of the object into CHOUT.

Reimplemented from elementa::base::Serializer< NatType >.

Definition at line 695 of file serializers.h.

References ELE_CODE_PLACE, and elementa::base::serch_isgood().

◆ deser()

template<typename NatType >
void elementa::base::Szer_NatBin< NatType >::deser ( InSerCh chin,
NatType &  obj 
)
virtual

#include <elementa/base/serial_channels/serializers.h>

Deserializes the number from CHIN.

Reimplemented from elementa::base::Serializer< NatType >.

Definition at line 722 of file serializers.h.

References elementa::base::Exc::asEXC(), ELE_CODE_PLACE, and elementa::base::serch_isexhausted().