Ocular Engine
Ocular::Utils::String Class Reference

Collection of helper string-related utilities. More...

#include <StringUtils.hpp>

Public Member Functions

template<typename T >
std::enable_if<!std::is_pointer< T >::value, std::string >::type toString (T const &data, bool isPointer=false) const
 
template<typename T >
std::enable_if<!std::is_pointer< T >::value, bool >::type toString (T const &data, std::string &str, bool isPointer=false) const
 
std::string toString (std::string const &type, void *data, bool isPointer=false) const
 
bool toString (std::string const &type, void *data, std::string &str, bool isPointer=false) const
 
template<typename T >
std::enable_if<!std::is_pointer< T >::value, T >::type fromString (std::string const &value) const
 
template<typename T >
std::enable_if<!std::is_pointer< T >::value, bool >::type fromString (std::string const &value, T &object) const
 
bool fromString (std::string const &type, std::string const &value, void *object)
 
template<typename T >
std::enable_if<!std::is_pointer< T >::value, void >::type registerToString (std::function< std::string(void *, bool)> func)
 
template<typename T >
std::enable_if<!std::is_pointer< T >::value, void >::type registerFromString (std::function< void(std::string const &, void *)> func)
 

Static Public Member Functions

static std::string ToLower (std::string const &str)
 
static std::string ToUpper (std::string const &str)
 
static bool IsEqual (std::string const &strA, std::string const &strB, bool ignoreCase=false)
 
static bool Contains (std::string const &source, std::string const &find, bool ignoreCase=false)
 
static std::string FormatWindowsError (unsigned long error)
 
static std::string FormatBytes (uint64_t bytes)
 
static void Split (std::string const &str, char delim, std::vector< std::string > &tokens)
 
template<typename T >
static std::enable_if< std::is_arithmetic< T >::value, std::string >::type FormatHex (T const x)
 

Detailed Description

Collection of helper string-related utilities.

Member Function Documentation

bool Ocular::Utils::String::Contains ( std::string const &  source,
std::string const &  find,
bool  ignoreCase = false 
)
static
Parameters
[in]source
[in]find
[in]ignoreCase
Returns
TRUE if the source string contains the find string.
std::string Ocular::Utils::String::FormatBytes ( uint64_t  bytes)
static

Supports sizes up to tebibytes in size.

Example:

bytes = 4293386240
"3.99853 GiB (4293386240 B)"
Parameters
[in]bytes
Returns
Formatted string
template<typename T >
static std::enable_if<std::is_arithmetic<T>::value, std::string>::type Ocular::Utils::String::FormatHex ( T const  x)
inlinestatic

Converts an integer type to a hex string.
Source: http://stackoverflow.com/a/5100745/735425

std::string Ocular::Utils::String::FormatWindowsError ( unsigned long  error)
static

Converts a Win32 specific system error DWORD into a human readable string.

Parameters
[in]errorThe DWORD error message
Returns
String representation of the error
template<typename T >
std::enable_if<!std::is_pointer<T>::value, T>::type Ocular::Utils::String::fromString ( std::string const &  value) const
inline

Attempts to create an object of the specified type from the provided string.

In order to perform the conversion, an appropriate 'FromString' method must have been registered (via registerFromString). If no matching function has been registered, then a default object of the type is returned.

See also the bool return variant of this method.

Parameters
[in]valueString representation of the value. Must be castable to the specified type.
Returns
Object resulting form the string. Returns a default constructed object of the type if no function was found.
template<typename T >
std::enable_if<!std::is_pointer<T>::value, bool>::type Ocular::Utils::String::fromString ( std::string const &  value,
T &  object 
) const
inline

Attempts to create an object of the specified type from the provided string.

In order to perform the conversion, an appropriate 'FromString' method must have been registered (via registerFromString). If no matching function has been registered, then FALSE is returned.

Parameters
[in]valueString representation of the value. Must be castable to the specified type.
[out]objectObject to be set based on the input string
Returns
Returns TRUE if a matching 'FromString' function was found, else returns FALSE.
bool Ocular::Utils::String::fromString ( std::string const &  type,
std::string const &  value,
void *  object 
)
inline

Attempts to modify the data pointed to by the object parameter so that it matches the conversion performed on the specified string for the given type.

Example:

void Foo(void* vectorVoid)
{
    OcularString->fromString(Utils::TypeName<Vector3f>::name, "0.0 1.0 2.0", vectorVoid);
}
Parameters
[in]typeString representation of the type. See Utils::TypeName and OCULAR_TYPE macro
[in]valueString representation of the value. Must be castable to the specified type.
[out]objectRaw object data pointer where the converted value will be placed
Returns
Returns TRUE if a matching 'FromString' function was found, else returns FALSE.
bool Ocular::Utils::String::IsEqual ( std::string const &  strA,
std::string const &  strB,
bool  ignoreCase = false 
)
static
Parameters
[in]strA
[in]strB
[in]ignoreCaseIf true, performs a case-insensitive comparision on the strings.
Returns
TRUE if the strings are equal.
template<typename T >
std::enable_if<!std::is_pointer<T>::value, void>::type Ocular::Utils::String::registerFromString ( std::function< void(std::string const &, void *)>  func)
inline

Registers a function to be called when the specified type is requested to be converted.

For more information, see the OCULAR_REGISTER_FROM_STRING helper macro defined in 'Utilities/StringRegistrar.hpp'

template<typename T >
std::enable_if<!std::is_pointer<T>::value, void>::type Ocular::Utils::String::registerToString ( std::function< std::string(void *, bool)>  func)
inline

Registers a function to be called when the specified type is requested to be converted.

For more information, see the OCULAR_REGISTER_TO_STRING helper macro defined in 'Utilities/StringRegistrar.hpp'

void Ocular::Utils::String::Split ( std::string const &  str,
char  delim,
std::vector< std::string > &  tokens 
)
static

Splits the provided string by the specified deliminator. Resulting substrings are stored in the tokens container.

Parameters
[in]str
[in]delim
[out]tokens
std::string Ocular::Utils::String::ToLower ( std::string const &  str)
static

Converts a mixed-case string to all lower-case

Parameters
[in]strString to convert
Returns
Converted string
template<typename T >
std::enable_if<!std::is_pointer<T>::value, std::string>::type Ocular::Utils::String::toString ( T const &  data,
bool  isPointer = false 
) const
inline

Attempts to convert the provided object to a string.

In order to perform the conversion, an appropriate 'ToString' method must have been registered (via registerToString). If no matching function has been registered, then an empty string is returned.

See also the bool return variant of this method.

Parameters
[in]dataObject to convert to a string
[in]isPointerTRUE if data is a pointer
Returns
String representation of the object, or an empty string if no conversion was available.
template<typename T >
std::enable_if<!std::is_pointer<T>::value, bool>::type Ocular::Utils::String::toString ( T const &  data,
std::string &  str,
bool  isPointer = false 
) const
inline

Attempts to convert the provided object to a string.

In order to perform the conversion, an appropriate 'ToString' method must have been registered (via registerToString). If no matching function has been registered, then FALSE is returned.

Parameters
[in]dataObject to convert to a string
[in]isPointerTRUE if data is a pointer
[out]str
Returns
Returns TRUE if a matching 'ToString' function was found, else FALSE.
std::string Ocular::Utils::String::toString ( std::string const &  type,
void *  data,
bool  isPointer = false 
) const
inline

Attempts to convert the provided raw data to a string.

In order to perform the conversion, an appropriate 'ToString' method must have been registered (via registerToString) for the provided type. If no matching function has been registered, then an empty string is returned.

Parameters
[in]typeString representation of the data type. See OCULAR_TYPE macro and/or Utils::TypeName template. Case-sensitive.
[in]dataData to be converted to string
[in]isPointerTRUE if data is a pointer
Returns
String representation of the object, or an empty string if no conversion was available.
bool Ocular::Utils::String::toString ( std::string const &  type,
void *  data,
std::string &  str,
bool  isPointer = false 
) const
inline

Attempts to convert the provided object to a string.

In order to perform the conversion, an appropriate 'ToString' method must have been registered (via registerToString). If no matching function has been registered, then FALSE is returned.

Parameters
[in]typeString representation of the data type. See OCULAR_TYPE macro and/or Utils::TypeName template. Case-sensitive.
[in]dataData to be converted to string
[in]isPointerTRUE if data is a pointer
[out]str
Returns
Returns TRUE if a matching 'ToString' function was found, else returns FALSE.
std::string Ocular::Utils::String::ToUpper ( std::string const &  str)
static

Converts a mixed-case string to all upper-case

Parameters
[in]strString to convert
Returns
Converted string

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