Toy 1.1.6
The Toy programming language is an imperative bytecode-intermediate embedded scripting language
Loading...
Searching...
No Matches
toy_refstring.h
Go to the documentation of this file.
1
7#ifndef TOY_REFSTRING_H_
8#define TOY_REFSTRING_H_
9
10#include <string.h>
11#include <stdbool.h>
12#include <stddef.h>
13
14#include "toy_common.h"
15
16//memory allocation hook
25typedef void* (*Toy_RefStringAllocatorFn)(void *pointer, size_t oldSize, size_t newSize);
26
34
35//the RefString structure
41typedef struct Toy_RefString {
42 size_t length;
44 char data[];
46
47//API
55TOY_API Toy_RefString* Toy_createRefString(const char *cstring);
56
66TOY_API Toy_RefString* Toy_createRefStringLength(const char *cstring, size_t length);
67
74TOY_API void Toy_deleteRefString(Toy_RefString *refString);
75
83TOY_API int Toy_countRefString(Toy_RefString *refString);
84
92TOY_API size_t Toy_lengthRefString(Toy_RefString *refString);
93
102
111
119TOY_API const char* Toy_toCString(Toy_RefString *refString);
120
130
139TOY_API bool Toy_equalsRefStringCString(Toy_RefString *lhs, char *cstring);
140
141//TODO: merge refstring memory
142
143#endif /* TOY_REFSTRING_H_ */
144
Definition: toy_refstring.h:41
char data[]
Definition: toy_refstring.h:44
int refCount
Definition: toy_refstring.h:43
size_t length
Definition: toy_refstring.h:42
TOY_API void Toy_setRefStringAllocatorFn(Toy_RefStringAllocatorFn)
Conforms to and is invoked by Toy's memory API, and generally shouldn't be used.
void *(* Toy_RefStringAllocatorFn)(void *pointer, size_t oldSize, size_t newSize)
Prototype for interface conforms to Toy's memory API, and generally shouldn't be used.
Definition: toy_refstring.h:25
TOY_API const char * Toy_toCString(Toy_RefString *refString)
Exposes the interal cstring of refString. Only use this function when dealing with external APIs.
TOY_API Toy_RefString * Toy_copyRefString(Toy_RefString *refString)
Increases the reference counter of refString by 1, before returning the given pointer.
TOY_API void Toy_deleteRefString(Toy_RefString *refString)
Reduces the refString's reference counter by 1 and, if it reaches 0, frees the memory.
TOY_API Toy_RefString * Toy_deepCopyRefString(Toy_RefString *refString)
Behaves identically to Toy_copyRefString, except that it explicitly preforms a deep copy of the inter...
TOY_API size_t Toy_lengthRefString(Toy_RefString *refString)
Returns the length of the underlying cstring of refString.
TOY_API int Toy_countRefString(Toy_RefString *refString)
Returns the total number of references to refString, for debugging.
TOY_API Toy_RefString * Toy_createRefString(const char *cstring)
Wraps Toy_CreateRefStringLength, by determining the length of the given cstring and passing it to the...
TOY_API bool Toy_equalsRefStringCString(Toy_RefString *lhs, char *cstring)
Returns true when the refString contains the same value as the cstring. Otherwise it returns false.
TOY_API Toy_RefString * Toy_createRefStringLength(const char *cstring, size_t length)
Returns a new Toy_RefString, containing a copy of cstring, or NULL on error. This function also sets ...
TOY_API bool Toy_equalsRefString(Toy_RefString *lhs, Toy_RefString *rhs)
Returns true when the two refstrings are either the same refstring, or contain the same value....