ArmNN
 20.02
BackendOptions::Var Class Reference

Very basic type safe variant. More...

#include <BackendOptions.hpp>

Public Member Functions

 Var (int i)
 Constructors. More...
 
 Var (float f)
 
 Var (bool b)
 
 Var (const char *s)
 
 Var (std::string s)
 
template<typename DisallowedType >
 Var (DisallowedType)
 Disallow implicit conversions from types not explicitly allowed below. More...
 
 Var (const Var &other)
 Copy Construct. More...
 
Varoperator= (const Var &other)
 Copy operator. More...
 
bool IsBool () const
 Type getters. More...
 
bool IsInt () const
 
bool IsFloat () const
 
bool IsString () const
 
bool AsBool () const
 Value getters. More...
 
int AsInt () const
 
float AsFloat () const
 
std::string AsString () const
 
 ~Var ()
 Destructor. More...
 

Detailed Description

Very basic type safe variant.

Definition at line 31 of file BackendOptions.hpp.

Constructor & Destructor Documentation

◆ Var() [1/7]

Var ( int  i)
inlineexplicit

Constructors.

Definition at line 36 of file BackendOptions.hpp.

36 : m_Vals(i), m_Type(VarTypes::Integer) {};

◆ Var() [2/7]

Var ( float  f)
inlineexplicit

Definition at line 37 of file BackendOptions.hpp.

37 : m_Vals(f), m_Type(VarTypes::Float) {};

◆ Var() [3/7]

Var ( bool  b)
inlineexplicit

Definition at line 38 of file BackendOptions.hpp.

38 : m_Vals(b), m_Type(VarTypes::Boolean) {};

◆ Var() [4/7]

Var ( const char *  s)
inlineexplicit

Definition at line 39 of file BackendOptions.hpp.

39 : m_Vals(s), m_Type(VarTypes::String) {};

◆ Var() [5/7]

Var ( std::string  s)
inlineexplicit

Definition at line 40 of file BackendOptions.hpp.

40 : m_Vals(s), m_Type(VarTypes::String) {};

◆ Var() [6/7]

Var ( DisallowedType  )
inline

Disallow implicit conversions from types not explicitly allowed below.

Definition at line 44 of file BackendOptions.hpp.

45  {
46  static_assert(CheckAllowed<DisallowedType>::value, "Type is not allowed for Var<DisallowedType>.");
47  assert(false && "Unreachable code");
48  }

◆ Var() [7/7]

Var ( const Var other)
inline

Copy Construct.

Definition at line 51 of file BackendOptions.hpp.

52  : m_Type(other.m_Type)
53  {
54  switch(m_Type)
55  {
56  case VarTypes::String:
57  {
58  new (&m_Vals.s) std::string(other.m_Vals.s);
59  break;
60  }
61  default:
62  {
63  DoOp(other, [](auto& a, auto& b)
64  {
65  a = b;
66  });
67  break;
68  }
69  }
70  }

◆ ~Var()

~Var ( )
inline

Destructor.

Definition at line 116 of file BackendOptions.hpp.

References armnn::Boolean, BackendOptions::Var::IsBool(), BackendOptions::Var::IsFloat(), BackendOptions::Var::IsInt(), and BackendOptions::Var::IsString().

117  {
118  DoOp(*this, [this](auto& a, auto&)
119  {
120  Destruct(a);
121  });
122  }

Member Function Documentation

◆ AsBool()

bool AsBool ( ) const
inline

Value getters.

Definition at line 110 of file BackendOptions.hpp.

Referenced by armnn::ParseBoolean().

110 { assert(IsBool()); return m_Vals.b; }
bool IsBool() const
Type getters.

◆ AsFloat()

float AsFloat ( ) const
inline

Definition at line 112 of file BackendOptions.hpp.

112 { assert(IsFloat()); return m_Vals.f; }

◆ AsInt()

int AsInt ( ) const
inline

Definition at line 111 of file BackendOptions.hpp.

111 { assert(IsInt()); return m_Vals.i; }

◆ AsString()

std::string AsString ( ) const
inline

Definition at line 113 of file BackendOptions.hpp.

Referenced by armnn::ParseFile().

113 { assert(IsString()); return m_Vals.s; }

◆ IsBool()

bool IsBool ( ) const
inline

Type getters.

Definition at line 104 of file BackendOptions.hpp.

References armnn::Boolean.

Referenced by armnn::ParseBoolean(), and BackendOptions::Var::~Var().

104 { return m_Type == VarTypes::Boolean; }

◆ IsFloat()

bool IsFloat ( ) const
inline

Definition at line 106 of file BackendOptions.hpp.

Referenced by BackendOptions::Var::~Var().

106 { return m_Type == VarTypes::Float; }

◆ IsInt()

bool IsInt ( ) const
inline

Definition at line 105 of file BackendOptions.hpp.

Referenced by armnn::ParseTuningLevel(), and BackendOptions::Var::~Var().

105 { return m_Type == VarTypes::Integer; }

◆ IsString()

bool IsString ( ) const
inline

Definition at line 107 of file BackendOptions.hpp.

Referenced by armnn::ParseFile(), and BackendOptions::Var::~Var().

107 { return m_Type == VarTypes::String; }

◆ operator=()

Var& operator= ( const Var other)
inline

Copy operator.

Definition at line 73 of file BackendOptions.hpp.

74  {
75  // Destroy existing string
76  if (m_Type == VarTypes::String)
77  {
78  Destruct(m_Vals.s);
79  }
80 
81  m_Type = other.m_Type;
82  switch(m_Type)
83  {
84  case VarTypes::String:
85  {
86 
87  new (&m_Vals.s) std::string(other.m_Vals.s);
88  break;
89  }
90  default:
91  {
92  DoOp(other, [](auto& a, auto& b)
93  {
94  a = b;
95  });
96  break;
97  }
98  }
99 
100  return *this;
101  };

The documentation for this class was generated from the following file: