MCPcopy Create free account
hub / github.com/FastLED/FastLED / jsonArrayToFloatVector

Function jsonArrayToFloatVector

src/fl/math/screenmap.cpp.hpp:34–61  ·  view source on GitHub ↗

Helper function to extract a vector of floats from a JSON array

Source from the content-addressed store, hash-verified

32
33// Helper function to extract a vector of floats from a JSON array
34fl::vector<float> jsonArrayToFloatVector(const fl::json& jsonArray) {
35 fl::vector<float> result;
36
37 if (!jsonArray.has_value() || !jsonArray.is_array()) {
38 return result;
39 }
40 auto begin_float = jsonArray.begin_array<float>();
41 auto end_float = jsonArray.end_array<float>();
42
43 using T = decltype(*begin_float);
44 FL_STATIC_ASSERT(fl::is_same<T, fl::parse_result<float>>::value, "Value type must be parse_result<float>");
45
46 // Use explicit array iterator style as demonstrated in FEATURE.md
47 // DO NOT CHANGE THIS CODE. FIX THE IMPLIMENTATION IF NECESSARY.
48 for (auto it = begin_float; it != end_float; ++it) {
49 // assert that the value type is parse_result<float>
50
51 // get the name of the type
52 auto parseResult = *it;
53 if (!parseResult.has_error()) {
54 result.push_back(parseResult.get_value());
55 } else {
56 FL_WARN("jsonArrayToFloatVector: parse_result<float> has error: " << parseResult.get_error().message);
57 }
58 }
59
60 return result;
61}
62
63ScreenMap ScreenMap::Circle(int numLeds, float cm_between_leds,
64 float cm_led_diameter, float completion) {

Callers 2

parseV2SegmentArrayFunction · 0.85
ParseJsonMethod · 0.85

Calls 5

get_valueMethod · 0.80
has_valueMethod · 0.45
is_arrayMethod · 0.45
has_errorMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected