1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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 //*****************************************************************************
21 #include "ngraph/ngraph_visibility.hpp"
22 #include "ngraph/node.hpp"
23 #include "ngraph/type.hpp"
27 using VariantTypeInfo = DiscreteTypeInfo;
29 class NGRAPH_API Variant
33 virtual const VariantTypeInfo& get_type_info() const = 0;
35 virtual std::shared_ptr<ngraph::Variant> init(const std::shared_ptr<ngraph::Node>& node);
36 virtual std::shared_ptr<ngraph::Variant> merge(const ngraph::NodeVector& nodes);
39 template <typename VT>
40 class VariantImpl : public Variant
43 using value_type = VT;
45 VariantImpl(const value_type& value)
50 const value_type& get() const { return m_value; }
51 value_type& get() { return m_value; }
52 void set(const value_type& value) { m_value = value; }
57 extern template class NGRAPH_API VariantImpl<std::string>;
58 extern template class NGRAPH_API VariantImpl<int64_t>;
60 template <typename VT>
66 class NGRAPH_API VariantWrapper<std::string> : public VariantImpl<std::string>
69 static constexpr VariantTypeInfo type_info{"Variant::std::string", 0};
70 const VariantTypeInfo& get_type_info() const override { return type_info; }
71 VariantWrapper(const value_type& value)
72 : VariantImpl<value_type>(value)
78 class NGRAPH_API VariantWrapper<int64_t> : public VariantImpl<int64_t>
81 static constexpr VariantTypeInfo type_info{"Variant::int64_t", 0};
82 const VariantTypeInfo& get_type_info() const override { return type_info; }
83 VariantWrapper(const value_type& value)
84 : VariantImpl<value_type>(value)