Buffer Ownership; String Conversions; Converting Between Cpstrings And Supported C Native Data Types - Casio ClassPad 300 Programming Manual

Sdk programming guide
Hide thumbs Also See for ClassPad 300:
Table of Contents

Advertisement

Buffer Ownership

CPStrings control and manage a PEGCHAR* buffer that represents a string. The
deletion of these buffers is normally handled by the CPString class. If you have a
PEGCHAR* that you have already created, but would like to encapsulate in a CPString
class, you can place it in a CPString with:
void TakeBufferOwnership(PEGCHAR *buffer);
This does not mean that the PEGCHAR buffer is copied into CPString. Instead, the
current memory location of PEGCHAR becomes the buffer portion of the CPString. The
CPString's current buffer is discarded when it takes ownership of the new buffer.
On the other hand, you can give up the ownership of a buffer and place it back into a
PEGCHAR* with:
PEGCHAR *GiveBufferOwnership();
This function differs from GetBuffer() in a very important way: Once a CPString has
called GiveBufferOwnership() its buffer is gone. The person who called the function is
now responsible for keeping track of the returned PEGCHAR* and making sure that it is
deleted.

String Conversions

The ClassPad contains several functions to convert strings to and from different data
types. Be aware that these functions take CP_CHAR* and not CPStrings. However,
once you have the converted value you can easily create a CPString with the appropriate
constructor.

Converting Between CPStrings and Supported C native data types

To convert a string to another data type the following functions are used:
int CP_StringToInt(CP_CHAR *pS);
long CP_StringToLong(CP_CHAR *pS);
short CP_StringToShort(CP_CHAR *pS);
char CP_StringToChar(CP_CHAR *pS);
If you want to convert from an int, long, short or char to a string, use:
CP_CHAR *CP_IntToString(int value, CP_CHAR *pS);
CP_CHAR *CP_LongToString(long value, CP_CHAR *pS);
CP_CHAR *CP_ShortToString(short value, CP_CHAR *pS);
CP_CHAR *CP_CharToString(char value, CP_CHAR *pS);
102

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents