Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Static Public Member Functions | Private Types | Static Private Member Functions | List of all members
Codable Class Reference

Provides helpers for serialization/deserialization of basic types. More...

#include <Codable.hpp>

Static Public Member Functions

static bool decodeBool (const KeyValues &param, unsigned int position=0)
 
static std::string encode (bool b)
 
static glm::vec2 decodeVec2 (const KeyValues &param, unsigned int position=0)
 
static std::vector< std::string > encode (const glm::vec2 &v)
 
static glm::vec3 decodeVec3 (const KeyValues &param, unsigned int position=0)
 
static std::vector< std::string > encode (const glm::vec3 &v)
 
static glm::vec4 decodeVec4 (const KeyValues &param, unsigned int position=0)
 
static std::vector< std::string > encode (const glm::vec4 &v)
 
static glm::mat4 decodeTransformation (const std::vector< KeyValues > &params)
 
static std::vector< KeyValuesencode (const glm::mat4 &transfo)
 
static std::pair< std::string, LayoutdecodeTexture (const KeyValues &param)
 
static KeyValues encode (const Texture *texture)
 
static std::vector< KeyValuesdecode (const std::string &codableFile)
 
static std::string encode (const std::vector< KeyValues > &params)
 
static std::string encode (const KeyValues &params)
 
static void unknown (const KeyValues &params)
 

Private Types

enum class  Prefix : uint { ROOT , LIST , NONE }
 Prefix type/. More...
 

Static Private Member Functions

static std::string encode (const std::vector< KeyValues > &params, Prefix prefix, uint level)
 

Detailed Description

Provides helpers for serialization/deserialization of basic types.

Member Enumeration Documentation

◆ Prefix

enum class Codable::Prefix : uint
strongprivate

Prefix type/.

Enumerator
ROOT 

"*" prefix.

LIST 

"-" prefix.

NONE 

No prefix.

Member Function Documentation

◆ decode()

std::vector< KeyValues > Codable::decode ( const std::string &  codableFile)
static

Split a Codable-compatible text file in a hierarchical list of (key,values) tuples, getting rid of extraneous spaces and punctuations. The following rules are applied:

  • elements beginning with a '*' denote root-level objects.
  • elements beginning with a '-' belong to an array, defined by the element just before those.
  • elements can be nested on the same line: 'elem1: elem2: values'
    Parameters
    codableFilethe text content to parse
    Returns
    a hierarchical list of (key, value) tokens

◆ decodeBool()

bool Codable::decodeBool ( const KeyValues param,
unsigned int  position = 0 
)
static

Decode a boolean from a parameters tuple, at a specified position. A boolean is set to true if its value is 'true', 'True', 'yes', 'Yes' or '1'.

Parameters
paramthe parameters tuple
positionindex of the boolean in the values array
Returns
a boolean

◆ decodeTexture()

std::pair< std::string, Layout > Codable::decodeTexture ( const KeyValues param)
static

Decode a texture from a parameters tuple and load it. A texture is described as follows:

texturetype: texturename

(where texturetype can be one of 'rgb', 'srgb', 'rgb32', 'rgbcube', 'srgbcube', 'rgb32cube' depending on the desired format).

Parameters
paramthe parameters tuple
Returns
the name of the texture and its format.

◆ decodeTransformation()

glm::mat4 Codable::decodeTransformation ( const std::vector< KeyValues > &  params)
static

Decode a transformation from a series of parameters tuple. For now this function look for three keywords in the whole params vector: translation, orientation, scaling. A transformation is described as follows:

translation: X,Y,Z
orientation: axisX,axisY,axisZ angle
scaling: scale
Parameters
paramsa list of parameters tuples
Returns
the 4x4 matrix representation of the transformation

◆ decodeVec2()

glm::vec2 Codable::decodeVec2 ( const KeyValues param,
unsigned int  position = 0 
)
static

Decode a 2D vector from a parameters tuple, starting at a specified position. A 2D vector is described as a set of 2 floats separated by spaces or commas: X,Y.

Parameters
paramthe parameters tuple
positionindex of the first vector component in the values array
Returns
a 2D vector

◆ decodeVec3()

glm::vec3 Codable::decodeVec3 ( const KeyValues param,
unsigned int  position = 0 
)
static

Decode a 3D vector from a parameters tuple, starting at a specified position. A 3D vector is described as a set of 3 floats separated by spaces or commas: X,Y,Z.

Parameters
paramthe parameters tuple
positionindex of the first vector component in the values array
Returns
a 3D vector

◆ decodeVec4()

glm::vec4 Codable::decodeVec4 ( const KeyValues param,
unsigned int  position = 0 
)
static

Decode a 4D vector from a parameters tuple, starting at a specified position. A 4D vector is described as a set of 4 floats separated by spaces or commas: X,Y,Z,W.

Parameters
paramthe parameters tuple
positionindex of the first vector component in the values array
Returns
a 4D vector

◆ encode() [1/9]

std::string Codable::encode ( bool  b)
static

Encode a boolean into a string ("true" or "false")

Parameters
bthe boolean value to encode
Returns
the string representation

◆ encode() [2/9]

std::vector< KeyValues > Codable::encode ( const glm::mat4 &  transfo)
static

Encode a rotation/scaling/orientation transformation matrix into a set of parameters.

Parameters
transfothe transformation to encode
Returns
a list of 3 Codable-comaptible parameters

◆ encode() [3/9]

std::vector< std::string > Codable::encode ( const glm::vec2 &  v)
static

Encode a 2D vector into a vector of strings {"X","Y"}

Parameters
vthe vector to encode
Returns
the vector of strings representation

◆ encode() [4/9]

std::vector< std::string > Codable::encode ( const glm::vec3 &  v)
static

Encode a 3D vector into a vector of strings {"X","Y","Z"}

Parameters
vthe vector to encode
Returns
the vector of strings representation

◆ encode() [5/9]

std::vector< std::string > Codable::encode ( const glm::vec4 &  v)
static

Encode a 4D vector into a vector of strings {"X","Y","Z","W"}

Parameters
vthe vector to encode
Returns
the vector of strings representation

◆ encode() [6/9]

std::string Codable::encode ( const KeyValues params)
static

Generate a Codable-compatible text representation from a (key,values) tuple.

Parameters
paramsa (key, value) token
Returns
a string containing the text representation

◆ encode() [7/9]

std::string Codable::encode ( const std::vector< KeyValues > &  params)
static

Generate a Codable-compatible text representation from a hierarchical list of (key,values) tuples. The following rules are applied:

  • elements beginning with a '*' denote root-level objects.
  • elements beginning with a '-' belong to an array, defined by the element just before those.
    Parameters
    paramsa hierarchical list of (key, value) tokens
    Returns
    a string containing the text representation

◆ encode() [8/9]

std::string Codable::encode ( const std::vector< KeyValues > &  params,
Prefix  prefix,
uint  level 
)
staticprivate

Generate a Codable-compatible text representation from a hierarchical list of (key,values) tuples.

Parameters
paramsa hierarchical list of (key, value) tokens
prefixthe type of prefix character to use (
See also
Prefix)
Parameters
levelthe indentation level (using tabulations)
Returns
a string containing the text represenation

◆ encode() [9/9]

KeyValues Codable::encode ( const Texture texture)
static

Encode a texture into a Codable-compliant tuple.

Parameters
texturethe texture to encode
Returns
the tuple representation

◆ unknown()

void Codable::unknown ( const KeyValues params)
static

Log an unknown parameter set

Parameters
paramsthe token to log

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