FastLED 3.10.8
Loading...
Searching...
No Matches
type_schema.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/json.h"
4#include "fl/stl/stdint.h"
5#include "fl/stl/string.h"
7#include "fl/stl/vector.h"
8#include "fl/stl/noexcept.h"
9
10namespace fl {
11namespace detail {
12
13// =============================================================================
14// TypeSchema - Generate JSON Schema for C++ types
15// =============================================================================
16
17// Primary template - unknown types
18template <typename T, typename Enable = void>
19struct TypeSchema {
20 static const char* typeName() FL_NO_EXCEPT {
21 return "unknown";
22 }
23};
24
25// Integer types (excluding bool)
26template <typename T>
27struct TypeSchema<T, typename fl::enable_if<
28 fl::is_integral<T>::value && !fl::is_same<T, bool>::value
29>::type> {
30 static const char* typeName() FL_NO_EXCEPT {
31 return "integer";
32 }
33};
34
35// Boolean type
36template <>
37struct TypeSchema<bool, void> {
38 static const char* typeName() FL_NO_EXCEPT {
39 return "boolean";
40 }
41};
42
43// Floating point types
44template <typename T>
45struct TypeSchema<T, typename fl::enable_if<fl::is_floating_point<T>::value>::type> {
46 static const char* typeName() FL_NO_EXCEPT {
47 return "number";
48 }
49};
50
51// String type
52template <>
53struct TypeSchema<fl::string, void> {
54 static const char* typeName() FL_NO_EXCEPT {
55 return "string";
56 }
57};
58
59// Void type (for return types)
60template <>
61struct TypeSchema<void, void> {
62 static const char* typeName() FL_NO_EXCEPT {
63 return "void";
64 }
65};
66
67// =============================================================================
68// MethodSchema - Generate schema for a function signature
69// =============================================================================
70
71template <typename Sig>
73
74// Specialization for non-void return
75template <typename R, typename... Args>
76struct MethodSchema<R(Args...)> {
77 // Flat params: [["name", "type"], ...] optimized for low-memory devices
79 json arr = json::array();
80 addParams<0, Args...>(arr, names);
81 return arr;
82 }
83
84 static const char* resultTypeName() FL_NO_EXCEPT {
86 }
87
88private:
89 template <fl::size Index>
90 static void addParams(json& arr, const fl::vector<fl::string>& names) FL_NO_EXCEPT {
91 // Base case: no more parameters
92 (void)arr;
93 (void)names;
94 }
95
96 template <fl::size Index, typename First, typename... Rest>
97 static void addParams(json& arr, const fl::vector<fl::string>& names) FL_NO_EXCEPT {
98 json param = json::array();
99 // Name
100 if (Index < names.size() && !names[Index].empty()) {
101 param.push_back(names[Index].c_str());
102 } else {
103 param.push_back("arg" + fl::to_string(static_cast<i64>(Index)));
104 }
105 // Type name
107 arr.push_back(param);
108 addParams<Index + 1, Rest...>(arr, names);
109 }
110};
111
112// Specialization for void return
113template <typename... Args>
114struct MethodSchema<void(Args...)> {
115 // Flat params: [["name", "type"], ...] optimized for low-memory devices
117 json arr = json::array();
118 addParams<0, Args...>(arr, names);
119 return arr;
120 }
121
122 static const char* resultTypeName() FL_NO_EXCEPT {
124 }
125
126private:
127 template <fl::size Index>
128 static void addParams(json& arr, const fl::vector<fl::string>& names) FL_NO_EXCEPT {
129 // Base case: no more parameters
130 (void)arr;
131 (void)names;
132 }
133
134 template <fl::size Index, typename First, typename... Rest>
135 static void addParams(json& arr, const fl::vector<fl::string>& names) FL_NO_EXCEPT {
136 json param = json::array();
137 // Name
138 if (Index < names.size() && !names[Index].empty()) {
139 param.push_back(names[Index].c_str());
140 } else {
141 param.push_back("arg" + fl::to_string(static_cast<i64>(Index)));
142 }
143 // Type name
145 arr.push_back(param);
146 addParams<Index + 1, Rest...>(arr, names);
147 }
148};
149
150} // namespace detail
151} // namespace fl
void push_back(const json &value) FL_NO_EXCEPT
Definition json.h:918
static json array() FL_NO_EXCEPT
Definition json.h:853
FastLED's Elegant JSON Library: fl::json
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_info.h:57
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
string to_string(T value) FL_NO_EXCEPT
Definition string.h:459
Base definition for an LED controller.
Definition crgb.hpp:179
fl::i64 i64
Definition stdint.h:221
static void addParams(json &arr, const fl::vector< fl::string > &names) FL_NO_EXCEPT
Definition type_schema.h:90
static json params(const fl::vector< fl::string > &names) FL_NO_EXCEPT
Definition type_schema.h:78
static const char * resultTypeName() FL_NO_EXCEPT
Definition type_schema.h:84
static void addParams(json &arr, const fl::vector< fl::string > &names) FL_NO_EXCEPT
Definition type_schema.h:97
static const char * resultTypeName() FL_NO_EXCEPT
static json params(const fl::vector< fl::string > &names) FL_NO_EXCEPT
static void addParams(json &arr, const fl::vector< fl::string > &names) FL_NO_EXCEPT
static void addParams(json &arr, const fl::vector< fl::string > &names) FL_NO_EXCEPT
static const char * typeName() FL_NO_EXCEPT
Definition type_schema.h:38
static const char * typeName() FL_NO_EXCEPT
Definition type_schema.h:54
static const char * typeName() FL_NO_EXCEPT
Definition type_schema.h:62
static const char * typeName() FL_NO_EXCEPT
Definition type_schema.h:20