Added some utilities to ScriptValue for reading from arrays and maps.
This commit is contained in:
parent
c31dbbd093
commit
44aee31747
@ -10,6 +10,7 @@
|
|||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../container/map_view.hpp"
|
||||||
#include "../container/optional.hpp"
|
#include "../container/optional.hpp"
|
||||||
#include "../internal/common.hpp"
|
#include "../internal/common.hpp"
|
||||||
#include "../util/traits.hpp"
|
#include "../util/traits.hpp"
|
||||||
@ -259,6 +260,60 @@ public:
|
|||||||
static_assert(mijin::always_false_v<T>, "Cannot convert to this type.");
|
static_assert(mijin::always_false_v<T>, "Cannot convert to this type.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
ScriptValue& operator[](std::size_t index) MIJIN_NOEXCEPT
|
||||||
|
{
|
||||||
|
MIJIN_ASSERT_FATAL(isArray(), "Called operator[size_t] on a non-array value.");
|
||||||
|
return std::get<array_t>(base_)[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
const ScriptValue& operator[](std::size_t index) const MIJIN_NOEXCEPT
|
||||||
|
{
|
||||||
|
MIJIN_ASSERT_FATAL(isArray(), "Called operator[size_t] on a non-array value.");
|
||||||
|
return std::get<array_t>(base_)[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
ScriptValue& operator[](const std::string& key) MIJIN_NOEXCEPT
|
||||||
|
{
|
||||||
|
MIJIN_ASSERT_FATAL(isMap(), "Called operator[string] on a non-map value.");
|
||||||
|
return std::get<map_t>(base_)[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
const ScriptValue& operator[](const std::string& key) const MIJIN_NOEXCEPT
|
||||||
|
{
|
||||||
|
MIJIN_ASSERT_FATAL(isMap(), "Called operator[string] on a non-map value.");
|
||||||
|
return std::get<map_t>(base_)[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
std::span<ScriptValue> arrayView() MIJIN_NOEXCEPT
|
||||||
|
{
|
||||||
|
MIJIN_ASSERT_FATAL(isArray(), "Called iterateArray() on a non-array value.");
|
||||||
|
return std::get<array_t>(base_);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
std::span<const ScriptValue> arrayView() const MIJIN_NOEXCEPT
|
||||||
|
{
|
||||||
|
MIJIN_ASSERT_FATAL(isArray(), "Called iterateArray() on a non-array value.");
|
||||||
|
return std::get<array_t>(base_);
|
||||||
|
}
|
||||||
|
|
||||||
|
MapView<std::string, ScriptValue> mapView() MIJIN_NOEXCEPT
|
||||||
|
{
|
||||||
|
MIJIN_ASSERT_FATAL(isMap(), "Called iterateMap() on a non-map value.");
|
||||||
|
return std::get<map_t>(base_);
|
||||||
|
}
|
||||||
|
|
||||||
|
MapView<std::string, const ScriptValue> mapView() const MIJIN_NOEXCEPT
|
||||||
|
{
|
||||||
|
MIJIN_ASSERT_FATAL(isMap(), "Called iterateMap() on a non-map value.");
|
||||||
|
return std::get<map_t>(base_);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user