EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
JSONDeserialiserHelpers.hpp File Reference

JSONDeserialiserHelpers specification. More...

#include <simdjson.h>
#include <unordered_map>
#include "../Sensor.hpp"
#include "../factories/SignalFactory.hpp"

Go to the source code of this file.

Classes

class  echomap::JSONDeserialiserHelpers
 Provides a set of static helpers for parsing Project fields with SIMDJSON. More...

Namespaces

namespace  echomap
 The main EchoMap outermost namespace for all non-exported symbols.

Functions

template<typename simdjson_value>
auto simdjson::tag_invoke (deserialize_tag, simdjson_value &value, echomap::SignalFactory &signal_factory)
template<typename simdjson_value>
static error_code simdjson::tag_invoke (deserialize_tag, simdjson_value &value, echomap::Sensor &sensor)

Detailed Description

JSONDeserialiserHelpers specification.

Author
Oliver Dixon
Date
2026-07-25

Definition in file JSONDeserialiserHelpers.hpp.

Function Documentation

◆ tag_invoke() [1/2]

template<typename simdjson_value>
error_code simdjson::tag_invoke ( deserialize_tag ,
simdjson_value & value,
echomap::Sensor & sensor )
static

Definition at line 178 of file JSONDeserialiserHelpers.hpp.

183{
184 ondemand::object root;
185 auto error = value.get_object().get(root);
186 if (error)
187 return error;
188
189 std::string_view name;
190 if ((error = root["name"].get(name)))
191 return error;
192 sensor.set_name(name);
193
194 ondemand::object position;
195 if ((error = root["position"].get_object().get(position)))
196 return error;
197
198 if ((error = position["x"].get(sensor.position.x)))
199 return error;
200 if ((error = position["y"].get(sensor.position.y)))
201 return error;
202 if ((error = position["z"].get(sensor.position.z)))
203 return error;
204
205 ondemand::object colour;
206 if ((error = root["colour"].get_object().get(colour)))
207 return error;
208
209 if ((error = colour["r"].get(sensor.colour.r)))
210 return error;
211 if ((error = colour["g"].get(sensor.colour.g)))
212 return error;
213 if ((error = colour["b"].get(sensor.colour.b)))
214 return error;
215 if ((error = colour["a"].get(sensor.colour.a)))
216 return error;
217
218 return SUCCESS;
219}
float b
The blue component in the range [0, 1].
Definition Colour.hpp:23
float a
The alpha extent in the range [0, 1].
Definition Colour.hpp:24
float g
The green component in the range [0, 1].
Definition Colour.hpp:22
float r
The red component in the range [0, 1].
Definition Colour.hpp:21
float y
The Y co-ordinate.
Definition Position.hpp:22
float x
The X co-ordinate.
Definition Position.hpp:21
float z
The Z co-ordinate.
Definition Position.hpp:23

◆ tag_invoke() [2/2]

template<typename simdjson_value>
auto simdjson::tag_invoke ( deserialize_tag ,
simdjson_value & value,
echomap::SignalFactory & signal_factory )

Definition at line 127 of file JSONDeserialiserHelpers.hpp.

132{
133 ondemand::object root;
134 auto error = value.get_object().get(root);
135 if (error)
136 return error;
137
138 std::string_view name;
139 if ((error = root["name"].get(name)))
140 return error;
141 signal_factory.set_signal_name(name);
142
143 ondemand::object source;
144 if ((error = root["source"].get_object().get(source)))
145 return error;
146
147 std::string_view kind;
148 if ((error = source["kind"].get(kind)))
149 return error;
150
151 if (kind == "filesystem") {
152 // Signals sourced from the file system are not loaded by the parser; we just populate the source information.
153
154 std::string_view path;
155 if ((error = source["path"].get(path)))
156 return error;
157
158 std::size_t channel_num;
159 if ((error = source["channel"].get(channel_num)))
160 return error;
161
162 signal_factory.set_source(path, channel_num);
163 } else if (kind == "embeddedUniform") {
164 // Embedded signals with uniform sampling are constructed by the parser with the mandatory timing information.
165 if ((error = echomap::JSONDeserialiserHelpers::get_uniformly_sampled_signal_source(source, signal_factory)))
166 return error;
167 } else if (kind == "embeddedVariable") {
168 // Embedded signals with variable sampling are constructed by the parser with the optional timing information.
169 if ((error = echomap::JSONDeserialiserHelpers::get_variably_sampled_signal_source(source, signal_factory)))
170 return error;
171 } else
172 throw std::runtime_error(std::format("Signal {} specifies unknown source kind \"{}\".", name, kind));
173
174 return SUCCESS;
175}
T format(T... args)