1
Cpp API Overview
GigabiteStudios edited this page 2026-06-17 19:24:43 -05:00

C++ API Overview

The complete public API is declared in <ikvxx/ikvxx.hpp> under namespace ikv.

Supporting types

enum ValueType {
    nullValue, stringValue, intValue, realValue,
    booleanValue, objectValue, arrayValue
};

enum class Version : unsigned { v1 = 1, v2 = 2 };

class Error : public std::runtime_error {};

Construction and ownership

API Behavior
Value(ValueType type = objectValue, std::string root_name = "root") Creates an object or array root; scalar roots throw
Value(const Value&) Copies a handle and shares tree ownership
operator=(const Value&) = delete Structural subtree assignment is deliberately unavailable

Static input methods

API Behavior
Value::parse(text) Parse auto-detected text from memory
Value::load(path) Parse auto-detected text from a file
Value::fromBinary(data, size) Parse auto-detected binary memory
Value::loadBinary(path) Parse auto-detected binary file

All failures throw ikv::Error.

Metadata and type checks

API Result
type() Runtime ValueType; missing values report nullValue
isNull() Missing/null handle
isString() String value
isInt() Signed integer value
isDouble() Double value
isBool() Boolean value
isObject() Object value
isArray() Array value
empty() Object/array has zero entries, or value is scalar/missing
size() Object member count or array length; otherwise zero
name() Root name or member key

Object access

API Behavior
isMember(key) True when an object contains the key
operator[](key) Member handle; missing non-const members are assignable
get(key, fallback) Member or fallback handle
makeObject(key) Add/replace and return nested object
makeArray(key, element_type) Add/replace and return array

String and const char* key overloads are available. Null C-string keys throw.

Array access

API Behavior
operator[](int) Indexed access with negative/bounds checks
operator[](ArrayIndex) Unsigned indexed access with bounds checks
append(string) Append string
append(int64_t) Append signed 64-bit integer
append(int) Append integer
append(double) Append double
append(bool) Append boolean
appendObject() Append and return object

Each access and append has the appropriate const or overload variants shown in the header.

Scalar mutation and reads

API Behavior
operator=(std::string/const char*) Set object member string
operator=(int64_t/int) Set object member integer
operator=(double) Set object member double
operator=(bool) Set object member boolean
asString() Strict string read
asInt64() Strict signed 64-bit read
asInt() Strict integer read with C++ int range check
asDouble() Strict double read
asBool() Strict boolean read

Output and refresh

API Behavior
write(path, version) Write text, default iKv2
writeBinary(path, version) Write binary file, default iKv2
toBinary(version) Return binary bytes, default iKv2
refresh(path) Atomically replace a mutable root from text/binary input

See Ownership, Errors, and Limits before retaining child handles across mutations.