Skip to content

Commit d771921

Browse files
committed
fable: Fix un-reusable interface of Factory class
Also remove factory.hpp from set of headers in schema.hpp, since most users of the library don't need Factory by default. Those who want to use it need to include it explicitely now. Add add_default_factory method to Factory schema. Add args subset option to Factory schema. Add schema transform method to Factory schema.
1 parent de9d324 commit d771921

File tree

7 files changed

+791
-60
lines changed

7 files changed

+791
-60
lines changed

engine/src/stack.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <cloe/simulator.hpp> // for SimulatorFactory
4040
#include <cloe/trigger.hpp> // for Source
4141
#include <cloe/utility/command.hpp> // for Command
42+
#include <fable/schema/factory.hpp> // for Factory
4243

4344
#include "plugin.hpp" // for Plugin
4445

fable/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ if(BuildTests)
5151
src/fable/environment_test.cpp
5252
src/fable/schema/const_test.cpp
5353
src/fable/schema/enum_test.cpp
54+
src/fable/schema/factory_test.cpp
55+
src/fable/schema/factory_advanced_test.cpp
5456
src/fable/schema/number_test.cpp
5557
src/fable/schema/optional_test.cpp
5658
src/fable/schema/struct_test.cpp

fable/include/fable/schema.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@
132132
#include <fable/schema/const.hpp> // for Const<>
133133
#include <fable/schema/duration.hpp> // for Duration<>
134134
#include <fable/schema/enum.hpp> // for Enum<>
135-
#include <fable/schema/factory.hpp> // for Factory<>
136135
#include <fable/schema/ignore.hpp> // for Ignore
137136
#include <fable/schema/interface.hpp> // for Interface, Box
138137
#include <fable/schema/json.hpp> // for FromJson<>

fable/include/fable/schema/confable.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,22 @@ class FromConfable : public Base<FromConfable<T>> {
4545
using Type = T;
4646

4747
explicit FromConfable(std::string&& desc = "") {
48-
schema_ = T().schema();
48+
schema_ = Type().schema();
4949
schema_.reset_ptr();
5050
this->type_ = schema_.type();
5151
this->desc_ = std::move(desc);
5252
}
5353

5454
FromConfable(Type* ptr, std::string&& desc)
55-
: Base<FromConfable<T>>(ptr->schema().type(), std::move(desc))
55+
: Base<FromConfable<Type>>(ptr->schema().type(), std::move(desc))
5656
, schema_(ptr->schema())
5757
, ptr_(ptr) {
5858
assert(ptr != nullptr);
5959
}
6060

61+
public: // Special
62+
Box get_confable_schema() const { return schema_.clone(); }
63+
6164
public: // Overrides
6265
Json json_schema() const override {
6366
Json j = schema_.json_schema();
@@ -86,7 +89,7 @@ class FromConfable : public Base<FromConfable<T>> {
8689
Json serialize(const Type& x) const { return x.to_json(); }
8790

8891
Type deserialize(const Conf& c) const {
89-
T tmp;
92+
Type tmp;
9093
tmp.from_conf(c);
9194
return tmp;
9295
}

0 commit comments

Comments
 (0)