NaviLibrary::NaviUtilities Namespace Reference


Classes

class  MultiValue
class  InlineVector

Typedefs

typedef InlineVector
< std::string > 
Strings
typedef InlineVector
< MultiValue
Args

Functions

std::string _NaviExport getCurrentWorkingDirectory ()
std::string _NaviExport htmlToDataURI (std::string htmlString)
std::string _NaviExport resourceToDataURI (const std::string &resFileName, const std::string &resourceGroupName=Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
void _NaviExport translateLocalProtocols (std::string &strToTranslate)
void _NaviExport translateResourceProtocols (std::string &strToTranslate)
std::string _NaviExport encodeURIComponent (std::wstring strToEncode)
std::wstring _NaviExport decodeURIComponent (std::string strToDecode)
std::string _NaviExport lowerString (std::string strToLower)
bool _NaviExport isPrefixed (const std::string &sourceString, const std::string &prefix, bool ignoreCase=true)
bool _NaviExport isNumeric (const std::string &numberString)
template<class NumberType>
std::string _NaviExport numberToString (const NumberType &number)
template<class NumberType>
NumberType _NaviExport toNumber (const std::string &numberString)
std::wstring _NaviExport toWide (const std::string &stringToConvert)
std::string _NaviExport toMultibyte (const std::wstring &wstringToConvert)
void _NaviExport setLocale (const std::string &localeLanguage="")
int _NaviExport replaceAll (std::string &sourceStr, const std::string &replaceWhat, const std::string &replaceWith)
std::vector
< std::string >
_NaviExport 
split (const std::string &sourceStr, const std::string &delimiter, bool ignoreEmpty=true)
std::map
< std::string,
std::string >
_NaviExport 
splitToMap (const std::string &sourceStr, const std::string &pairDelimiter, const std::string &keyValueDelimiter, bool ignoreEmpty=true)
std::string _NaviExport join (const std::vector< std::string > &sourceVector, const std::string &delimiter, bool ignoreEmpty=true)
std::string _NaviExport joinFromMap (const std::map< std::string, std::string > &sourceMap, const std::string &pairDelimiter, const std::string &keyValueDelimiter, bool ignoreEmpty=true)
std::string _NaviExport templateString (const std::string &templateStr, const Args &args)
void _NaviExport logTemplate (const std::string &templateStr, const Args &args)
bool _NaviExport hexStringToRGB (const std::string &hexString, unsigned char &R, unsigned char &G, unsigned char &B)
std::string _NaviExport encodeBase64 (const std::string &strToEncode)
template<class NumberType>
void _NaviExport limit (NumberType &input, NumberType min, NumberType max)


Detailed Description

Various public utilities that are internally used by by NaviLibrary but may be of some use to you.

Typedef Documentation

typedef InlineVector<MultiValue> NaviLibrary::NaviUtilities::Args

This is a simple way to quickly make inline MultiValue vectors.

Syntax is:

 Args(x)(x)(x)(x)... 

Note:
For example:
        // Before:
        vector<MultiValue> myArgs;
        myArgs.push_back("SandyBob");
        myArgs.push_back(naviData["class"]);
        myArgs.push_back(1337);
        myNavi->evaluateJS("displayInfo(?, ?, ?)", myArgs);

        // After:
        myNavi->evaluateJS("displayInfo(?, ?, ?)", Args("SandyBob")(navidata["class"])(1337));

typedef InlineVector<std::string> NaviLibrary::NaviUtilities::Strings

This is just a simple way to quickly make inline string vectors.

Syntax is: Strings(x)(x)(x)(x)...

Note:
For example:
        // Before:
        vector<string> myVector;
        myVector.push_back("hello");
        myVector.push_back("awesome");
        myVector.push_back("world");
        someFunction(myVector);

        // After:
        someFunction(Strings("hello")("awesome")("world"));


Function Documentation

std::wstring NaviLibrary::NaviUtilities::decodeURIComponent ( std::string  strToDecode  ) 

This is a C++ mirror implementation that I wrote for the Javascript function 'decodeURIComponent'. For more info: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Functions:decodeURIComponent

Parameters:
strToDecode The standard string to decode. Should be previously encoded by 'encodeURIComponent'.
Returns:
A wide string containing the decoded version of strToDecode. You may use toMultibyte() to convert this to a standard string.

std::string NaviLibrary::NaviUtilities::encodeBase64 ( const std::string &  strToEncode  ) 

Encodes a string into Base64.

Parameters:
strToEncode The string to encode.
Returns:
The Base64-encoded representation of the passed string.
The following is freely-available code by René Nyffenegger Obtained from: http://www.adp-gmbh.ch/cpp/common/base64.html

std::string NaviLibrary::NaviUtilities::encodeURIComponent ( std::wstring  strToEncode  ) 

This is a C++ mirror implementation that I wrote for the Javascript function 'encodeURIComponent'. For more info: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Functions:encodeURIComponent

Parameters:
strToEncode The wide string to encode. You may use toWide() to convert a standard string to wide.
Returns:
A standard string containing the encoded (UTF-8 percent-escaped) version of strToEncode.

std::string NaviLibrary::NaviUtilities::getCurrentWorkingDirectory (  ) 

Gets the current working directory for the executable.

Returns:
A string containing the current working directory.

bool NaviLibrary::NaviUtilities::hexStringToRGB ( const std::string &  hexString,
unsigned char &  R,
unsigned char &  G,
unsigned char &  B 
)

Converts a Hex Color String to R, G, B values.

Parameters:
hexString A hex color string in format: "#XXXXXX"
[out] R The unsigned char to store the Red value in.
[out] G The unsigned char to store the Green value in.
[out] B The unsigned char to store the Blue value in.
Returns:
Returns whether or not the conversion was successful.

std::string NaviLibrary::NaviUtilities::htmlToDataURI ( std::string  htmlString  ) 

Converts a String containing HTML into an equivalent Data URI, replaces all 'local://' and 'resource://group/filename' instances with their correct equivalent.

Parameters:
htmlString The string containing the HTML to convert.
Returns:
A string containing a Data URI with 'text/html' mime-type, data encoded in Base64.

bool NaviLibrary::NaviUtilities::isNumeric ( const std::string &  numberString  ) 

Checks whether or not a string is 'numeric' in nature (begins with actual, parseable digits).

Parameters:
numberString The string to check.
Note:
Strings beginning with 'true'/'false' (regardless of case) are numeric.
Returns:
Whether or not the string is numeric (can be successfully parsed into a number).

bool _NaviExport NaviLibrary::NaviUtilities::isPrefixed ( const std::string &  sourceString,
const std::string &  prefix,
bool  ignoreCase = true 
) [inline]

Checks whether or not a string is prefixed with a certain prefix.

Parameters:
sourceString The string to check.
prefix The prefix to search for.
ignoreCase Whether or not to ignore differences in case, default is true.
Returns:
Whether or not a match was found.

std::string NaviLibrary::NaviUtilities::join ( const std::vector< std::string > &  sourceVector,
const std::string &  delimiter,
bool  ignoreEmpty = true 
)

Joins a string vector into a single string. (Effectively does the inverse of NaviUtilities::split)

Parameters:
sourceVector The string vector to join.
delimiter What to delimit each token by.
ignoreEmpty Whether or not to ignore empty strings within the string vector.

std::string NaviLibrary::NaviUtilities::joinFromMap ( const std::map< std::string, std::string > &  sourceMap,
const std::string &  pairDelimiter,
const std::string &  keyValueDelimiter,
bool  ignoreEmpty = true 
)

Joins a string map into a single string. (Effectively does the inverse of NaviUtilities::splitToMap)

Parameters:
sourceMap The string map to join.
pairDelimiter What to delimit each pair by.
keyValueDelimiter What to delimit each key-value by.
ignoreEmpty Whether or not to ignore empty string values within the string map.

template<class NumberType>
void _NaviExport NaviLibrary::NaviUtilities::limit ( NumberType &  input,
NumberType  min,
NumberType  max 
) [inline]

Ensures that a number (input) is within certain limits.

Parameters:
input The number that will be limited.
min The minimum limit.
max The maximum limit.

void NaviLibrary::NaviUtilities::logTemplate ( const std::string &  templateStr,
const Args &  args 
)

A super-easy way to log messages to the Ogre LogManager. For example, instead of:

 LogManager::GetSingleton().logMessage(templateString("a: ?, b: ?"), Args(a)(b))); 
You can just use:
 logTemplate("a: ?, b: ?", Args(a)(b)); 

Note:
See NaviUtilities::templateString for more information.

std::string NaviLibrary::NaviUtilities::lowerString ( std::string  strToLower  ) 

Converts a string into its lower-case equivalent.

Parameters:
strToLower The standard string to convert to lower-case.
Returns:
A standard string containing the equivalent lower-case representation.

template<class NumberType>
std::string _NaviExport NaviLibrary::NaviUtilities::numberToString ( const NumberType &  number  )  [inline]

Converts a Number (int, float, double, bool, etc.) to a String.

Parameters:
number The number (usually of type int, float, double, bool, etc.) to convert to a String.
Returns:
If the conversion succeeds, returns the string equivalent of the number, otherwise an empty string.

int NaviLibrary::NaviUtilities::replaceAll ( std::string &  sourceStr,
const std::string &  replaceWhat,
const std::string &  replaceWith 
)

Replaces all instances of 'replaceWhat' with 'replaceWith' inside a source string.

Parameters:
sourceStr The string to do this to.
replaceWhat What to be replaced.
replaceWith All occurrences of 'replaceWhat' will be replaced with this.
Returns:
The number of instances replaced within 'sourceStr'.

std::string NaviLibrary::NaviUtilities::resourceToDataURI ( const std::string &  resFileName,
const std::string &  resourceGroupName = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME 
)

Converts an Ogre Resource into an equivalent Data URI. Additional 'local://' and 'resource://' specifier translation will occur on the following filetypes: '.html, .htm, .shtml, .php, .asp, .xhtml, .xml, .js, .cgi, .css'

Parameters:
resFileName The filename of the Ogre Resource
resourceGroupName The name of the Ogre Resource Group to search in.
Returns:
A string containing a Data URI with an automatically-identified mime-type, data encoded in Base64.

void NaviLibrary::NaviUtilities::setLocale ( const std::string &  localeLanguage = ""  ) 

Sets the current locale, used for 'toMultibyte()'. If you never call this, the default is usually "English".

Parameters:
localeLanguage The name of the locale language to set. An empty string sets this to the current locale of the OS.

std::vector< std::string > NaviLibrary::NaviUtilities::split ( const std::string &  sourceStr,
const std::string &  delimiter,
bool  ignoreEmpty = true 
)

Splits a string up into a series of tokens (contained within a string vector), delimited by a certain string.

Parameters:
sourceStr The string to split up.
delimiter What to delimit the source string by.
ignoreEmpty Whether or not to ignore empty tokens. (usually created by 2 or more immediately adjacent delimiters)
Returns:
A string vector containing a series of ordered tokens.

std::map< std::string, std::string > NaviLibrary::NaviUtilities::splitToMap ( const std::string &  sourceStr,
const std::string &  pairDelimiter,
const std::string &  keyValueDelimiter,
bool  ignoreEmpty = true 
)

A more advanced form of splitting, parses a string into a string map. Exceptionally useful for use with Query Strings.

Parameters:
sourceStr The string to parse.
pairDelimiter What to delimit pairs by.
keyValueDelimiter What to delimit key-values by.
ignoreEmpty Whether or not to ignore empty values. Empty pairs will always be ignored.
Returns:
A string map containing the parsed equivalent of the passed string.
Note:
For example:
        std::string myQueryString = "name=Bob&sex=none&color=purple";
        std::map<std::string,std::string> myMap = splitToMap(myQueryString, "&", "=");
        std::string myColor = myMap["color"]; // myColor is now 'purple' 

std::string NaviLibrary::NaviUtilities::templateString ( const std::string &  templateStr,
const Args &  args 
)

Translates a template string and some arguments into a full string.

Parameters:
templateStr A string containing the base template, the '?' character will be replaced with string representations of the passed arguments.
args The arguments that will be used to fill in the template.
Note:
For example:
        std::string myString = templateString("name: ?, strength: ?, color: ?", Args("ValhallaSword")(999)("Red"));
        // myString is now = "name: ValhallaSword, strength: 999, color: Red";

std::string NaviLibrary::NaviUtilities::toMultibyte ( const std::wstring &  wstringToConvert  ) 

Converts a wide string to a multibyte string (standard string), based on the current locale.

Parameters:
wstringToConvert The wide string to convert.
Returns:
The multibyte-equivalent of the passed string, based on the current locale.

template<class NumberType>
NumberType _NaviExport NaviLibrary::NaviUtilities::toNumber ( const std::string &  numberString  )  [inline]

Converts a String to a Number.

Parameters:
<NumberType> The NumberType (int, float, bool, double, etc.) to convert to.
numberString A string containing a valid numeric sequence (can check using isNumeric()).
Note:
Strings beginning with 'true'/'false' (regardless of case) are numeric and will be converted accordingly.
Returns:
If conversion succeeds, returns a number of type 'NumberType', otherwise returns a '0' equivalent.

std::wstring NaviLibrary::NaviUtilities::toWide ( const std::string &  stringToConvert  ) 

Converts a multibyte string (standard string) to a wide string.

Parameters:
stringToConvert The multibyte (standard) string to convert.
Returns:
The wide-equivalent of the passed string.

void NaviLibrary::NaviUtilities::translateLocalProtocols ( std::string &  strToTranslate  ) 

Replaces all 'local://' instances within a String with the correct NaviLocal directory.

Note:
For example:
local://filename.html --> file:///C:\My Application\NaviLocal\filename.html 

The NaviManager singleton must be instantiated prior to calling this utility function.

Parameters:
strToTranslate The string to translate.

void NaviLibrary::NaviUtilities::translateResourceProtocols ( std::string &  strToTranslate  ) 

Replaces all '"resource://Group/Filename.ext"' with an equivalent Data URI of the Ogre Resource. Syntax of '"resource://Filename.ext"' assumes the Resource Group is DEFAULT_RESOURCE_GROUP_NAME. If the Ogre Resource is not found, the 'resource://' specifier instance is skipped. Please note that this statement is required to be encased within double-quotes to be valid. Certain filetypes will be additionally parsed for local/resource specifiers and translated accordingly.

Parameters:
strToTranslate The string to translate.


Generated on Tue Jun 10 22:33:20 2008 for NaviLibrary by  doxygen 1.5.3