Skip to content

Commit 2457a22

Browse files
committed
fixup! fable: Add example stress test with generated code
1 parent 015745e commit 2457a22

18 files changed

+87
-221
lines changed

fable/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ add_library(${target}
2424
src/fable/confable.cpp
2525
src/fable/json.cpp
2626
src/fable/schema.cpp
27-
src/fable/make_schema.cpp
2827
src/fable/schema/boolean.cpp
2928
src/fable/schema/number.cpp
3029
src/fable/schema/struct.cpp

fable/include/fable/make_schema.hpp

Lines changed: 0 additions & 123 deletions
This file was deleted.

fable/include/fable/schema.hpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,27 @@
122122
#include <utility> // for move
123123
#include <vector> // for vector<>
124124

125-
#include <fable/make_schema.hpp> // for make_schema
125+
#include <fable/schema/array.hpp> // for Array<>
126+
#include <fable/schema/boolean.hpp> // for Boolean
127+
#include <fable/schema/confable.hpp> // for FromConfable
128+
#include <fable/schema/const.hpp> // for Const<>
129+
#include <fable/schema/duration.hpp> // for Duration<>
130+
#include <fable/schema/enum.hpp> // for Enum<>
131+
#include <fable/schema/ignore.hpp> // for Ignore
132+
#include <fable/schema/interface.hpp> // for Interface, Box
133+
#include <fable/schema/json.hpp> // for FromJson<>
134+
#include <fable/schema/map.hpp> // for Map<>
135+
#include <fable/schema/number.hpp> // for Number<>
136+
#include <fable/schema/optional.hpp> // for Optional<>
137+
#include <fable/schema/passthru.hpp> // for Passthru
138+
#include <fable/schema/path.hpp> // for Path
139+
#include <fable/schema/string.hpp> // for String
140+
#include <fable/schema/struct.hpp> // for Struct
141+
#include <fable/schema/variant.hpp> // for Variant
142+
143+
// It is important that this include comes after all the other ones,
144+
// so that it has access to ALL the previous definitions.
145+
#include <fable/schema/magic.hpp> // for make_prototype, ...
126146

127147
namespace fable {
128148

@@ -131,7 +151,6 @@ using schema::make_const_schema;
131151
using schema::make_const_str;
132152
using schema::make_prototype;
133153
using schema::make_schema;
134-
using schema::make_schema_impl;
135154

136155
/**
137156
* Define the automatically deduced schema class of a given type.

fable/include/fable/schema/array.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ class Array : public Base<Array<T, P>> {
173173
Type* ptr_{nullptr};
174174
};
175175

176-
template <typename T, typename P>
177-
Array<T, P> make_schema_impl(std::vector<T>* ptr, P&& prototype, std::string&& desc) {
178-
return Array<T, P>(ptr, std::forward<P>(prototype), std::move(desc));
176+
template <typename T, typename P, typename S>
177+
Array<T, P> make_schema(std::vector<T>* ptr, P&& prototype, S&& desc) {
178+
return Array<T, P>(ptr, std::forward<P>(prototype), std::forward<S>(desc));
179179
}
180180

181181
} // namespace schema

fable/include/fable/schema/boolean.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class Boolean : public Base<Boolean> {
5151
Type* ptr_{nullptr};
5252
};
5353

54-
inline Boolean make_schema_impl(bool* ptr, std::string&& desc) { return Boolean(ptr, std::move(desc)); }
54+
template <typename S>
55+
inline Boolean make_schema(bool* ptr, S&& desc) { return Boolean(ptr, std::forward<S>(desc)); }
5556

5657
} // namespace schema
5758
} // namespace fable

fable/include/fable/schema/confable.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ class FromConfable : public Base<FromConfable<T>> {
103103
Type* ptr_{nullptr};
104104
};
105105

106-
template <typename T>
107-
FromConfable<T> make_schema_impl(T* ptr, std::string&& desc) {
106+
template <typename T, typename S>
107+
FromConfable<T> make_schema(T* ptr, S&& desc) {
108108
assert(ptr != nullptr);
109-
return FromConfable<T>(ptr, std::move(desc));
109+
return FromConfable<T>(ptr, std::forward<S>(desc));
110110
}
111111

112112
} // namespace schema

fable/include/fable/schema/const.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,14 @@ class Const : public Base<Const<T, P>> {
8888
const Type constant_;
8989
};
9090

91-
template <typename T, typename P>
92-
Const<T, P> make_const_schema(const T& constant, P&& prototype, std::string&& desc) {
93-
return Const<T, P>(constant, std::forward<P>(prototype), std::move(desc));
94-
}
95-
96-
inline Const<std::string, String> make_const_str(const std::string& constant, std::string&& desc) {
97-
return Const<std::string, String>(constant, std::move(desc));
91+
template <typename T, typename P, typename S>
92+
Const<T, P> make_const_schema(const T& constant, P&& prototype, S&& desc) {
93+
return Const<T, P>(constant, std::forward<P>(prototype), std::forward<S>(desc));
9894
}
9995

100-
inline Const<std::string, String> make_const_str(const char* constant, std::string&& desc) {
101-
return Const<std::string, String>(constant, std::move(desc));
96+
template <typename S1, typename S2>
97+
inline Const<std::string, String> make_const_str(S1&& constant, S2&& desc) {
98+
return Const<std::string, String>(std::forward<S1>(constant), std::forward<S2>(desc));
10299
}
103100

104101
} // namespace schema

fable/include/fable/schema/duration.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,9 @@ class Duration : public Base<Duration<T, Period>> {
186186
Type* ptr_{nullptr};
187187
};
188188

189-
template <typename Rep, typename Period>
190-
inline Duration<Rep, Period> make_schema_impl(std::chrono::duration<Rep, Period>* ptr,
191-
std::string&& desc) {
192-
return Duration<Rep, Period>(ptr, std::move(desc));
189+
template <typename Rep, typename Period, typename S>
190+
inline Duration<Rep, Period> make_schema(std::chrono::duration<Rep, Period>* ptr, S&& desc) {
191+
return Duration<Rep, Period>(ptr, std::forward<S>(desc));
193192
}
194193

195194
} // namespace schema

fable/include/fable/schema/enum.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ class Enum : public Base<Enum<T>> {
102102
Type* ptr_{nullptr};
103103
};
104104

105-
template <typename T, std::enable_if_t<std::is_enum<T>::value, int> = 0>
106-
inline Enum<T> make_schema_impl(T* ptr, std::string&& desc) {
107-
return Enum<T>(ptr, std::move(desc));
105+
template <typename T, typename S, std::enable_if_t<std::is_enum_v<T>, int> = 0>
106+
inline Enum<T> make_schema(T* ptr, S&& desc) {
107+
return Enum<T>(ptr, std::forward<S>(desc));
108108
}
109109

110110
} // namespace schema

fable/include/fable/schema/interface.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,11 @@ using enable_if_confable_t = std::enable_if_t<std::is_base_of<Confable, T>::valu
457457
template <typename T>
458458
using enable_if_not_confable_t = std::enable_if_t<!std::is_base_of<Confable, T>::value>;
459459

460-
template <typename T, std::enable_if_t<std::is_base_of<Confable, T>::value, int> = 0>
461-
auto make_prototype(std::string&& desc = "");
460+
template <typename T, typename S = std::string, std::enable_if_t<std::is_base_of_v<Confable, T>, int> = 0>
461+
auto make_prototype(S&& desc = "");
462462

463-
template <typename T, std::enable_if_t<!std::is_base_of<Confable, T>::value, int> = 0>
464-
auto make_prototype(std::string&& desc = "");
463+
template <typename T, typename S = std::string, std::enable_if_t<!std::is_base_of_v<Confable, T>, int> = 0>
464+
auto make_prototype(S&& desc = "");
465465

466466
} // namespace schema
467467
} // namespace fable

0 commit comments

Comments
 (0)