TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Core Namespace Reference

Contains core functionality for each component of the API. More...

Namespaces

 Debug
 Contains some functionality for creating a debug log, and in some cases (Windows) popping open a console window.
 
 Error
 Contains defines and functionality for protecting the framework and your project from disaster.
 
 Version
 Contains functionality for retrieving and comparing the version of the TurtleBrains framework.
 

Classes

class  Component
 
class  DynamicStructure
 
class  FixedString
 
class  Formatter
 
class  HybridOwnedPointer
 
class  Node
 
class  Noncopyable
 
class  ResourceCache
 
class  ResourceHandle
 
struct  TypedInteger
 
struct  TypedRange
 
struct  DynamicTypedRange
 
struct  OtherTypedRange
 
class  size
 
class  size32
 
class  size64
 
class  TypedUUID
 

Typedefs

using ScopedDebugInfo = Debug::ScopedDebugInfo
 
typedef TypedUUID< Implementation::ComponentKeyType > ComponentKey
 
typedef TypedUUID< Implementation::ComponentTypeKeyType > ComponentTypeKey
 
typedef std::unique_ptr< ComponentComponentPointer
 
typedef std::function< ComponentPointer(Node &, const ComponentKey &)> CreateComponentFunction
 
using NodeKey = TypedUUID< NodeKeyType >
 
using NodePointer = std::unique_ptr< Node >
 
typedef std::string String
 
using tbString = String
 
using int8 = std::int8_t
 Signed integer with a size of 8 bits. Supports values from -128 to 127.
 
using uint8 = std::uint8_t
 Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
 
using byte = std::uint8_t
 Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
 
using int16 = std::int16_t
 Signed integer with a size of 16 bits. Supports values from -32768 to 32767.
 
using uint16 = std::uint16_t
 Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
 
using int32 = std::int32_t
 Signed integer with a size of 32 bits. Supports values from -2147483648 to 2147483647.
 
using uint32 = std::uint32_t
 Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1).
 
using int64 = std::int64_t
 Signed integer with a size of 64 bits. Supports values from -(2^63) to (2^63 - 1).
 
using uint64 = std::uint64_t
 Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
 
using InputFile = std::istream
 
using OutputFile = std::ostream
 
using uuid = TypedUUID< DefaultKeyType >
 

Enumerations

enum class  Space { Local , World }
 
enum class  Recursive { No , Yes }
 
enum class  NodeKeyType
 
enum class  DefaultKeyType
 

Functions

DynamicStructure ParseCsv (const String &csvData, const String &debugID="")
 
DynamicStructure LoadCsvFile (const String &filepath)
 
bool SaveCsvFile (const String &filepath, const DynamicStructure &saveData)
 
template<typename Type >
void SafeDelete (Type *&objectPointer)
 
template<typename Type >
void SafeDeleteArray (Type *&arrayPointer)
 
template<typename ReturnType , typename InitialType >
ReturnType RangedCast (const InitialType &value)
 
template<typename ReturnType , typename InitialType >
ReturnType ClampedCast (const InitialType &value, const ReturnType &minimum, const ReturnType &maximum)
 
String ToJsonString (const tbCore::DynamicStructure &data, bool prettyJson)
 
template<size_t Size>
std::ostream & operator<< (std::ostream &outputStream, const FixedString< Size > &fixed)
 
template<size_t Size>
std::istream & operator<< (std::istream &inputStream, FixedString< Size > &fixed)
 
template<size_t Size>
bool operator== (const char *left, const FixedString< Size > &right)
 
template<size_t Size>
bool operator== (const String &left, const FixedString< Size > &right)
 
template<size_t Size>
bool operator!= (const char *left, const FixedString< Size > &right)
 
template<size_t Size>
bool operator!= (const String &left, const FixedString< Size > &right)
 
String EscapeJsonString (const String &input)
 
DynamicStructure ParseJson (const String &jsonData)
 
DynamicStructure LoadJsonFile (const String &filepath)
 
bool SaveJsonFile (const String &filepath, const DynamicStructure &saveData, bool prettyJson=true)
 
String GetPathFromFilepath (const String &filepath)
 
String GetChildFilepath (const String &parentFilename, const String &childFilename)
 
const NodePointer & GetRootNode (void)
 
NodePointer & GetMutableRootNode (void)
 
void SetRootNode (NodePointer &&rootNode)
 
template<typename Type >
std::string ToStdString (const Type &object)
 
std::string ToStdString (const std::string &object)
 
std::string ToStdString (const std::wstring &object)
 
std::string ToStdString (const wchar_t *object)
 
std::string ToStdString (float value, int precision=-1)
 
std::string ToStdString (double value, int precision=-1)
 
template<typename Type >
Type FromStdString (const std::string &input)
 
template<typename Type >
std::wstring ToWideString (const Type &object)
 
std::wstring ToWideString (const std::wstring &object)
 
std::wstring ToWideString (const std::string &object)
 
std::wstring ToWideString (const char *object)
 
std::wstring ToWideString (float value, int precision=-1)
 
std::wstring ToWideString (double value, int precision=-1)
 
template<typename Type >
Type FromWideString (const std::wstring &input)
 
template<typename Type >
String ToString (const Type &object)
 
String ToString (float value, int precision=-1)
 
String ToString (double value, int precision=-1)
 
template<typename Type >
Type FromString (const std::string &input)
 
template<typename Type >
Type FromString (const std::wstring &input)
 
template<typename MapContainerType >
Internals::ValuesOfAccessor< MapContainerType > ValuesOf (MapContainerType &container)
 
DynamicStructure ParseYaml (const String &yamlData)
 
DynamicStructure LoadYamlFile (const String &filepath)
 

Detailed Description

Most contents in the Core namespace will be required for other portions of the TurtleBrains framework. Core contains types like tbString which are used widely through the framework, and small helper classes/objects to create the small and common building blocks to the TurtleBrains framework and handle errors or configurations.

Typedef Documentation

◆ String

typedef std::string TurtleBrains::Core::String

The String is a type definition of either wide-string (std::wstring) when tb_with_wide_string is defined or std::string when tb_with_wide_string is not defined. This effects how TurtleBrains strings are held and passed The tb_with_wide_string can be defined in tb_configuration.h if wide-strings are preferred.

Note
For maximum portability, when using strings returned from TurtleBrains you should not assume the String is defined as STD or WIDE and instead always convert it back to what you are expecting. While this may add a small performance overhead, it will allow you to sleep at night knowing if you decide to change from STD to WIDE strings, everything will work splendidly. Alternatively, storing all your own strings as String will also allow for the same peace of mind.
Examples
/home/timbeaudet/development/tyre_bytes/turtle_brains/source/turtle_brains/core/tb_resource_cache.hpp.

Function Documentation

◆ ClampedCast()

template<typename ReturnType , typename InitialType >
ReturnType TurtleBrains::Core::ClampedCast ( const InitialType &  value,
const ReturnType &  minimum,
const ReturnType &  maximum 
)

First range cast to ensure the value it fits within the range (min/max) of the return type. Then clamp that value to the specified minimum and maximum provded. This will trigger an error condition if the initial value does not fit in the return type; at runtime.

Parameters
valueThe value to test to check if within range of ReturnType, then gets returned as a ReturnType.
minimumThe lowest value to return from this function.
maximumThe highest value to return from the function.
Note
This triggers runtime error conditions if the value does not fit into the ReturnType based on min/max.

◆ FromStdString()

template<typename Type >
Type TurtleBrains::Core::FromStdString ( const std::string &  input)

Convert a std::string into some type of an object, specified by type T, using the operator>>(istream) which must exist in for the type specified by T as must a default constructor. For best portability and reducing non-wide to wide string conversions, using the function FromString() should be used instead.

Parameters
inputThe string that will be used to create an object.
Returns
the object of type T with the value setup/converted from a std::string using the operator>>(istream).
Note
If the object type, T, does not have an operator>>(istream) or default constructor the compiler will almost certainly complain.

◆ FromString() [1/2]

template<typename Type >
Type TurtleBrains::Core::FromString ( const std::string &  input)

Convert a std::string into some type of an object, specified by type T, using the operator>>(istream) which must exist in for the type specified by T as must a default constructor.

Parameters
inputThe string that will be used to create an object.
Returns
the object of type T with the value setup/converted from a std::string using the operator>>(istream).
Note
This is in global space to allow a Game project to specialize ToString on their own types.
If the object type, T, does not have an operator>>(istream) or default constructor the compiler will almost certainly complain.

◆ FromString() [2/2]

template<typename Type >
Type TurtleBrains::Core::FromString ( const std::wstring &  input)

Convert a std::wstring into some type of an object, specified by type T, using operator>>(wistream) which must exist in for the type specified by T as must a default constructor.

Parameters
inputThe wide-string that will be used to create an object of type T
Returns
the object of type T with the value setup/converted from a std::wstring using the operator>>(wistream).
Note
This is in global space to allow a Game project to specialize ToString on their own types.
If the object type, T, does not have an operator>>(wistream) or default constructor the compiler will almost certainly complain.

◆ FromWideString()

template<typename Type >
Type TurtleBrains::Core::FromWideString ( const std::wstring &  input)

Convert a std::wstring into some type of an object, specified by type T, using operator>>(wistream) which must exist in for the type specified by T as must a default constructor. For best portability and reducing non-wide to wide string conversions, using the function FromString() should be used instead.

Parameters
inputThe wide-string that will be used to create an object of type T
Returns
the object of type T with the value setup/converted from a std::wstring using the operator>>(wistream).
Note
If the object type, T, does not have an operator>>(wistream) or default constructor the compiler will almost certainly complain.

◆ GetChildFilepath()

String TurtleBrains::Core::GetChildFilepath ( const String parentFilename,
const String childFilename 
)

TODO: TIM: This belongs in some form of Utilities / FileSystem thing?

Attempts to find the location of a file based on a parent file for containing filepaths within another file. Ex. A level file format containing textures, sounds or other assets. The texture/sound or other asset would be the child file, and the level being the parent file. This will first check if the childFilename is already existing as is, as a file and if it does, returns that path. If it doesn't the parentFilename will be broken down to a directory path (where the level file exists) and the childFilename appended to create a second attempt to see if that file exists, returning the path if it did. If both fail, an empty string is returned.

Parameters
parentFilenameThe path and filename of the parent file that contains the child file, the Level file as described in the example above.
childFilenameThe path to or filename of the child file that was contained in the parent file, the Asset file as described in the example above.

◆ GetPathFromFilepath()

String TurtleBrains::Core::GetPathFromFilepath ( const String filepath)

TODO: TIM: This belongs in some form of Utilities / FileSystem thing?

Returns the directory path to the given file without the filename, "data/art/castle.png" would become "data/art/" on return.

◆ LoadCsvFile()

DynamicStructure TurtleBrains::Core::LoadCsvFile ( const String filepath)

TODO: TIM: This may become an "Extensions" or such that takes csv to create a DynamicStructure.

Loads all the contents of the file specified by filepath into a string object and passes it into ParseCsv returning the resulting DynamicStructure. If the file was not loaded or memory for the string could not be allocated an error condition will be triggered.

Note
The first row MUST contain the headers for each column, this is required to create the members of row in the DynamicStructure.
Header fields cannot contain quotes or new-lines and must exist on the FIRST line.

◆ LoadJsonFile()

DynamicStructure TurtleBrains::Core::LoadJsonFile ( const String filepath)

TODO: TIM: This may become an "Extensions" or such that takes json to create a DynamicStructure.

Loads all the contents of the file specified by filepath into a string object and passes it into ParseJson returning the resulting DynamicStructure. If the file was not loaded or memory for the string could not be allocated an error condition will be triggered.

◆ LoadYamlFile()

DynamicStructure TurtleBrains::Core::LoadYamlFile ( const String filepath)

TODO: TIM: This may become an "Extensions" or such that takes json to create a DynamicStructure.

Loads all the contents of the file specified by filepath into a string object and passes it into ParseYaml returning the resulting DynamicStructure. If the file was not loaded or memory for the string could not be allocated an error condition will be triggered.

◆ ParseCsv()

DynamicStructure TurtleBrains::Core::ParseCsv ( const String csvData,
const String debugID = "" 
)

TODO: TIM: This may become an "Extensions" or such that takes csv to create a DynamicStructure.

Parses a string in the CSV format, although it may be a super basic subset of the CSV format. This function is not yet thoroughly tested for more complicated CSV features, like escaped-strings with commas, quotes, CR LF etc.

Note
The first row MUST contain the headers for each column, this is required to create the members of row in the DynamicStructure.
Header fields cannot contain quotes or new-lines and must exist on the FIRST line.

◆ ParseJson()

DynamicStructure TurtleBrains::Core::ParseJson ( const String jsonData)

TODO: TIM: This may become an "Extensions" or such that takes json to create a DynamicStructure.

Parses a string with the "SuperEasyJSON" parser written by Jeff Weinstein and then converted into a DynamicStructure. This is not the most memory efficient way to parse json, but most tables will likely be loaded then destroyed after processing so the memory footprint should be temporary. Will return a DynamicStructure of type Nil if any errors occurred such as invalid json data.

◆ ParseYaml()

DynamicStructure TurtleBrains::Core::ParseYaml ( const String yamlData)

TODO: TIM: This may become an "Extensions" or such that takes yaml to create a DynamicStructure.

Parses a string in the YAML format, although it may be a super basic subset of the YAML format. This function was written to collect data from the iRacing SDK in TelemetryBuddy and not thoroughly tested for more complicated YAML features/strings.

◆ RangedCast()

template<typename ReturnType , typename InitialType >
ReturnType TurtleBrains::Core::RangedCast ( const InitialType &  value)

Ensures the value fits within the range (min/max) of the return type. This will trigger an error condition if the types are mismatched; at runtime.

Parameters
valueThe value to test to check if within range of ReturnType, then gets returned as a ReturnType.
Note
This triggers runtime error conditions if the value does not fit into the ReturnType based on min/max.

◆ SafeDelete()

template<typename Type >
void TurtleBrains::Core::SafeDelete ( Type *&  objectPointer)

Checks the objectPointer and deletes it setting it to nullptr, this will only work for objects that were dynamically allocated using new.

◆ SafeDeleteArray()

template<typename Type >
void TurtleBrains::Core::SafeDeleteArray ( Type *&  arrayPointer)

Checks the objectPointer and deletes it setting it to nullptr, this will only work for object arrays that were dynamically allocated using new [].

◆ SaveCsvFile()

bool TurtleBrains::Core::SaveCsvFile ( const String filepath,
const DynamicStructure saveData 
)

TODO: TurtleBrains: Documentation: This needs to teach user how to use.

◆ SaveJsonFile()

bool TurtleBrains::Core::SaveJsonFile ( const String filepath,
const DynamicStructure saveData,
bool  prettyJson = true 
)

TODO: TurtleBrains: Documentation: This needs to teach user how to use.

◆ ToJsonString()

String TurtleBrains::Core::ToJsonString ( const tbCore::DynamicStructure data,
bool  prettyJson 
)

TODO: TurtleBrains: Documentation: This needs to teach user how to use.

◆ ToStdString() [1/5]

std::string TurtleBrains::Core::ToStdString ( const std::string &  object)
inline

This is a specialization of the template function above, if the type specified by T is already a std::string, simply return a value of that string without needing conversion.

Parameters
objectThe string to return
Returns
a value of the string represented by object.

◆ ToStdString() [2/5]

std::string TurtleBrains::Core::ToStdString ( const std::wstring &  object)
inline

This is a specialization of the template function ToStdString, if the type specified by T is a wide-string (std::wstring), attempt to convert the characters into a std::string the best way possible to retain as much of the initial string as possible, replacing unknown or unsupported characters with a question mark '?' character.

Parameters
objectThe wide-string to covert into a std::string

◆ ToStdString() [3/5]

template<typename Type >
std::string TurtleBrains::Core::ToStdString ( const Type &  object)

Convert some type of an object into a std::string using the operator<<(ostream) which must exist in for the type specified by T.

Parameters
objectThe object to convert into a string, typically a basic-type, (int, float, bool), but any type with a defined operator<<(ostream) will work.
Returns
the object transformed into a std::string.
Note
If the object type, T, does not have an operator<<(ostream) the compiler will likely complain.

◆ ToStdString() [4/5]

std::string TurtleBrains::Core::ToStdString ( const wchar_t *  object)
inline

This is a specialization of the template function ToStdString, if the type specified by T is a c-style string of wchar's, attempt to convert the characters into a std::string by first converting it into a wide-string and reusing the ToStdString(const std::wstring&) code.

Parameters
objectThe c-style wide-string to covert into a std::string.

◆ ToStdString() [5/5]

std::string TurtleBrains::Core::ToStdString ( float  value,
int  precision = -1 
)
inline

This is a specialization of the template function ToWideString to provide specific precision values when dealing with floating point numbers, so ToWideString(value, 3) would print out: value to the third decimal point like: 52.123

Parameters
valueThe floating point value that will be converted into a std::string.
precisionHow many points AFTER the decimal point should be displayed, defaults to -1 which means use the defaults of stringstream.

◆ ToString() [1/3]

template<typename Type >
String TurtleBrains::Core::ToString ( const Type &  object)

Easily convert to the string type defined by String, which is either std::string or std::wstring depending on the tb_with_wide_string definition. By using this to convert when passing string parameters into the TurtleBrains framework you can sleep well knowing it will be converted and held safely regardless of the tb_with_wide_string definition and the string type passed. Even objects with both operator<<(ostream) and operator<<(wostream) can be converted into a String using ToString().

Note
This is in global space to allow a Game project to specialize ToString on their own types.
Non-string objects like basic primitives and even custom types can be converted to a String using ToString but will need to have both operator<<(ostream) and operator<<(wostream) defined and implemented to perform the conversion properly, including when tb_with_wide_string is defined.

◆ ToString() [2/3]

String TurtleBrains::Core::ToString ( double  value,
int  precision = -1 
)
inline

Easily convert to the string type defined by String, which is either std::string or std::wstring depending on the tb_with_wide_string definition. By using this to convert when passing string parameters into the TurtleBrains framework you can sleep well knowing it will be converted and held safely regardless of the tb_with_wide_string definition and the string type passed. Even objects with both operator<<(ostream) and operator<<(wostream) can be converted into a String using ToString().

Note
This is in global space to allow a Game project to specialize ToString on their own types.
Non-string objects like basic primitives and even custom types can be converted to a String using ToString but will need to have both operator<<(ostream) and operator<<(wostream) defined and implemented to perform the conversion properly, including when tb_with_wide_string is defined.
Parameters
valueThe floating point value to convert into a string.
precisionHow much precision to display, -1 is the default.

◆ ToString() [3/3]

String TurtleBrains::Core::ToString ( float  value,
int  precision = -1 
)
inline

Easily convert to the string type defined by String, which is either std::string or std::wstring depending on the tb_with_wide_string definition. By using this to convert when passing string parameters into the TurtleBrains framework you can sleep well knowing it will be converted and held safely regardless of the tb_with_wide_string definition and the string type passed. Even objects with both operator<<(ostream) and operator<<(wostream) can be converted into a String using ToString().

Note
This is in global space to allow a Game project to specialize ToString on their own types.
Non-string objects like basic primitives and even custom types can be converted to a String using ToString but will need to have both operator<<(ostream) and operator<<(wostream) defined and implemented to perform the conversion properly, including when tb_with_wide_string is defined.
Parameters
valueThe floating point value to convert into a string.
precisionHow much precision to display, -1 is the default.

◆ ToWideString() [1/5]

std::wstring TurtleBrains::Core::ToWideString ( const char *  object)
inline

This is a specialization of the template function ToWideString, if the type specified by T is a c-style string of char's, attempt to convert the characters into a std::wstring by first converting it into a std::string and reusing the ToWideString(const std::string&) code.

Parameters
objectThe c-style string to convert into a std::string.

◆ ToWideString() [2/5]

std::wstring TurtleBrains::Core::ToWideString ( const std::string &  object)
inline

This is a specialization of the template function ToWideString, if the type specified by T is a std::string, attempt to convert the characters into a std::wstring the best way possible by widening each character to retain the same initial string in widened format.

Parameters
objectThe string to covert into a wide string, (std::wstring)

◆ ToWideString() [3/5]

std::wstring TurtleBrains::Core::ToWideString ( const std::wstring &  object)
inline

This is a specialization of the template function ToWideString, if the type specified by T is already a std::wstring, simply return a value of that string without needing conversion.

Parameters
objectThe wide-string to return
Returns
a value of the wide-string represented by object.

◆ ToWideString() [4/5]

template<typename Type >
std::wstring TurtleBrains::Core::ToWideString ( const Type &  object)

Convert some type of an object into a std::wstring using the operator<<(wostream) which must exist in for the type specified by T.

Parameters
objectThe object to convert into a wide-string, typically a basic-type, (int, float, bool), but any type with a defined operator<<(wostream) will work.
Returns
the object transformed into a std::wstring.
Note
If the object type, T, does not have an operator<<(wostream) the compiler will likely complain.

◆ ToWideString() [5/5]

std::wstring TurtleBrains::Core::ToWideString ( float  value,
int  precision = -1 
)
inline

This is a specialization of the template function ToWideString to provide specific precision values when dealing with floating point numbers, so ToWideString(value, 3) would print out: value to the third decimal point like: 52.123

Parameters
valueThe floating point value that will be converted into a wide string.
precisionHow many points AFTER the decimal point should be displayed, defaults to -1 which means use the defaults of stringstream.

◆ ValuesOf()

template<typename MapContainerType >
Internals::ValuesOfAccessor<MapContainerType> TurtleBrains::Core::ValuesOf ( MapContainerType &  container)

This is an attempt to have a "nicer" range-base loop over maps/unordered_maps etc where we can ignore the Key, so range-based loop over the values in the map.

Given a map: map<Key, Value> myMap; Access like: for (Value& : ValuesOf(myMap)) { ... } Access like: for (const Value& : ValuesOf(myMap)) { ... }