ThingWorx BaseType definitions and functions.
More...
Go to the source code of this file.
|
|
twPrimitive * | twPrimitive_CreateFromLocation (const twLocation *value) |
| Helper function to create a twPrimitive of type TW_LOCATION from a location structure. More...
|
|
twPrimitive * | twPrimitive_CreateFromNumber (const double value) |
| Helper function to create a twPrimitive of type TW_NUMBER from a double. More...
|
|
twPrimitive * | twPrimitive_CreateFromInteger (const int32_t value) |
| Helper function to create a twPrimitive of type TW_INTEGER from an integral type (int, short, char). More...
|
|
twPrimitive * | twPrimitive_CreateFromDatetime (const DATETIME value) |
| Helper function to create a twPrimitive of type TW_DATETIME from a DATETIME type. More...
|
|
twPrimitive * | twPrimitive_CreateFromCurrentTime () |
| Helper function to create a twPrimitive of type TW_DATETIME from the current time. More...
|
|
twPrimitive * | twPrimitive_CreateFromBoolean (const char value) |
| Helper function to create a twPrimitive of type TW_BOOLEAN from a char type. More...
|
|
twPrimitive * | twPrimitive_CreateFromInfoTable (struct twInfoTable *it) |
| Helper function to create a twPrimitive of type TW_INFOTABLE from a twInfoTable structure. More...
|
|
twPrimitive * | twPrimitive_CreateVariant (twPrimitive *input) |
| Helper function to create a twPrimitive of type TW_VARIANT from a twPrimitive structure. More...
|
|
twPrimitive * | twPrimitive_CreateFromString (const char *value, char duplicate) |
| Helper function to create a twPrimitive of type TW_STRING from a null-terminated char array. More...
|
|
twPrimitive * | twPrimitive_CreateFromBlob (const char *value, int32_t length, char isImage, char duplicate) |
| Helper function to create a twPrimitive of type TW_BLOB or TW_IMAGE from a char array. More...
|
|
twPrimitive * | twPrimitive_CreateFromVariable (const void *value, enum BaseType type, char duplicateCharArray, uint32_t blobLength) |
| Helper function to create a twPrimitive of any type from a void *. More...
|
|
|
- Note
- Using any of these functions will cause the cJSON library to be linked to your application, increasing the size of the application by ~22KB.
|
struct cJSON * | twPrimitive_ToJson (char *name, twPrimitive *p, struct cJSON *parent) |
| Helper function to convert a twPrimitive to a CJSON object. More...
|
|
twPrimitive * | twPrimitive_CreateFromJson (struct cJSON *j, char *name, enum BaseType type) |
| Helper function to convert a cJSON object to a twPrimitive. More...
|
|
|
typedef struct twLocation | twLocation |
| Location primitive structure.
|
|
void | swap4bytes (char *bytes) |
|
void | swap8bytes (char *bytes) |
|
int | stringToStream (char *string, twStream *s) |
|
char * | streamToString (twStream *s) |
|
enum BaseType | baseTypeFromString (const char *s) |
|
const char * | baseTypeToString (enum BaseType b) |
|
|
typedef struct twPrimitive | twPrimitive |
| BaseType primitive structure. More...
|
|
twPrimitive * | twPrimitive_Create () |
| Creates a new twPrimitive structure. More...
|
|
twPrimitive * | twPrimitive_CreateFromStream (twStream *s) |
| Creates a new twPrimitive structure and populates it with data from a twStream. More...
|
|
twPrimitive * | twPrimitive_CreateFromStreamTyped (twStream *s, enum BaseType type) |
| Allocates a new twPrimitive structure of a specified type and populates it with data from a twStream. More...
|
|
twPrimitive * | twPrimitive_ZeroCopy (twPrimitive *p) |
| Creates a new twPrimitive structure which inherits all pointers of an existing twPrimitive structure p . The pointers of p will be zeroed so that it may be safely deleted. More...
|
|
twPrimitive * | twPrimitive_FullCopy (twPrimitive *p) |
| Creates a new twPrimitive structure and copies all data from an existing twPrimitive structure to the newly created twPrimitive structure. More...
|
|
void | twPrimitive_Delete (void *p) |
| Frees all memory associated with a twPrimitive and all of its owned substructures. More...
|
|
int | twPrimitive_ToStream (twPrimitive *p, twStream *s) |
| Copies the data from a twPrimitive structure to a twStream structure. More...
|
|
char * | twPrimitive_DecoupleStringAndDelete (twPrimitive *p) |
| Helper function to return the value of a TW_STRING family type, remove it from the twPrimitive p , and then delete , leaving the caller with ownership of the returned TW_STRING TW_STRING. More...
|
|
int | twPrimitive_Compare (twPrimitive *p1, twPrimitive *p2) |
| Compares two twPrimitive structures for equivalence. More...
|
|
char | twPrimitive_IsTrue (twPrimitive *p1) |
| Compares a twPrimitive to "true". For booleans true is if the value is "true", for numeric and dattime values true means non-zero, for string, blob & image types true means non-zero length, for locations true means one of longitude, latitude or altitude is non-zero, for infotables true means the table has at least one row. More...
|
|
ThingWorx BaseType definitions and functions.
BaseType primitive structure.
- Note
- Used as a "variant" type throughout the entire API.
Dynamically allocated byte array. Automatically expands its length as needed.
- Note
- Usually not used by applications directly.
Compares two twPrimitive structures for equivalence.
- Parameters
-
[in] | p1 | A pointer to the twPrimitive to be compared against. |
[in] | p2 | A pointer to the twPrimitive to compare with. |
- Returns
- 0 if the twPrimitive structures are identical, 1 if they are not identical, -1 if an error was encountered.
Creates a new twPrimitive structure.
- Returns
- A pointer to the newly allocated structure. Returns NULL on error.
- Note
- The newly allocated twPrimitive structure defaults to a type of TW_NOTHING.
-
The calling function will gain ownership of the returned structure and will be responsible for freeing it via twPrimitive_Delete().
twPrimitive* twPrimitive_CreateFromBlob |
( |
const char * |
value, |
|
|
int32_t |
length, |
|
|
char |
isImage, |
|
|
char |
duplicate |
|
) |
| |
Helper function to create a twPrimitive of type TW_BLOB or TW_IMAGE from a char array.
- Parameters
-
[in] | value | A pointer to the char array to assign to the twPrimitive. |
[in] | length | The length of the char array. |
[in] | isImage | If #TRUE, the returned twPrimitive::type is set to TW_IMAGE. If FALSE, it is set to TW_BLOB. |
[in] | duplicate | If #TRUE, a copy of the array is made. If #FALSE, the primitive takes ownership of the array. |
- Returns
- A pointer to the newly allocated twPrimitive. Returns NULL if an error was encountered.
- Note
- If
duplicate
is #TRUE, the calling function retains ownership of value
and is responsible for freeing it.
-
The calling function gains ownership of the returned twPrimitive and is responsible for freeing it via twPrimitive_Delete();
twPrimitive* twPrimitive_CreateFromBoolean |
( |
const char |
value | ) |
|
twPrimitive* twPrimitive_CreateFromInteger |
( |
const int32_t |
value | ) |
|
Helper function to create a twPrimitive of type TW_INTEGER from an integral type (int, short, char).
- Parameters
-
[in] | value | An integral value to assign to the twPrimitive. |
- Returns
- A pointer to the newly allocated twPrimitive. Returns NULL if an error was encountered.
- Note
- The calling function gains ownership of the returned twPrimitive and is responsible for freeing it via twPrimitive_Delete().
Helper function to convert a cJSON object to a twPrimitive.
- Parameters
-
[in] | j | A pointer to the cJSON object to convert. |
[in] | name | The name of the element that is to be converted. |
[in] | type | The BaseType of the twPrimitive to be created. |
- Returns
- A pointer to the newly allocated twPrimitive object. Returns NULL if an error was encountered.
- Note
- The calling function will gain ownership of the newly allocated cJSON object and is responsible for freeing it.
- Warning
- Using this function will cause the cJSON library to be linked to your application, increasing the size of the application by ~22KB.
Helper function to create a twPrimitive of type TW_LOCATION from a location structure.
- Parameters
-
[in] | value | A pointer to the location structure. |
- Returns
- A pointer to the newly allocated twPrimitive. Returns NULL if an error was encountered.
- Note
- The calling function retains ownership of
value
and is responsible for freeing it.
-
The calling function gains ownership of the returned twPrimitive and is responsible for freeing it via twPrimitive_Delete().
twPrimitive* twPrimitive_CreateFromNumber |
( |
const double |
value | ) |
|
Creates a new twPrimitive structure and populates it with data from a twStream.
- Parameters
-
- Returns
- A pointer to the newly allocated structure. Returns NULL on error.
- Note
- The newly allocated twPrimitive structure defaults to a type of TW_NOTHING.
-
The calling function will gain ownership of the returned structure and will be responsible for freeing it via twPrimitive_Delete().
Allocates a new twPrimitive structure of a specified type and populates it with data from a twStream.
- Parameters
-
- Returns
- A pointer to the newly allocated structure. Returns NULL on error.
- Note
- The calling function will gain ownership of the returned structure and will be responsible for freeing it via twPrimitive_Delete().
twPrimitive* twPrimitive_CreateFromString |
( |
const char * |
value, |
|
|
char |
duplicate |
|
) |
| |
Helper function to create a twPrimitive of type TW_STRING from a null-terminated char array.
- Parameters
-
[in] | value | A pointer to the null-terminated char array to assign to the twPrimitive. |
[in] | duplicate | If #TRUE, a copy of the string is made. If #FALSE, the primitive takes ownership of the string. |
- Returns
- A pointer to the newly allocated twPrimitive. Returns NULL if an error was encountered.
- Note
- If
duplicate
is #TRUE, the calling function retains ownership of value
and is responsible for freeing it.
-
The calling function gains ownership of the returned twPrimitive and is responsible for freeing it via twPrimitive_Delete();
twPrimitive* twPrimitive_CreateFromVariable |
( |
const void * |
value, |
|
|
enum BaseType |
type, |
|
|
char |
duplicateCharArray, |
|
|
uint32_t |
blobLength |
|
) |
| |
Helper function to create a twPrimitive of any type from a void *.
- Parameters
-
[in] | value | A pointer to the char array to assign to the twPrimitive. |
[in] | type | The base type to assign to the new twPrimitive. |
[in] | duplicateCharArray | If #TRUE, a copy of the array is made. If #FALSE, the primitive takes ownership of the array. |
[in] | blobLength | The length of the char array if the type is TW_BLOB or TW_IMAGE. |
- Returns
- A pointer to the newly allocated twPrimitive. Returns NULL if an error was encountered.
- Note
- If
duplicate
is #TRUE, the calling function retains ownership of value
and is responsible for freeing it.
-
The calling function gains ownership of the returned twPrimitive and is responsible for freeing it via twPrimitive_Delete();
char* twPrimitive_DecoupleStringAndDelete |
( |
twPrimitive * |
p | ) |
|
Helper function to return the value of a TW_STRING family type, remove it from the twPrimitive p
, and then delete
, leaving the caller with ownership of the returned TW_STRING TW_STRING.
- Parameters
-
- Returns
- #TW_OK if successful, positive integral on error code (see twErrors.h) if an error was encountered.
- Note
- The calling function will gain ownership of the returned string and is responsible for freeing it.
-
The returned string is guaranteed to not be NULL.
void twPrimitive_Delete |
( |
void * |
p | ) |
|
Frees all memory associated with a twPrimitive and all of its owned substructures.
- Parameters
-
- Returns
- Nothing.
Creates a new twPrimitive structure and copies all data from an existing twPrimitive structure to
the newly created twPrimitive structure.
- Parameters
-
- Returns
- A pointer to the newly allocated structure. Returns NULL on error.
- Note
- The original twPrimitive structure
p
will not be modified. The calling function will therefore retain ownership of p
and is responsible for freeing it via twPrimitive_Delete().
-
The calling function will gain ownership of the returned structure and will be responsible for freeing it via twPrimitive_Delete().
Compares a twPrimitive to "true". For booleans true is if the value is "true", for numeric and dattime values true means non-zero, for string, blob & image types true means non-zero length, for locations true means one of longitude, latitude or altitude is non-zero, for infotables true means the table has at least one row.
- Parameters
-
- Returns
- 0 if the twPrimitive structures is "true", 1 if they are not identical, -1 if an error was encountered.
Helper function to convert a twPrimitive to a CJSON object.
- Parameters
-
[in] | name | The name of the newly created JSON object. |
[in] | p | A pointer to the twPrimitive to convert. |
[in] | parent | (Optional) parent to add the JSON object to (may be NULL). |
- Returns
- A pointer to the newly allocated cJSON object. Returns NULL if an error was encountered.
- Note
- The calling function will retain ownership of the
parent
object and is responsible for freeing it if necessary.
-
The calling function will gain ownership of the newly allocated cJSON object and is responsible for freeing it.
- Warning
- Using this function will cause the cJSON library to be linked to your application, increasing the size of the application by ~22KB.
Copies the data from a twPrimitive structure to a twStream structure.
- Parameters
-
[in] | p | A pointer to the twPrimitive to write to s . |
[in,out] | s | A pointer to the twStream to write p to. |
- Returns
- #TW_OK if successful, positive integral on error code (see twErrors.h) if an error was encountered.
- Note
- This function is typically not used directly by applications.
Creates a new twPrimitive structure which inherits all pointers of an existing twPrimitive structure p
. The pointers of p
will be zeroed so that it may be safely deleted.
- Parameters
-
[in] | p | A pointer to the twPrimitive to be copied from and zeroed. |
- Returns
- A pointer to the newly allocated structure. Returns NULL on error.
- Note
- The calling function gains ownership of the returned twPrimitive and is responsible for freeing it via twPrimitive_Delete().
-
twPrimitive_ZeroCopy() does not free /p p.It only zeros the pointers of
p
so that the base structure p
may be deleted without modifying the newly created twPrimitive. The calling function must still free p
via twPrimitive_Delete().
int twStream_AddBytes |
( |
struct twStream * |
s, |
|
|
void * |
b, |
|
|
uint32_t |
count |
|
) |
| |
Adds data bytes to a twStream.
- Parameters
-
[in] | s | A pointer to the twStream to add bytes to. |
[in] | b | A pointer to the bytes to add. |
[in] | count | The number of bytes to be added. |
- Returns
- #TW_OK if successful, positive integral on error code (see twErrors.h) if an error was encountered.
Creates a new twStream structure.
- Returns
- A pointer to the newly allocated structure. Returns NULL on error.
- Note
- The calling function will gain ownership of the returned structure and will be responsible for freeing it via twStream_Delete().
twStream* twStream_CreateFromCharArray |
( |
const char * |
data, |
|
|
uint32_t |
length |
|
) |
| |
Creates a new twStream structure and copies the data from a char array to the new structure's twStream::data.
- Parameters
-
[in] | data | A pointer to the char array to copy into twStream::data. |
[in] | length | The length of the char array. |
- Returns
- A pointer to the newly allocated structure. Returns NULL on error.
- Note
- The calling function will gain ownership of the returned structure and will be responsible for freeing it via twStream_Delete().
-
The calling function will retain ownership of
data
and will is responsible for freeing it.
twStream* twStream_CreateFromCharArrayZeroCopy |
( |
const char * |
data, |
|
|
uint32_t |
length |
|
) |
| |
Allocates a new twStream structure and points twStream::data to an existing char array.
- Parameters
-
[in] | data | A pointer to the char array to point twStream::data to. |
[in] | length | The length of the char array. |
- Returns
- A pointer to the newly allocated structure. Returns NULL on error.
- Note
- The newly allocated twStream will gain ownership of
data
. The calling function should not free it directly.
-
The calling function will gain ownership of the returned structure and will be responsible for freeing it via twStream_Delete().
void twStream_Delete |
( |
void * |
s | ) |
|
Frees all memory associated with a twStream and all of its owned substructures.
- Parameters
-
[in] | s | A pointer to the twStream to be deleted. |
- Returns
- Nothing.
int twStream_GetBytes |
( |
struct twStream * |
s, |
|
|
void * |
b, |
|
|
uint32_t |
count |
|
) |
| |
Copies count
bytes of data from the twStream::data of a twStream into buf
.
- Parameters
-
[in] | s | A pointer to the twStream to get the bytes from. |
[out] | buf | A pointer to a buffer to hold the copied data. |
[in] | count | The number of bytes to copy. |
- Returns
- #TW_OK if successful, positive integral on error code (see twErrors.h) if an error was encountered.
char* twStream_GetData |
( |
struct twStream * |
s | ) |
|
int32_t twStream_GetIndex |
( |
struct twStream * |
s | ) |
|
Gets the ::twStream#index of a twStream.
- Parameters
-
[in] | s | A pointer to the twStream to get the index of. |
- Returns
- The ::twStream#index of
s
.
int32_t twStream_GetLength |
( |
struct twStream * |
s | ) |
|
int twStream_Reset |
( |
struct twStream * |
s | ) |
|