TurtleBrains  0.2.1
High quality, portable, C++ API for native application and game development.
TurtleBrains::Core Namespace Reference

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

Namespaces

 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  DynamicStructure
 
class  Noncopyable
 
class  RuntimeConstant
 

Typedefs

typedef std::string tbString
 
typedef int8_t int8
 Signed integer with a size of 8 bits. Supports values from -128 to 127.
 
typedef uint8_t uint8
 Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
 
typedef int16_t int16
 Signed integer with a size of 16 bits. Supports values from -32768 to 32767.
 
typedef uint16_t uint16
 Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
 
typedef int32_t int32
 Signed integer with a size of 32 bits. Supports values from -2147483648 to 2147483647.
 
typedef uint32_t uint32
 Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1).
 
typedef int64_t int64
 Signed integer with a size of 64 bits. Supports values from -(2^63) to (2^63 - 1).
 
typedef uint64_t uint64
 Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
 

Functions

DynamicStructure ParseJson (const tbCore::tbString &jsonData)
 
DynamicStructure LoadJsonFile (const tbCore::tbString &filepath)
 
tbCore::tbString GetPathFromFilepath (const tbCore::tbString &filepath)
 
tbCore::tbString GetChildFilepath (const tbCore::tbString &parentFilename, const tbCore::tbString &childFilename)
 
template<typename T >
std::string ToStdString (const T &object)
 
std::string ToStdString (const std::string &object)
 
std::string ToStdString (const std::wstring &object)
 
std::string ToStdString (const wchar_t *object)
 
template<typename T >
FromStdString (const std::string &input)
 
template<typename T >
FromString (const std::string &input)
 
template<typename T >
std::wstring ToWideString (const T &object)
 
std::wstring ToWideString (const std::wstring &object)
 
std::wstring ToWideString (const std::string &object)
 
std::wstring ToWideString (const char *object)
 
template<typename T >
FromWideString (const std::wstring &input)
 
template<typename T >
FromString (const std::wstring &input)
 
template<typename T >
tbString ToString (const T &object)
 

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

typedef std::string TurtleBrains::Core::tbString

The tbString is a type definition of either wide-string (std::wstring) when tb_wide_string is defined or std::string when tb_wide_string is not defined. This effects how TurtleBrains strings are held and passed The tb_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 tbString 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 tbString will also allow for the same peace of mind.

Function Documentation

template<typename T >
T 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.
template<typename T >
T 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
If the object type, T, does not have an operator>>(istream) or default constructor the compiler will almost certainly complain.
template<typename T >
T 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
If the object type, T, does not have an operator>>(wistream) or default constructor the compiler will almost certainly complain.
template<typename T >
T 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.
tbCore::tbString TurtleBrains::Core::GetChildFilepath ( const tbCore::tbString parentFilename,
const tbCore::tbString 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.
tbCore::tbString TurtleBrains::Core::GetPathFromFilepath ( const tbCore::tbString 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.

DynamicStructure TurtleBrains::Core::LoadJsonFile ( const tbCore::tbString 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.

DynamicStructure TurtleBrains::Core::ParseJson ( const tbCore::tbString 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.

template<typename T >
std::string TurtleBrains::Core::ToStdString ( const T &  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.
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.
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 conver 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
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.
template<typename T >
tbString TurtleBrains::Core::ToString ( const T &  object)

Easily convert to the string type defined by tbString, which is either std::string or std::wstring depending on the tb_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_wide_string definition and the string type passed. Even objects with both operator<<(ostream) and operator<<(wostream) can be converted into a tbString using ToString().

Note
Non-string objects like basic primitives and even custom types can be converted to a tbString using ToString but will need to have both operator<<(ostream) and operator<<(wostream) defined and implemented to perform the conversion.
template<typename T >
std::wstring TurtleBrains::Core::ToWideString ( const T &  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.
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.
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)
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.