Skip to content

Commit

Permalink
add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Nov 9, 2024
1 parent 8c65f53 commit 8c6c325
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions include/matjson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ namespace matjson {
template <class T>
concept CanSerde = CanSerialize<T> && CanDeserialize<T>;

/// Creates a JSON object from a list of key-value pairs
/// Example:
/// > auto obj = makeObject({ {"key", 123}, {"key2", "value"} });
/// @param entries List of key-value pairs
/// @return The JSON object
Value makeObject(std::initializer_list<std::pair<std::string, Value>>);

class MAT_JSON_DLL Value {
Expand Down Expand Up @@ -106,13 +111,17 @@ namespace matjson {
Value(Value&&);
~Value();

Value& operator=(Value);

bool operator==(Value const&) const;
bool operator<(Value const&) const;
bool operator>(Value const&) const;

/// Create an empty JSON object
static Value object();
/// Create an empty JSON array
static Value array();

Value& operator=(Value);

/// Parses JSON from a string
/// @param source The JSON string to parse
/// @return The parsed JSON value or an error
Expand Down Expand Up @@ -203,17 +212,14 @@ namespace matjson {
/// @note If this is not an array or object, returns 0
std::size_t size() const;

bool operator==(Value const&) const;
bool operator<(Value const&) const;
bool operator>(Value const&) const;

/// Dumps the JSON value to a string, with a given indentation.
/// If the given indentation is matjson::NO_INDENTATION, the json is compacted.
/// If the given indentation is matjson::TAB_INDENTATION, the json is indented with tabs.
/// @param indentationSize The number of spaces to use for indentation
/// @return The JSON string or an error
geode::Result<std::string> dump(int indentationSize = 4) const;

/// Returns the type of the JSON value
Type type() const;

std::vector<Value>::iterator begin();
Expand Down Expand Up @@ -253,6 +259,9 @@ namespace matjson {
geode::Result<double> asDouble() const;
geode::Result<std::vector<Value>> asArray() const;

/// Returns the key of the object entry, if it is one.
/// If this is not an entry in an object, returns an empty optional.
/// @return The key of the object entry
std::optional<std::string> getKey() const;

/// Converts the JSON value to a given type, possibly serializing to
Expand Down Expand Up @@ -312,7 +321,7 @@ namespace matjson {
return Value::parse(stream);
}

// This is used for destructuring the value, useful for range for loops:
// This is used internally by C++ when destructuring the value, useful for range for loops:
// > for (auto const& [key, value] : object) { ... }
template <size_t Index, class T>
requires requires { std::is_same_v<std::decay_t<T>, Value>; }
Expand Down

0 comments on commit 8c6c325

Please sign in to comment.