TwCopyStdStringToClientFunc (function)

void TwCopyStdStringToClientFunc(TwCopyStdStringToClient copyStdStringToClient)

Description

This function is related to variables of type TW_TYPE_STDSTRING (ie. of type std::string defined by the standard template library (STL)). TwCopyStdStringToClientFunc must be used in order to provide a function that will be called by the AntTweakBar library to copy a std::string to the client application (ie. your program).

This function is required because memory allocated by a dynamic library (like AntTweakBar) cannot be resized or deleted by its client application (your program) and vice versa. Thus the provided function is called by AntTweakBar to avoid bad memory handling between the two modules. If it is not provided, all variables of type TW_TYPE_STDSTRING will remain read-only.

In the other way, if your application needs to copy a C++ std::string to AntTweakBar (for instance if you use callbacks to handle the variable via TwAddVarCB), you should copy it by calling TwCopyStdStringToLibrary. See TwCopyStdStringToLibrary for an example of how to use TwAddVarCB with a variable of type TW_TYPE_STDSTRING.

Parameter

copyStdStringToClient

The function that will be called by AntTweakBar to copy a std::string to the client application.

It can be defined like this:

void TW_CALL CopyStdStringToClient(std::string& destinationClientString, const std::string& sourceLibraryString)
{
  // Copy the content of souceString handled by the AntTweakBar library to destinationClientString handled by your application
  destinationClientString = sourceLibraryString;
}

Example

An example of adding a std::string to a tweak bar:

std::string s = "a STL string";
TwBar *bar = TwNewBar("TweakBar");
TwCopyStdStringToClientFunc(CopyStdStringToClient); // CopyStdStringToClient implementation is given above
// ...
TwAddVarRW(bar, "s", TW_TYPE_STDSTRING, &s, "");

See TwCopyStdStringToLibrary for an example that uses TwAddVarCB.

See also