TailorMade 2.0
Tailor Made is a high-performance C++20 ECS library with on-the-fly entity creation and JSON-based definitions for entities, components, and their relationships.
 
Loading...
Searching...
No Matches
TM_Tools.h File Reference

Project TailorMade. More...

#include <variant>
#include <json.hpp>
#include <vector>
#include <unordered_map>
#include <mutex>
#include <fstream>
#include <iostream>
#include <string>
#include <filesystem>
#include <sstream>
#include <cctype>

Go to the source code of this file.

Classes

struct  Vector2
 Vector2 structure and operators. More...
 
struct  Vector3
 Vector3 structure and operators. More...
 

Macros

#define ECS_Types   int, float, std::string, bool, Vector2, Vector3
 Definitions of the types in TailorMade.
 

Typedefs

typedef struct Vector2 Vector2
 Vector2 structure and operators.
 
typedef struct Vector3 Vector3
 Vector3 structure and operators.
 
using dataUnMap = std::unordered_map<std::string, std::pair<std::string, std::variant<ECS_Types>>>
 Map of dataName -> {dataType, value}.
 
using dataVector = std::vector<std::pair<std::string, std::variant<ECS_Types>>>
 Vector of {dataType, value}.
 

Functions

std::ostream & operator<< (std::ostream &os, const Vector2 &v)
 Print a Vector2.
 
std::ostream & operator<< (std::ostream &os, const Vector3 &v)
 Print a Vector3.
 
std::variant< ECS_TypesstrToType (std::string type)
 Return a variant<ECS_Types> with the default value of the given type.
 
std::variant< ECS_TypesvalueToType (const nlohmann::json &value, std::string type)
 Return a variant<ECS_Types> with the given value of the given type.
 
nlohmann::ordered_json serializeType (const dataUnMap &data)
 Serialize the data in an ordered_json.
 
void valueToStream (std::ostream &stream, std::variant< ECS_Types > value)
 Will append in the given stream, the serialized version of the given variant value.
 
std::vector< std::string > getAllFilesFromDirectory (const std::string &directory)
 Return every files from the given directory, includes all subfolders.
 

Detailed Description

Project TailorMade.

Author
Thomas K/BIDI
Version
2.0

Macro Definition Documentation

◆ ECS_Types

#define ECS_Types   int, float, std::string, bool, Vector2, Vector3

Definitions of the types in TailorMade.

Typedef Documentation

◆ dataUnMap

using dataUnMap = std::unordered_map<std::string, std::pair<std::string, std::variant<ECS_Types>>>

Map of dataName -> {dataType, value}.

◆ dataVector

using dataVector = std::vector<std::pair<std::string, std::variant<ECS_Types>>>

Vector of {dataType, value}.

◆ Vector2

typedef struct Vector2 Vector2

Vector2 structure and operators.

◆ Vector3

typedef struct Vector3 Vector3

Vector3 structure and operators.

Function Documentation

◆ getAllFilesFromDirectory()

std::vector< std::string > getAllFilesFromDirectory ( const std::string & directory)
inline

Return every files from the given directory, includes all subfolders.

Parameters
directoryThe directory in which the research starts.

◆ operator<<() [1/2]

std::ostream & operator<< ( std::ostream & os,
const Vector2 & v )
inline

Print a Vector2.

◆ operator<<() [2/2]

std::ostream & operator<< ( std::ostream & os,
const Vector3 & v )
inline

Print a Vector3.

◆ serializeType()

nlohmann::ordered_json serializeType ( const dataUnMap & data)
inline

Serialize the data in an ordered_json.

See also
dataUnMap
Parameters
dataThe unordered_map with the data from a component in it.

◆ strToType()

std::variant< ECS_Types > strToType ( std::string type)
inline

Return a variant<ECS_Types> with the default value of the given type.

You can give a string of one of the supported types of TailorMade and it will return the associated variant with its default value.

Warning
If the type is unknown an error is thrown. You can checked the currently available types of this version on the project's github page.
Parameters
typeThe string version of the desired type. (e.g.: "Integer")

◆ valueToStream()

void valueToStream ( std::ostream & stream,
std::variant< ECS_Types > value )
inline

Will append in the given stream, the serialized version of the given variant value.

Parameters
streamThe stream on which the value should be append.
valueThe variant you want to serialize and append to the stream.

◆ valueToType()

std::variant< ECS_Types > valueToType ( const nlohmann::json & value,
std::string type )
inline

Return a variant<ECS_Types> with the given value of the given type.

Works the same way as TM_Tools::strToType but with the given value.

Warning
If the type is unknown an error is thrown. You can checked the currently available types of this version on the project's github page.
Parameters
valueA JSON object with the desired value in it.
typeThe string version of the desired type. (e.g.: "Integer")