OCSet
- group OCSet
Set types and operations in OCTypes.
Functions
-
OCTypeID OCSetGetTypeID(void)
Gets the OCTypeID for OCSet.
- Returns:
OCTypeID value.
-
OCSetRef OCSetCreate(void)
Creates a new empty immutable set.
- Returns:
A new OCSetRef instance or NULL on allocation failure.
-
OCMutableSetRef OCSetCreateMutable(OCIndex capacity)
Creates a new empty mutable set.
- Parameters:
capacity – Initial capacity hint (currently ignored).
- Returns:
A new OCMutableSetRef or NULL on allocation failure.
-
OCSetRef OCSetCreateCopy(OCSetRef theSet)
Creates an immutable copy of an existing set.
- Parameters:
theSet – The set to copy.
- Returns:
A new OCSetRef or NULL on error.
-
OCMutableSetRef OCSetCreateMutableCopy(OCSetRef theSet)
Creates a mutable copy of an existing set.
- Parameters:
theSet – The set to copy.
- Returns:
A new OCMutableSetRef or NULL on error.
-
OCIndex OCSetGetCount(OCSetRef theSet)
Returns the number of elements in the set.
- Parameters:
theSet – The set to query.
- Returns:
Element count, or 0 if NULL.
-
bool OCSetContainsValue(OCSetRef theSet, OCTypeRef value)
Checks whether the set contains a given value.
- Parameters:
theSet – The set to query.
value – The value to check.
- Returns:
true if present, false otherwise.
-
OCArrayRef OCSetCreateValueArray(OCSetRef theSet)
Returns all values in the set as a new OCArray.
- Parameters:
theSet – The source set.
- Returns:
A new OCArrayRef of set values, or NULL.
-
bool OCSetAddValue(OCMutableSetRef theSet, OCTypeRef value)
Adds a value to a mutable set.
If the value is already present, the set remains unchanged.
- Parameters:
theSet – The mutable set.
value – The value to add.
- Returns:
true if added or already present, false on error.
-
bool OCSetRemoveValue(OCMutableSetRef theSet, OCTypeRef value)
Removes a value from a mutable set.
If the value is not present, the set remains unchanged.
- Parameters:
theSet – The mutable set.
value – The value to remove.
- Returns:
true if removed, false otherwise.
-
void OCSetRemoveAllValues(OCMutableSetRef theSet)
Removes all values from a mutable set.
- Parameters:
theSet – The mutable set.
-
bool OCSetEqual(OCSetRef set1, OCSetRef set2)
Compares two sets for equality.
- Parameters:
set1 – The first set.
set2 – The second set.
- Returns:
true if both sets contain the same elements.
-
cJSON *OCSetCopyAsJSON(OCSetRef set, bool typed, OCStringRef *outError)
Creates a JSON representation of an OCSet.
For untyped serialization (typed=false), creates a JSON array where each element is serialized using untyped serialization. Note that this loses type information and the set will be indistinguishable from an array upon deserialization.
For typed serialization (typed=true), creates a JSON object with “type”: “OCSet” and “value” array, where each element is serialized with type information.
- Parameters:
set – An OCSetRef to serialize.
typed – Whether to include type information in the serialization.
outError – Optional pointer to receive error information if serialization fails.
- Returns:
A new cJSON object/array on success, or cJSON null on failure. The caller is responsible for managing the returned cJSON object.
-
OCSetRef OCSetCreateFromJSONTyped(cJSON *json, OCStringRef *outError)
Creates an OCSet from typed JSON representation.
Deserializes a JSON object created by OCSetCreateJSONTyped back into an OCSet. Uses the global type registry to deserialize each element.
- Parameters:
json – A cJSON object with “type”: “OCSet” and “value” array.
outError – Optional pointer to receive error information if deserialization fails.
- Returns:
A new OCSetRef on success, or NULL on failure.
-
void OCSetShow(OCSetRef theSet)
Logs the contents of the set to stderr.
- Parameters:
theSet – The set to display.
-
OCTypeID OCSetGetTypeID(void)