1
Value Types
GigabiteStudios edited this page 2026-06-17 19:04:13 -05:00

Value Types

ikv::ValueType

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

Inspection

ikv::ValueType type() const noexcept;
bool isNull() const noexcept;
bool isString() const noexcept;
bool isInt() const noexcept;
bool isDouble() const noexcept;
bool isBool() const noexcept;
bool isObject() const noexcept;
bool isArray() const noexcept;
bool empty() const;
std::size_t size() const;
std::string name() const;
  • type() returns nullValue for a missing member.
  • empty() is true for empty objects/arrays and for scalar or missing values.
  • size() returns object member count or array length; scalars return zero.
  • name() returns the node key/root name, or an empty string when absent.

Scalar assignment

Assignment is supported on a non-const object-member handle produced by operator[]:

root["text"] = std::string("hello");
root["literal"] = "world";
root["wide"] = std::int64_t{9000000000};
root["count"] = 42;
root["ratio"] = 0.5;
root["enabled"] = true;

Assigning a key that already exists replaces that member. A null const char* is rejected.

Scalar conversion

std::string asString() const;
std::int64_t asInt64() const;
int asInt() const;
double asDouble() const;
bool asBool() const;

Conversions are strict; iKvxx does not silently coerce between types. Calling asInt() on a string, for example, throws ikv::Error. asInt() also throws std::out_of_range if the stored 64-bit integer does not fit in a C++ int.

Null handles

auto missing = root["missing"];
if (missing.isNull()) {
    root["missing"] = "created";
}

A missing non-const object member preserves its parent and key, making scalar assignment possible. A missing const lookup is read-only.