File tree 1 file changed +20
-2
lines changed
fable/include/fable/schema
1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -192,9 +192,27 @@ class FactoryBase : public Base<CRTP> {
192
192
bool has_factory (const std::string& key) const { return available_.count (key); }
193
193
194
194
/* *
195
- * Add a factory with the given key, schema, and function.
195
+ * Add a factory with the given key, schema, and function, provided it
196
+ * doesn't already exist.
197
+ *
198
+ * Return true if successful, false otherwise.
196
199
*/
197
- void add_factory (const std::string& key, Box&& s, MakeFunc f) {
200
+ bool add_factory (const std::string& key, Box&& s, MakeFunc f) {
201
+ if (!available_.count (key)) {
202
+ available_.insert (std::make_pair (key, TypeFactory{std::move (s), f}));
203
+ reset_schema ();
204
+ return true ;
205
+ }
206
+ return false ;
207
+ }
208
+
209
+ /* *
210
+ * Add or replace a factory with the given key, schema, and function.
211
+ */
212
+ void set_factory (const std::string& key, Box&& s, MakeFunc f) {
213
+ if (!available_.count (key)) {
214
+ available_.erase (key);
215
+ }
198
216
available_.insert (std::make_pair (key, TypeFactory{std::move (s), f}));
199
217
reset_schema ();
200
218
}
You can’t perform that action at this time.
0 commit comments