diff --git a/fable/CMakeLists.txt b/fable/CMakeLists.txt index 1fb9ab765..890339bd4 100644 --- a/fable/CMakeLists.txt +++ b/fable/CMakeLists.txt @@ -24,6 +24,7 @@ add_library(${target} src/fable/confable.cpp src/fable/json.cpp src/fable/schema.cpp + src/fable/make_schema.cpp src/fable/schema/boolean.cpp src/fable/schema/number.cpp src/fable/schema/struct.cpp diff --git a/fable/include/fable/make_schema.hpp b/fable/include/fable/make_schema.hpp index 46a8ec486..0eb21e78c 100644 --- a/fable/include/fable/make_schema.hpp +++ b/fable/include/fable/make_schema.hpp @@ -100,4 +100,24 @@ auto make_schema(T* ptr, P proto, std::string&& desc) { return details::make_schema_wrapper2<T, P>::make_schema(ptr, std::move(proto), std::move(desc)); } +// Pre-Instantiate above templates for relevant datatypes + +#define FABLE_TYPES() \ + FABLE_TYPES_X(bool) \ + FABLE_TYPES_X(int8_t) \ + FABLE_TYPES_X(uint8_t) \ + FABLE_TYPES_X(int16_t) \ + FABLE_TYPES_X(uint16_t) \ + FABLE_TYPES_X(int32_t) \ + FABLE_TYPES_X(uint32_t) \ + FABLE_TYPES_X(int64_t) \ + FABLE_TYPES_X(uint64_t) \ + FABLE_TYPES_X(float) \ + FABLE_TYPES_X(double) + +#define FABLE_TYPES_X(TYPE) \ + extern template struct ::fable::schema::details::make_schema_wrapper1<TYPE>; + +FABLE_TYPES() + } // namespace fable::schema diff --git a/fable/src/fable/make_schema.cpp b/fable/src/fable/make_schema.cpp new file mode 100644 index 000000000..ae53778e1 --- /dev/null +++ b/fable/src/fable/make_schema.cpp @@ -0,0 +1,27 @@ +/* + * Copyright 2023 Robert Bosch GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include <fable/make_schema.hpp> + +namespace fable::schema { + +#define extern +FABLE_TYPES() +#undef extern + +}