variant.hpp
1 //*****************************************************************************
2 // Copyright 2017-2021 Intel Corporation
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 #pragma once
18 
19 #include <string>
20 
21 #include "ngraph/ngraph_visibility.hpp"
22 #include "ngraph/node.hpp"
23 #include "ngraph/type.hpp"
24 
25 namespace ngraph
26 {
27  using VariantTypeInfo = DiscreteTypeInfo;
28 
29  class NGRAPH_API Variant
30  {
31  public:
32  virtual ~Variant();
33  virtual const VariantTypeInfo& get_type_info() const = 0;
34 
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);
37  };
38 
39  template <typename VT>
40  class VariantImpl : public Variant
41  {
42  public:
43  using value_type = VT;
44 
45  VariantImpl(const value_type& value)
46  : m_value(value)
47  {
48  }
49 
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; }
53  protected:
54  value_type m_value;
55  };
56 
57  extern template class NGRAPH_API VariantImpl<std::string>;
58  extern template class NGRAPH_API VariantImpl<int64_t>;
59 
60  template <typename VT>
62  {
63  };
64 
65  template <>
67  {
68  public:
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)
73  {
74  }
75  };
76 
77  template <>
79  {
80  public:
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)
85  {
86  }
87  };
88 }
Definition: variant.hpp:41
Definition: variant.hpp:79
Definition: variant.hpp:67
Definition: variant.hpp:62
Definition: variant.hpp:30
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39