ArmNN
 24.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) {};

References armnn::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.

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.

119 { assert(IsBool()); return m_Vals.b; }

References BackendOptions::Var::IsBool().

Referenced by armnn::HasMatchingCapability(), armnn::ParseBooleanBackendOption(), and BackendOptions::Var::ToString().

◆ AsFloat()

float AsFloat ( ) const
inline

Definition at line 122 of file BackendOptions.hpp.

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

References BackendOptions::Var::IsFloat().

Referenced by armnn::HasMatchingCapability(), and BackendOptions::Var::ToString().

◆ AsInt()

int AsInt ( ) const
inline

◆ AsString()

std::string AsString ( ) const
inline

Definition at line 123 of file BackendOptions.hpp.

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

References BackendOptions::Var::IsString().

Referenced by armnn::HasMatchingCapability(), armnn::ParseStringBackendOption(), and BackendOptions::Var::ToString().

◆ AsUnsignedInt()

unsigned int AsUnsignedInt ( ) const
inline

Definition at line 121 of file BackendOptions.hpp.

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

References BackendOptions::Var::IsUnsignedInt().

Referenced by armnn::HasMatchingCapability(), and BackendOptions::Var::ToString().

◆ IsBool()

bool IsBool ( ) const
inline

Type getters.

Definition at line 112 of file BackendOptions.hpp.

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

Referenced by BackendOptions::Var::AsBool(), armnn::HasMatchingCapability(), armnn::ParseBooleanBackendOption(), and BackendOptions::Var::ToString().

◆ IsFloat()

bool IsFloat ( ) const
inline

Definition at line 115 of file BackendOptions.hpp.

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

Referenced by BackendOptions::Var::AsFloat(), armnn::HasMatchingCapability(), and BackendOptions::Var::ToString().

◆ IsInt()

bool IsInt ( ) const
inline

◆ IsString()

bool IsString ( ) const
inline

Definition at line 116 of file BackendOptions.hpp.

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

Referenced by BackendOptions::Var::AsString(), armnn::HasMatchingCapability(), armnn::ParseStringBackendOption(), and BackendOptions::Var::ToString().

◆ IsUnsignedInt()

bool IsUnsignedInt ( ) const
inline

Definition at line 114 of file BackendOptions.hpp.

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

Referenced by BackendOptions::Var::AsUnsignedInt(), armnn::HasMatchingCapability(), and BackendOptions::Var::ToString().

◆ 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.

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  }

References BackendOptions::Var::AsBool(), BackendOptions::Var::AsFloat(), BackendOptions::Var::AsInt(), BackendOptions::Var::AsString(), BackendOptions::Var::AsUnsignedInt(), BackendOptions::Var::IsBool(), BackendOptions::Var::IsFloat(), BackendOptions::Var::IsInt(), BackendOptions::Var::IsString(), and BackendOptions::Var::IsUnsignedInt().

Referenced by OptimizerOptions::ToString(), and OptimizerOptionsOpaque::ToString().


The documentation for this class was generated from the following file:
armnn::BackendOptions::Var::AsInt
int AsInt() const
Definition: BackendOptions.hpp:120
armnn::BackendOptions::Var::AsFloat
float AsFloat() const
Definition: BackendOptions.hpp:122
armnn::BackendOptions::Var::IsUnsignedInt
bool IsUnsignedInt() const
Definition: BackendOptions.hpp:114
armnn::BackendOptions::Var::IsInt
bool IsInt() const
Definition: BackendOptions.hpp:113
armnn::BackendOptions::Var::IsString
bool IsString() const
Definition: BackendOptions.hpp:116
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::BackendOptions::Var::AsBool
bool AsBool() const
Value getters.
Definition: BackendOptions.hpp:119
armnn::BackendOptions::Var::AsUnsignedInt
unsigned int AsUnsignedInt() const
Definition: BackendOptions.hpp:121
armnn::BackendOptions::Var::AsString
std::string AsString() const
Definition: BackendOptions.hpp:123
armnn::BackendOptions::Var::IsFloat
bool IsFloat() const
Definition: BackendOptions.hpp:115
armnn::BackendOptions::Var::IsBool
bool IsBool() const
Type getters.
Definition: BackendOptions.hpp:112