1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef FCP_AGGREGATION_CORE_TENSOR_AGGREGATOR_REGISTRY_H_ 18 #define FCP_AGGREGATION_CORE_TENSOR_AGGREGATOR_REGISTRY_H_ 19 20 #include <string> 21 22 #include "fcp/aggregation/core/tensor_aggregator_factory.h" 23 24 namespace fcp { 25 namespace aggregation { 26 27 // Registers a factory instance for the given intrinsic type. 28 void RegisterAggregatorFactory(const std::string& intrinsic_uri, 29 const TensorAggregatorFactory* factory); 30 31 // Looks up a factory instance for the given intrinsic type. 32 StatusOr<const TensorAggregatorFactory*> GetAggregatorFactory( 33 const std::string& intrinsic_uri); 34 35 namespace internal { 36 37 template <typename FactoryType> 38 struct Registrar { RegistrarRegistrar39 explicit Registrar(const std::string& intrinsic_uri) { 40 RegisterAggregatorFactory(intrinsic_uri, new FactoryType()); 41 } 42 }; 43 44 } // namespace internal 45 46 // This macro is used to register a factory type with the intrinsic uri. 47 #define REGISTER_AGGREGATOR_FACTORY(intrinsic_uri, FactoryType) \ 48 static auto unused = \ 49 ::fcp::aggregation::internal::Registrar<FactoryType>(intrinsic_uri); 50 51 } // namespace aggregation 52 } // namespace fcp 53 54 #endif // FCP_AGGREGATION_CORE_TENSOR_AGGREGATOR_REGISTRY_H_ 55