diff --git a/cmake/ac_local_plugin_util.cmake b/cmake/ac_local_plugin_util.cmake index e723ab60..09cbb196 100644 --- a/cmake/ac_local_plugin_util.cmake +++ b/cmake/ac_local_plugin_util.cmake @@ -173,6 +173,9 @@ const std::vector& get_@nameSym@_model_loaders() { FILES "${CMAKE_CURRENT_BINARY_DIR}/${schemaHeader}" ) endforeach() + + target_link_libraries(${baselibTargetName} PUBLIC ac::schema) + target_link_libraries(${plibTargetName} PUBLIC ac::schema) endif() # add plugin diff --git a/dummy-plugin/test/t-dummy-schema.cpp b/dummy-plugin/test/t-dummy-schema.cpp index 20659d06..e48cf6f3 100644 --- a/dummy-plugin/test/t-dummy-schema.cpp +++ b/dummy-plugin/test/t-dummy-schema.cpp @@ -1,14 +1,20 @@ // Copyright (c) Alpaca Core // SPDX-License-Identifier: MIT // -#include +#include +#include +#include #include +#include + #include #include #include +#include +#include struct LoadDummyFixture { LoadDummyFixture() { @@ -19,5 +25,15 @@ struct LoadDummyFixture { LoadDummyFixture loadDummyFixture; TEST_CASE("dummy schema") { + auto model = ac::local::Lib::modelLoaderRegistry().createModel({ + .inferenceType = "dummy", + .name = "synthetic" + }, {}); + + REQUIRE(!!model); + using Instance = ac::local::schema::Dummy::InstanceGeneral; + auto instance = Model_createInstance(*model, {.cutoff = 2}); + auto result = Instance_runOp(*instance, {.input = {"a", "b", "c"}}); + CHECK(result.result == "a one b two c one"); } diff --git a/local/code/CMakeLists.txt b/local/code/CMakeLists.txt index 17d3f498..46c6c52e 100644 --- a/local/code/CMakeLists.txt +++ b/local/code/CMakeLists.txt @@ -13,7 +13,6 @@ target_link_libraries(ac-local PUBLIC ac::astl ac::dict - ac::schema ) configure_file( diff --git a/schema/code/CMakeLists.txt b/schema/code/CMakeLists.txt index 4bdc7960..cb100299 100644 --- a/schema/code/CMakeLists.txt +++ b/schema/code/CMakeLists.txt @@ -8,6 +8,7 @@ target_link_libraries(ac-schema INTERFACE ac::dict ) target_sources(ac-schema INTERFACE FILE_SET HEADERS FILES + ac/schema/Helpers.hpp ac/schema/TupleIndexByItemId.hpp ) diff --git a/schema/code/ac/schema/Helpers.hpp b/schema/code/ac/schema/Helpers.hpp new file mode 100644 index 00000000..397a43b5 --- /dev/null +++ b/schema/code/ac/schema/Helpers.hpp @@ -0,0 +1,21 @@ +// Copyright (c) Alpaca Core +// SPDX-License-Identifier: MIT +// +#pragma once +#include +#include +#include + +namespace ac::local { + +template +auto Model_createInstance(Model& model, typename Instance::Params p) { + return model.createInstance(Instance::id, p.toDict()); +} + +template +typename Op::Return Instance_runOp(Instance& instance, typename Op::Params p, ProgressCb cb = {}) { + return Op::Return::fromDict(instance.runOp(Op::id, p.toDict(), std::move(cb))); +} + +} // namespace ac::local diff --git a/schema/code/generate-cpp-for-ac-model-schema.rb b/schema/code/generate-cpp-for-ac-model-schema.rb index 336c4500..05e0356a 100644 --- a/schema/code/generate-cpp-for-ac-model-schema.rb +++ b/schema/code/generate-cpp-for-ac-model-schema.rb @@ -129,6 +129,10 @@ def generate_struct(lines, name, data, indent) lines << "#{indent} return ret;" lines << "#{indent} }" + lines << "#{indent} static #{name.pascal_case} fromDict(Dict&& dict) {" + lines << "#{indent} return fromDict(dict);" + lines << "#{indent} }" + lines << '' lines << "#{indent} Dict toDict() {"