global functions
- ofBinaryToChar()
- ofBinaryToFloat()
- ofBinaryToInt()
- ofBinaryToString()
- ofContains()
- ofFind()
- ofFromString()
- ofGetCurrentTime()
- ofGetDay()
- ofGetElapsedTimeMicros()
- ofGetElapsedTimeMillis()
- ofGetElapsedTimef()
- ofGetEnv()
- ofGetFrameNum()
- ofGetHours()
- ofGetMinutes()
- ofGetMonth()
- ofGetSeconds()
- ofGetSystemTimeMicros()
- ofGetSystemTimeMillis()
- ofGetTargetPlatform()
- ofGetTimestampString()
- ofGetUnixTime()
- ofGetVersionInfo()
- ofGetVersionMajor()
- ofGetVersionMinor()
- ofGetVersionPatch()
- ofGetVersionPreRelease()
- ofGetWeekday()
- ofGetYear()
- ofHexToChar()
- ofHexToFloat()
- ofHexToInt()
- ofHexToString()
- ofIsStringInString()
- ofJoinString()
- ofLaunchBrowser()
- ofRandomize()
- ofRemove()
- ofResetElapsedTimeCounter()
- ofRestoreWorkingDirectoryToDefault()
- ofSaveFrame()
- ofSaveScreen()
- ofSaveViewport()
- ofSetDataPathRoot()
- ofSleepMillis()
- ofSort()
- ofSplitString()
- ofStringReplace()
- ofStringTimesInString()
- ofSystem()
- ofTo()
- ofToBinary()
- ofToBool()
- ofToChar()
- ofToDataPath()
- ofToDouble()
- ofToFloat()
- ofToHex()
- ofToInt()
- ofToInt64()
- ofToLower()
- ofToString()
- ofToUpper()
- ofTrim()
- ofTrimBack()
- ofTrimFront()
- ofUTF8Append()
- ofUTF8Erase()
- ofUTF8Insert()
- ofUTF8Length()
- ofUTF8Substring()
- ofUTF8ToString()
- ofVAArgsToString()
ofBinaryToChar(...)
char ofBinaryToChar(const string &value)
Interprets a string consisting only of 1s and 0s as a char, and returns the corresponding char value.
Documentation from code comments
Convert a binary string to an char.
Interprets a string consisting only of 1s and 0s as an char and returns the corresponding int value.
\value The binary string.
Returns: the char represented by the string or 0 on failure.
ofBinaryToFloat(...)
float ofBinaryToFloat(const string &value)
Interprets a string consisting only of 1s and 0s as a float (little-endian, 32-bit IEEE 754), and returns the corresponding float value.
Documentation from code comments
Convert a binary string to a float.
Interprets a string consisting only of 1s and 0s as an a float (little-endian, 32-bit IEEE 754), and returns the corresponding float value.
\value The binary string.
Returns: the float represented by the string or 0 on failure.
ofBinaryToInt(...)
int ofBinaryToInt(const string &value)
Interprets a string consisting only of 1s and 0s as an int (little-endian, 32-bit), and returns the corresponding int value.
Documentation from code comments
Convert a binary string to an int.
Interprets a string consisting only of 1s and 0s as an int (little-endian, 32-bit), and returns the corresponding int value.
\value The binary string.
Returns: the integer represented by the string or 0 on failure.
ofBinaryToString(...)
string ofBinaryToString(const string &value)
Interprets a string consisting only of 1s and 0s as 8-bit ASCII characters, and returns the corresponding string.
Documentation from code comments
Convert a binary string to ASCII characters.
Interprets a string consisting only of 1s and 0s as 8-bit ASCII characters and returns the corresponding string.
\value The binary string.
Returns: the ASCII string represented by the string.
ofContains(...)
bool ofContains(const int &values, const T &target)
returns true if the vector values contains target
Documentation from code comments
Search for a target value in a vector of values. \tparam T the type contained by the vector.
Parameters:
values The vector of values to be searched.
target The target value to be found.
Returns: true if at least one value equal to the target value is found.
ofFind(...)
size_t ofFind(const int &values, const T &target)
Documentation from code comments
Search for a target value in a vector of values. \tparam T the type contained by the vector.
Parameters:
values The vector of values to be searched.
target The target value to be found.
Returns: true the index of the first target value found.
See also: http://www.cplusplus.com/reference/iterator/distance/
ofFromString(...)
const char * ofFromString(const string &value)
Documentation from code comments
Convert a string represetnation to another string.
Equivalent to calling the .c_str()
on a std::string.
Parameters:
value The string value to convert to another string.
Returns: the string converted to a c-style string.
ofFromString(...)
T ofFromString(const string &value)
Documentation from code comments
Convert a string represetnation to another type.
Often, this method will be used to convert a string to a numerical type.
\tparam T The target data type.
Parameters:
value The string value to convert to type T.
Returns: the string converted to the target data type T.
ofFromString(...)
string ofFromString(const string &value)
Documentation from code comments
Convert a string represetnation to another string.
Parameters:
value The string value to convert to another string.
Returns: the string converted to another string.
ofGetCurrentTime()
ofTime ofGetCurrentTime()
Documentation from code comments
Get the system time.
Returns: the system time.
ofGetDay()
int ofGetDay()
Documentation from code comments
Get the current day within the month.
Returns: the day witin the month [1-31].
ofGetElapsedTimeMicros()
uint64_t ofGetElapsedTimeMicros()
returns the elapsed time since the application started in microseconds (1000000 microsecs = 1 second)
Documentation from code comments
Get the elapsed time in microseconds.
This returns the elapsed time since ofResetElapsedTimeCounter() was called. Usually ofResetElapsedTimeCounter() is called automatically upon program startup.
Returns: the elapsed time in microseconds (1000000 microseconds = 1 second).
ofGetElapsedTimeMillis()
uint64_t ofGetElapsedTimeMillis()
Documentation from code comments
Get the elapsed time in milliseconds.
This returns the elapsed time since ofResetElapsedTimeCounter() was called. Usually ofResetElapsedTimeCounter() is called automatically once during program startup.
Returns: the elapsed time in milliseconds (1000 milliseconds = 1 second).
ofGetElapsedTimef()
float ofGetElapsedTimef()
returns the elapsed time since the application started in seconds as a float
Documentation from code comments
Get the elapsed time in seconds.
This returns the elapsed time since ofResetElapsedTimeCounter() was called. Usually ofResetElapsedTimeCounter() is called automatically once during program startup.
Returns: the floating point elapsed time in seconds.
ofGetEnv(...)
string ofGetEnv(const string &var)
Documentation from code comments
Get the value of a given environment variable. \note The available environment variables differ between operating systems.
Returns: the environmnt variable's value or an empty string if not found.
ofGetFrameNum()
uint64_t ofGetFrameNum()
Documentation from code comments
Get the number of frames rendered since the program started.
Returns: the number of frames rendered since the program started.
ofGetHours()
int ofGetHours()
Documentation from code comments
Get the hour of the day.
Returns: the hour of the day [0-23].
ofGetMinutes()
int ofGetMinutes()
Documentation from code comments
Get minutes after the hour.
Returns: the minutes after the hour [0-59].
ofGetMonth()
int ofGetMonth()
Documentation from code comments
Get the current month.
Returns: the current month [1-12].
ofGetSeconds()
int ofGetSeconds()
Documentation from code comments
\section System Time Get the seconds after the minute.
Returns: the seconds after the minute [0-59].
ofGetSystemTimeMicros()
uint64_t ofGetSystemTimeMicros()
Documentation from code comments
Get the system time in microseconds.
Returns: the system time in microseconds.
ofGetSystemTimeMillis()
uint64_t ofGetSystemTimeMillis()
Documentation from code comments
Get the system time in milliseconds.
Returns: the system time in milliseconds.
ofGetTargetPlatform()
ofTargetPlatform ofGetTargetPlatform()
Documentation from code comments
Get the target platform of the current system.
Returns: the current ofTargetPlatform.
ofGetTimestampString(...)
string ofGetTimestampString(const string ×tampFormat)
Documentation from code comments
Formats the current system time according to the given format.
The format string is used as a template to format the date and is copied character by character except for the following special characters, which are replaced by the corresponding value.
specifier | Replaced by | Example |
---|---|---|
%a | Abbreviated weekday name | Thu |
%A | Full weekday name | Thursday |
%b | Abbreviated month name | Aug |
%B | Full month name | August |
%c | Date and time representation | Thu Aug 23 14:55:02 2001 |
%C | Year divided by 100 and truncated to integer (00-99) | 20 |
%d | Day of the month, zero-padded (01-31) | 23 |
%D | Short MM/DD/YY date, equivalent to %m/%d/%y | 08/23/01 |
%e | Day of the month, space-padded ( 1-31) | 23 |
%F | Short YYYY-MM-DD date, equivalent to %Y-%m-%d | 2001-08-23 |
%g | Week-based year, last two digits (00-99) | 01 |
%G | Week-based year | 2001 |
%h | Abbreviated month name (same as %b) | Aug |
%H | Hour in 24h format (00-23) | 14 |
%I | Hour in 12h format (01-12) | 02 |
%j | Day of the year (001-366) | 235 |
%m | Month as a decimal number (01-12) | 08 |
%M | Minute (00-59) | 55 |
%n | New-line character | ('\n') |
%p | AM or PM designation | PM |
%r | 12-hour clock time | 02:55:02 pm |
%R | 24-hour HH:MM time, equivalent to %H:%M | 14:55 |
%S | Second (00-61) | 02 |
%t | Horizontal-tab character | ('\t') |
%T | ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S | 14:55:02 |
%u | ISO 8601 weekday as number with Monday as 1 (1-7) | 4 |
%U | Week number with the first Sunday as the first day of week one (00-53) | 33 |
%V | ISO 8601 week number (01-53) | 34 |
%w | Weekday as a decimal number with Sunday as 0 (0-6) | 4 |
%W | Week number with the first Monday as the first day of week one (00-53) | 34 |
%x | Date representation | 08/23/01 |
%X | Time representation | 14:55:02 |
%y | Year, last two digits (00-99) | 01 |
%Y | Year | 2001 |
%z | ISO 8601 offset from UTC in timezone (1 minute=1, 1 hour=100) If timezone cannot be determined, no characters | +100 |
%Z | Timezone name or abbreviation. If timezone cannot be determined, no characters | CDT |
%% | A % sign | % |
Parameters:
timestampFormat The formatting pattern.
Returns: the formatted timestamp as a string.
Warning: an invalid timestampFormat may crash windows apps.
ofGetTimestampString()
string ofGetTimestampString()
Documentation from code comments
Formats the current system time according to the given format.
The default timestamp format is "%Y-%m-%d-%H-%M-%S-%i" (e.g. 2011-01-15-18-29-35-299).
Returns: the current time as a string with the default format.
ofGetUnixTime()
unsigned int ofGetUnixTime()
Documentation from code comments
Get the number of seconds since Midnight, January 1, 1970.
Resolution is in seconds.
Returns: the number of seconds since Midnight, January 1, 1970 (epoch time).
ofGetVersionInfo()
string ofGetVersionInfo()
Documentation from code comments
\section openFrameworks Version Get the current version of openFrameworks as a string.
openFrameworks uses the semantic versioning system.
See also: http://semver.org/
Returns: The string representation of the version (e.g. 0.9.0
).
ofGetVersionMajor()
unsigned int ofGetVersionMajor()
Documentation from code comments
Get the major version number of openFrameworks.
openFrameworks uses the semantic versioning system.
See also: http://semver.org/
Returns: The major version number.
ofGetVersionMinor()
unsigned int ofGetVersionMinor()
Documentation from code comments
Get the minor version number of openFrameworks.
openFrameworks uses the semantic versioning system.
See also: http://semver.org/
Returns: The minor version number.
ofGetVersionPatch()
unsigned int ofGetVersionPatch()
Documentation from code comments
Get the patch version number of openFrameworks.
openFrameworks uses the semantic versioning system.
See also: http://semver.org/
Returns: The patch version number.
ofGetVersionPreRelease()
string ofGetVersionPreRelease()
Documentation from code comments
Get the pre-release version of openFrameworks.
openFrameworks uses the semantic versioning system.
For pre-release versions of openFrameworks, including development versions, this string will describe the pre-release state. Examples might include "master", "rc1", "rc2", etc. For all stable releases, this string will be empty.
See also: http://semver.org/
Returns: The pre-release version string.
ofGetWeekday()
int ofGetWeekday()
Documentation from code comments
Get the current weekday.
Values 0 = Sunday, 1 = Monday, ..., 6 = Saturday.
Returns: the current weekday [0-6].
ofGetYear()
int ofGetYear()
Documentation from code comments
Get the current year.
Returns: the current year.
ofHexToChar(...)
char ofHexToChar(const string &charHexString)
Converts a hexadecimal representation of an char (e.g., "61") to an actual char (e.g., a).
Documentation from code comments
Convert a string representing an char in hexadecimal to a char.
Converts a hexadecimal representation of an char (e.g., "61"
) to an actual
char
(e.g., a
).
Parameters:
charHexString The string representing an char in hexadecimal.
Returns: the char represented by the string.
ofHexToFloat(...)
float ofHexToFloat(const string &floatHexString)
Converts a hexadecimal representation of an float (little-endian, 32-bit IEEE 754, e.g., "4060000000000000") to an actual float (e.g., 128.f).
Documentation from code comments
Convert a string representing an float in hexadecimal to a float.
Converts a hexadecimal representation of an float (little-endian, 32-bit
IEEE 754, e.g., "43000000"
) to an actual float (e.g., 128.f
).
Parameters:
floatHexString The string representing an float in hexadecimal.
Returns: the float represented by the string.
ofHexToInt(...)
int ofHexToInt(const string &intHexString)
Converts a hexadecimal representation of an int (little-endian, 32-bit, e.g., "0xbadf00d" or "badf00d") to an actual int.
Documentation from code comments
Convert a string representing an integer in hexadecimal to a string.
Converts a hexadecimal representation of an int (little-endian, 32-bit,
e.g., "0xbadf00d"
or "badf00d"
) to an actual int
.
Parameters:
intHexString The string representing an integer in hexadecimal.
Returns: the integer represented by the string.
ofHexToString(...)
string ofHexToString(const string &stringHexString)
Converts a hexadecimal representation of an string (e.g., "61626364656667") to an actual string ("abcdefg");
Documentation from code comments
Convert a string representing an string in hexadecimal to a string.
Converts a hexadecimal representation of an string (e.g.,
"61626364656667"
) to an actual string ("abcdefg"
).
Parameters:
stringHexString The string representing an string in hexadecimal.
Returns: the string represented by the string.
ofIsStringInString(...)
bool ofIsStringInString(const string &haystack, const string &needle)
ofJoinString(...)
string ofJoinString(const int &stringElements, const string &delimiter)
Turns a stringElements into a single string, with an instance of delimiter between all the elements.
Documentation from code comments
Join a vector of strings together into one string.
Parameters:
stringElements The vector of strings to join.
delimiter The delimiter to put betweeen each string.
ofRandomize(...)
void ofRandomize(int &values)
Documentation from code comments
\section Vectors Randomly reorder the values in a vector. \tparam T the type contained by the vector.
Parameters:
values The vector of values to modify.
See also: http://www.cplusplus.com/reference/algorithm/random_shuffle/
ofRemove(...)
void ofRemove(int &values, BoolFunction shouldErase)
Documentation from code comments
Conditionally remove values from a vector.
Values are removed if, when passed to the BoolFunction, the BoolFunction function returns true. The given BoolFunction can be a custom function or a built-in function.
Example of a custom function to remove odd numbers from a std::vector
bool IsOdd(int i) {
return ((i % 2) == 1);
}
To call the function, one might use:
std::vector<int> myInts;
// Fill the vector with integers.
for (int i = 0; i < 10; ++i)
{
myInts.push_back(i);
}
ofRemove(myInts, IsOdd);
The resulting vector will contain the following values:
0, 2, 4, 6, 8
\tparam T the type contained by the vector. \tparam BoolFunction the boolean function used to erase.
Parameters:
values The vector of values to modify.
shouldErase A boolean function as described above.
See also: http://www.cplusplus.com/reference/algorithm/remove_if/
ofResetElapsedTimeCounter()
void ofResetElapsedTimeCounter()
Documentation from code comments
\section Elapsed Time Reset the elapsed time counter.
This method resets the times returned by ofGetElapsedTimef(), ofGetElapsedTimeMillis() and ofGetElapsedTimeMicros() to zero.
\note This is called on the first frame during app startup.
ofRestoreWorkingDirectoryToDefault()
bool ofRestoreWorkingDirectoryToDefault()
Documentation from code comments
Reset the working directory to the platform default.
The default working directory is where the application was started from or the exe directory in case of osx bundles. GLUT might change the default working directory to the resources directory in the bundle in osx. This will restore it to the exe dir or whatever was the current dir when the application was started
ofSaveFrame(...)
void ofSaveFrame(bool bUseViewport=false)
Documentation from code comments
Saves the current frame as a PNG image.
The PNG image will be named according to an internal counter in sequence. The count will be restarted each time the program is restarted.
Parameters:
bUseViewport Set to true if the current viewport should be used.
ofSaveScreen(...)
void ofSaveScreen(const string &filename)
Saves the current screen image into a given file name (string filename). Example:
string filename;
filename = "screen1.png";
ofSaveScreen(filename);
Documentation from code comments
\section Frame Saving Saves the current screen image to a file on disk.
Example:
ofSaveScreen("screen.png"); // Will save screen.png in the /data folder.
The output file type will be deduced from the given file name.
Parameters:
filename The image output file.
ofSaveViewport(...)
void ofSaveViewport(const string &filename)
Documentation from code comments
Saves the current viewport as an image.
The output file type will be deduced from the given file name.
Parameters:
filename The image output file.
ofSetDataPathRoot(...)
void ofSetDataPathRoot(const filesystem::path &root)
Documentation from code comments
Set the relative path to the data/ folder from the executable.
This method can be useful when users want to embed the data as a resource folder within an *.app bundle on OSX or perhaps work from a shared data folder in the user's Documents directory.
Warning: The provided path must have a trailing slash (/).
Parameters:
root The path to the data/ folder relative to the app executable.
ofSleepMillis(...)
void ofSleepMillis(int millis)
Documentation from code comments
Sleeps the current thread for the specified amount of milliseconds.
Parameters:
millis The number of millseconds to sleep.
ofSort(...)
void ofSort(int &values)
Documentation from code comments
Sort a vector of values into ascending order.
The elements are compared using operator< for the first version. Equivalent elements are not guaranteed to keep their original relative order.
\tparam T the type contained by the vector.
Parameters:
values The vector of values to be sorted.
See also: http://www.cplusplus.com/reference/algorithm/sort/
ofSort(...)
void ofSort(int &values, BoolFunction compare)
Documentation from code comments
Sort a vector of values into an order defined by a comparator.
Example of a custom function to sort descending of integers:
bool sortDescending(int i, int j)
{
return (j < i);
}
This binary function must accept two elements in the range as arguments and return a value convertible to bool. The value returned indicates whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines. The function shall not modify any of its arguments. This can either be a function pointer or a function object.
To call the function, one might use:
std::vector<int> myInts;
// Fill the vector with integers.
for (int i = 0; i < 10; ++i)
{
myInts.push_back(i);
}
ofSort(myInts, sortDescending);
The resulting vector will contain the following values:
9, 8, 7, 6, 5, 4, 3, 2, 1, 0.
\tparam T the type contained by the vector.
Parameters:
values The vector of values to be sorted.
compare The comparison function.
See also: http://www.cplusplus.com/reference/algorithm/sort/
ofSplitString()
int ofSplitString()
Splits source using delimiter and returns the separate tokens. In modern versions of openFrameworks, delimiter can be a multi-character string. In older versions of openFrameworks, delimiter was interpreted as multiple single-character delimiters.
Documentation from code comments
\section String Manipulation Splits a string using a delimiter.
ofSplitString splits a string and returns the collection of string tokens inside of a std::vector<:string>.
A useful application is to use delimiter " "
:
result = ofSplitString("of rocks", " ");
// result[0] = "of"
// result[1] = "rocks"
Like this a big string can be "cut" and turned it into a collection of words. The user can also ignore empty tokens. Empty tokens occur when a there are multiple delimiters in a row (e.g. "of,rocks,,!"). The user can also "trim" the tokens. This will remove whitespace from before and after each token. This might be useful when a delimted string is padded with with spaces (e.g. "of , rocks ,!").
Parameters:
source The string to split.
delimiter The delimiter string.
ignoreEmpty Set to true to remove empty tokens.
trim Set to true to trim the resulting tokens.
Returns: A vector of strings split with the delimiter.
ofStringReplace(...)
void ofStringReplace(string &input, const string &searchStr, const string &replaceStr)
Searches input for instances of searchStr and replaces them with replaceStr.
string message = "hello, world!";
ofStringReplace(message,"hello","goodbye");
ofLog() << message; // outputs "goodbye, world!"
Documentation from code comments
Replace all occurrences of a string with another string. \note The input string is passed by reference, so it will be modified.
Parameters:
input The string to run the replacement on.
searchStr The string to be replaced.
replaceStr The string to put in place.
ofStringTimesInString(...)
size_t ofStringTimesInString(const string &haystack, const string &needle)
Documentation from code comments
Check how many times a string contains another string.
Parameters:
haystack The string to check for occurrence in .
needle The string to check for.
ofSystem(...)
string ofSystem(const string &command)
Executes an application or a system command and returns its output as string. Will block until the executed program/command has finished.
Documentation from code comments
Executes a system command. Similar to run a command in terminal. \note Will block until the executed program/command has finished.
Returns: the system command output as string.
ofToBinary(...)
string ofToBinary(const T &value)
Converts any datatype value to a string of only 1s and 0s corresponding to the way value is stored in memory.
Documentation from code comments
Converts any datatype value to a string of only 1s and 0s.
The corresponding string of 1s and 0s corresponds to the way value is stored in memory.
\tparam T The data type of the value to convert to a binary string.
Parameters:
value The data to convert to a binary string.
Returns: a binary string.
ofToBinary(...)
string ofToBinary(const string &value)
Converts a string value to a string of only 1s and 0s corresponding to the way value is stored in memory.
Documentation from code comments
Converts a string value to a string of only 1s and 0s.
The corresponding string of 1s and 0s corresponds to the way value is stored in memory.
Parameters:
value The string to convert to a binary string.
Returns: a binary string.
ofToBinary(...)
string ofToBinary(const char *value)
Converts any C-style string value to a string of only 1s and 0s corresponding to the way value is stored in memory.
Documentation from code comments
Converts a c-style string to a string of only 1s and 0s.
The corresponding string of 1s and 0s corresponds to the way value is stored in memory.
Parameters:
value The c-style string to convert to a binary string.
Returns: a binary string.
ofToBool(...)
bool ofToBool(const string &boolString)
Converts a string representation boolString (e.g., "TRUE") to an actual bool using a case-insensitive comparison against the words "true" and "false".
Documentation from code comments
Convert a string to a boolean.
Converts a std::string representation of a boolean (e.g., "TRUE"
) to an
actual bool
using a case-insensitive comparison against the words "true"
and "false"
.
Parameters:
boolString The string representation of the boolean.
Returns: the boolean represented by the string or 0 on failure.
ofToChar(...)
char ofToChar(const string &charString)
Converts a string representation of a single char (e.g., " c ") to an actual char.
Documentation from code comments
Convert a string representation of a char to a actual char.
Converts a string representation of a single char (e.g., "c"
) to an
actual char
.
\note Multi-byte chars and multi-char strings are not supported.
Parameters:
charString The char string to convert.
Returns: The string as a char or 0 on failure.
ofToDataPath(...)
string ofToDataPath(const filesystem::path &path, bool absolute=false)
openFrameworks now treats all files in the data/ folder as being at the same level as your app. When a file is loaded using openFrameworks classes (like ofVideoPlayer) the file path is run through this function to turn it into a relative path for the executible. As windows, mac and linux all have different relative paths, it is important to use this function if you have written your own class or addon for openFrameworks and you wish to be able to load files from the data/ folder.
The optional parameter makeAbsolute, if set to true (false by default) returns the generated path as an absolute path starting from the root of your filesystem instead of from the folder your application is run from.
Documentation from code comments
Make a path relative to the location of the data/ folder.
This funtion returns path unchanged if ofDisableDataPath() was called first.
By default, a relative path is returned. Users requiring absolute paths for (e.g. for non-openFrameworks functions), can specify that an absolute path be returned.
Parameters:
path The path to make relative to the data/ folder.
absolute Set to true to return an absolute path.
Returns: the new path, unless paths were disabled with ofDisableDataPath().
ofToDouble(...)
double ofToDouble(const string &doubleString)
Documentation from code comments
Convert a string to a double.
Converts a std::string representation of a double (e.g., "3.14"
) to an
actual double
.
Parameters:
doubleString The string representation of the double.
Returns: the double represented by the string or 0 on failure.
ofToFloat(...)
float ofToFloat(const string &floatString)
Converts a string representation floatString (e.g., "3.14") to an actual float.
Documentation from code comments
Convert a string to a float.
Converts a std::string representation of a float (e.g., "3.14"
) to an
actual float
.
Parameters:
floatString string representation of the float.
Returns: the float represented by the string or 0 on failure.
ofToHex(...)
string ofToHex(const T &value)
Converts any value to its equivalent hexadecimal representation corresponding to the way it is stored in memory.
Documentation from code comments
Converts any value to its equivalent hexadecimal representation.
The hexadecimal representation corresponds to the way a number is stored in memory.
\tparam T The data type of the value to convert to a hexadecimal string.
Parameters:
value The value to convert to a hexadecimal string.
Returns: the hexadecimal string representation of the value.
ofToHex(...)
string ofToHex(const string &value)
Converts a string (e.g., "abc") to its equivalent hexadecimal representation (e.g., "616263").
Documentation from code comments
Convert a string to a hexadecimal string.
Converts a string (e.g., "abc"
) to its equivalent hexadecimal
representation (e.g., "616263"
).
Parameters:
value The value to convert to a hexadecimal string.
Returns: a hexadecimal string.
ofToHex(...)
string ofToHex(const char *value)
Converts a c-style string (e.g., "abc") to its equivalent hexadecimal representation (e.g., "616263").
Documentation from code comments
Convert a c-style string to a hexadecimal string.
Converts a string (e.g., "abc"
) to its equivalent hexadecimal
representation (e.g., "616263"
).
Parameters:
value The value to convert to a hexadecimal string.
Returns: a hexadecimal string.
ofToInt(...)
int ofToInt(const string &intString)
Converts a string representation of an int (e.g., "2012") to an actual int.
Documentation from code comments
\section Number Conversion Convert a string to an integer.
Converts a std::string
representation of an int (e.g., "3"
) to an actual
int
.
Parameters:
intString The string representation of the integer.
Returns: the integer represented by the string or 0 on failure.
ofToInt64(...)
int64_t ofToInt64(const string &intString)
Documentation from code comments
Convert a string to a int64_t.
Converts a std::string
representation of a long integer
(e.g., "9223372036854775807"
) to an actual int64_t
.
Parameters:
intString The string representation of the long integer.
Returns: the long integer represented by the string or 0 on failure.
ofToLower(...)
string ofToLower(const string &src, const string &locale)
Converts all characters in the string src to lowercase.
Documentation from code comments
Converts all characters in a string to lowercase.
This function expects a UTF-8 encoded multi-byte string to be passed. Resulting strings will be returned as UTF-8 encoded multi-byte strings.
std::string enthusiasticGreeting = "HELLO, WORLD!";
std::string politeGreeting = ofToLower(enthusiasticGreeting);
ofLog() << politeGreeting; // Returns "hello, world!"
Parameters:
src The UTF-8 encoded string to convert to lowercase.
Returns: the UTF-8 encoded string as all lowercase characters.
ofToString(...)
string ofToString(const T &value)
Documentation from code comments
\section String Conversion Convert a value to a string.
ofToString does its best to convert any value to a string. If the data type implements a stream << operator, then it will be converted.
Example:
std::string str = "framerate is ";
str += ofToString(ofGetFrameRate()) + " fps";
// The string now containes something like "framerate is 60 fps".
\tparam T The data type of the value to convert to a string.
Parameters:
value The value to convert to a string.
Returns: A string representing the value or an empty string on failure.
ofToString(...)
string ofToString(const T &value, int precision)
Documentation from code comments
Convert a value to a string with a specific precision.
Like sprintf "%4f" format, in this example precision=4
\tparam T The data type of the value to convert to a string.
Parameters:
value The value to convert to a string.
precision The precision to use when converting to a string.
Returns: The string representation of the value.
ofToString(...)
string ofToString(const T &value, int precision, int width, char fill)
Documentation from code comments
Convert a value to a string with a specific precision, width and filll
Like sprintf "%04.2d" or "%04.2f" format, in this example precision=2, width=4, fill='0'
\tparam T The data type of the value to convert to a string.
Parameters:
value The value to convert to a string.
precision The precision to use when converting to a string.
width The width of the value to use when converting to a string.
fill The character to use when padding the converted string.
Returns: The string representation of the value.
ofToString(...)
string ofToString(const T &value, int width, char fill)
Documentation from code comments
Convert a value to a string with a specific width and fill
Like sprintf "% 4d" or "% 4f" format, in this example width=4, fill=' '
\tparam T The data type of the value to convert to a string.
Parameters:
value The value to convert to a string.
width The width of the value to use when converting to a string.
fill The character to use when padding the converted string.
Returns: The string representation of the value.
ofToString(...)
string ofToString(const int &values)
Converts a vector of values to a single string representation.
vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
cout << ofToString(vec) << endl; // prints "{1, 2, 3}"
Documentation from code comments
Convert a vector of values to a comma-delimited string.
This method will take any vector of values and output a list of the values as a comma-delimited string.
\tparam T The data type held by the vector.
Parameters:
values The vector of values to be converted to a string.
Returns: a comma-delimited string representation of the intput values.
ofToUpper(...)
string ofToUpper(const string &src, const string &locale)
Converts all characters in the string src to uppercase.
string politeGreeting = "Hello, World!";
string enthusiasticGreeting = ofToUpper(politeGreeting);
ofLog() << enthusiasticGreeting; // returns "HELLO, WORLD!"
Documentation from code comments
Converts all characters in the string to uppercase.
This function expects a UTF-8 encoded multi-byte string to be passed. Resulting strings will be returned as UTF-8 encoded multi-byte strings.
std::string politeGreeting = "Hello, World!";
std::string enthusiasticGreeting = ofToUpper(politeGreeting);
ofLog() << enthusiasticGreeting; // Returns "HELLO, WORLD!"
Parameters:
src The UTF-8 encoded string to convert to uppercase.
Returns: the UTF-8 encoded string as all uppercase characters.
ofVAArgsToString(...)
string ofVAArgsToString(const char *format)
Documentation from code comments
Convert a variable length argument to a string.
Parameters:
format a printf-style format string.
Returns: A string representation of the argument list.
ofVAArgsToString(...)
string ofVAArgsToString(const char *format, va_list args)
Documentation from code comments
Convert a variable length argument to a string.
Parameters:
format A printf-style format string.
args A variable argument list.
Returns: A string representation of the argument list.
Last updated Saturday, 17 August 2024 20:48:46 UTC - 99bfb4fd7929e233b87b05758efc36f91505592e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue