载入中...
搜索中...
未找到
OceanCodecInternal.h
浏览该文件的文档.
1#pragma once
2#include <cmath>
3#include <glm/glm.hpp>
4#include <stdexcept>
5#include "common/Value.h"
6
8inline void keys(const Value& value, std::initializer_list<const char*> names) {
9 if (!value.isObject() || value.keys().size() != names.size()) throw std::runtime_error("object fields");
10 for (const auto* name : names)
11 if (!value.find(name)) throw std::runtime_error(name);
12}
20inline const Value& field(const Value& value, const char* name) {
21 const auto* child = value.find(name);
22 if (!child) throw std::runtime_error(name);
23 return *child;
24}
25inline double number(const Value& value) {
26 if (!value.isNumeric()) throw std::runtime_error("number type");
27 const double result = value.isInt64() ? static_cast<double>(value.asInt()) : value.asDouble();
28 if (!std::isfinite(result)) throw std::runtime_error("finite number");
29 return result;
30}
31inline glm::dvec2 vector(const Value& value) {
32 if (!value.isArray() || value.arraySize() != 2) throw std::runtime_error("two vector components");
33 return {number(value.at(0)), number(value.at(1))};
34}
35inline Value vector(glm::dvec2 value) { return Value::Array{Value(value.x), Value(value.y)}; }
36inline glm::dvec3 vector3(const Value& value) {
37 if (!value.isArray() || value.arraySize() != 3) throw std::runtime_error("three vector components");
38 return {number(value.at(0)), number(value.at(1)), number(value.at(2))};
39}
40inline Value vector(glm::dvec3 value) { return Value::Array{Value(value.x), Value(value.y), Value(value.z)}; }
41} // namespace eve::fluids::ocean_codec
std::string name
Definition ECS.cpp:154
Poco::JSON::Object::Ptr result
Object::Ptr value
double number
Owning, renderer-independent dynamic values.
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::vector< Value > Array
Definition Value.h:33
void keys(const Value &value, std::initializer_list< const char * > names)
glm::dvec2 vector(const Value &value)
glm::dvec3 vector3(const Value &value)
const Value & field(const Value &value, const char *name)
Borrow a required child of value; throws on a missing field.