variant.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <string>
8 
9 #include "ngraph/ngraph_visibility.hpp"
10 #include "ngraph/node.hpp"
11 #include "ngraph/type.hpp"
12 
13 namespace ngraph
14 {
15  using VariantTypeInfo = DiscreteTypeInfo;
16 
17  class NGRAPH_API Variant
18  {
19  public:
20  virtual ~Variant();
21  virtual const VariantTypeInfo& get_type_info() const = 0;
22 
23  virtual std::shared_ptr<ngraph::Variant> init(const std::shared_ptr<ngraph::Node>& node);
24  virtual std::shared_ptr<ngraph::Variant> merge(const ngraph::NodeVector& nodes);
25  };
26 
27  template <typename VT>
28  class VariantImpl : public Variant
29  {
30  public:
31  using value_type = VT;
32 
33  VariantImpl(const value_type& value)
34  : m_value(value)
35  {
36  }
37 
38  const value_type& get() const { return m_value; }
39  value_type& get() { return m_value; }
40  void set(const value_type& value) { m_value = value; }
41 
42  protected:
43  value_type m_value;
44  };
45 
46  extern template class NGRAPH_API VariantImpl<std::string>;
47  extern template class NGRAPH_API VariantImpl<int64_t>;
48 
49  template <typename VT>
51  {
52  };
53 
54  template <>
56  {
57  public:
58  static constexpr VariantTypeInfo type_info{"Variant::std::string", 0};
59  const VariantTypeInfo& get_type_info() const override { return type_info; }
60  VariantWrapper(const value_type& value)
62  {
63  }
64  };
65 
66  template <>
68  {
69  public:
70  static constexpr VariantTypeInfo type_info{"Variant::int64_t", 0};
71  const VariantTypeInfo& get_type_info() const override { return type_info; }
72  VariantWrapper(const value_type& value)
74  {
75  }
76  };
77 } // namespace ngraph
Definition: variant.hpp:29
Definition: variant.hpp:68
Definition: variant.hpp:56
Definition: variant.hpp:51
Definition: variant.hpp:18
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27