ArmNN
 22.02
BackendOptions::Var Class Reference

Very basic type safe variant. More...

#include <BackendOptions.hpp>

Public Member Functions

 Var (int i)
 Constructors. More...
 
 Var (unsigned int u)
 
 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 IsUnsignedInt () const
 
bool IsFloat () const
 
bool IsString () const
 
bool AsBool () const
 Value getters. More...
 
int AsInt () const
 
unsigned int AsUnsignedInt () const
 
float AsFloat () const
 
std::string AsString () const
 
std::string ToString ()
 
 ~Var ()
 Destructor. More...
 

Detailed Description

Very basic type safe variant.

Definition at line 38 of file BackendOptions.hpp.

Constructor & Destructor Documentation

◆ Var() [1/8]

Var ( int  i)
inlineexplicit

Constructors.

Definition at line 43 of file BackendOptions.hpp.

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

◆ Var() [2/8]

Var ( unsigned int  u)
inlineexplicit

Definition at line 44 of file BackendOptions.hpp.

44 : m_Vals(u), m_Type(VarTypes::UnsignedInteger) {};

◆ Var() [3/8]

Var ( float  f)
inlineexplicit

Definition at line 45 of file BackendOptions.hpp.

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

◆ Var() [4/8]

Var ( bool  b)
inlineexplicit

Definition at line 46 of file BackendOptions.hpp.

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

◆ Var() [5/8]

Var ( const char *  s)
inlineexplicit

Definition at line 47 of file BackendOptions.hpp.

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

◆ Var() [6/8]

Var ( std::string  s)
inlineexplicit

Definition at line 48 of file BackendOptions.hpp.

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

◆ Var() [7/8]

Var ( DisallowedType  )
inline

Disallow implicit conversions from types not explicitly allowed below.

Definition at line 52 of file BackendOptions.hpp.

53  {
54  static_assert(CheckAllowed<DisallowedType>::value, "Type is not allowed for Var<DisallowedType>.");
55  assert(false && "Unreachable code");
56  }

◆ Var() [8/8]

Var ( const Var other)
inline

Copy Construct.

Definition at line 59 of file BackendOptions.hpp.

60  : m_Type(other.m_Type)
61  {
62  switch(m_Type)
63  {
64  case VarTypes::String:
65  {
66  new (&m_Vals.s) std::string(other.m_Vals.s);
67  break;
68  }
69  default:
70  {
71  DoOp(other, [](auto& a, auto& b)
72  {
73  a = b;
74  });
75  break;
76  }
77  }
78  }

◆ ~Var()

~Var ( )
inline

Destructor.

Definition at line 138 of file BackendOptions.hpp.

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

139  {
140  DoOp(*this, [this](auto& a, auto&)
141  {
142  Destruct(a);
143  });
144  }

Member Function Documentation

◆ AsBool()

bool AsBool ( ) const
inline

Value getters.

Definition at line 119 of file BackendOptions.hpp.

Referenced by armnn::HasCapability(), armnn::ParseBoolean(), and armnn::ParseBooleanBackendOption().

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

◆ AsFloat()

float AsFloat ( ) const
inline

Definition at line 122 of file BackendOptions.hpp.

Referenced by armnn::HasCapability().

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

◆ AsInt()

int AsInt ( ) const
inline

Definition at line 120 of file BackendOptions.hpp.

Referenced by armnn::HasCapability(), armnn::ParseIntBackendOption(), and armnn::ParseTuningLevel().

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

◆ AsString()

std::string AsString ( ) const
inline

Definition at line 123 of file BackendOptions.hpp.

Referenced by armnn::HasCapability(), armnn::ParseFile(), and armnn::ParseStringBackendOption().

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

◆ AsUnsignedInt()

unsigned int AsUnsignedInt ( ) const
inline

Definition at line 121 of file BackendOptions.hpp.

Referenced by armnn::HasCapability().

121 { assert(IsUnsignedInt()); return m_Vals.u; }

◆ IsBool()

bool IsBool ( ) const
inline

Type getters.

Definition at line 112 of file BackendOptions.hpp.

References armnn::Boolean.

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

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

◆ IsFloat()

bool IsFloat ( ) const
inline

Definition at line 115 of file BackendOptions.hpp.

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

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

◆ IsInt()

bool IsInt ( ) const
inline

Definition at line 113 of file BackendOptions.hpp.

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

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

◆ IsString()

bool IsString ( ) const
inline

Definition at line 116 of file BackendOptions.hpp.

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

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

◆ IsUnsignedInt()

bool IsUnsignedInt ( ) const
inline

Definition at line 114 of file BackendOptions.hpp.

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

114 { return m_Type == VarTypes::UnsignedInteger; }

◆ operator=()

Var& operator= ( const Var other)
inline

Copy operator.

Definition at line 81 of file BackendOptions.hpp.

82  {
83  // Destroy existing string
84  if (m_Type == VarTypes::String)
85  {
86  Destruct(m_Vals.s);
87  }
88 
89  m_Type = other.m_Type;
90  switch(m_Type)
91  {
92  case VarTypes::String:
93  {
94 
95  new (&m_Vals.s) std::string(other.m_Vals.s);
96  break;
97  }
98  default:
99  {
100  DoOp(other, [](auto& a, auto& b)
101  {
102  a = b;
103  });
104  break;
105  }
106  }
107 
108  return *this;
109  };

◆ ToString()

std::string ToString ( )
inline

Definition at line 124 of file BackendOptions.hpp.

Referenced by OptimizerOptions::ToString().

125  {
126  if (IsBool()) { return AsBool() ? "true" : "false"; }
127  else if (IsInt()) { return std::to_string(AsInt()); }
128  else if (IsUnsignedInt()) { return std::to_string(AsUnsignedInt()); }
129  else if (IsFloat()) { return std::to_string(AsFloat()); }
130  else if (IsString()) { return AsString(); }
131  else
132  {
133  throw armnn::InvalidArgumentException("Unknown data type for string conversion");
134  }
135  }
std::string AsString() const
unsigned int AsUnsignedInt() const
bool AsBool() const
Value getters.
bool IsBool() const
Type getters.

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