ArmNN
 25.11
Loading...
Searching...
No Matches
BackendOptions::Var Class Reference

Very basic type safe variant. More...

#include <BackendOptions.hpp>

Public Member Functions

 Var (int i)
 Constructors.
 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.
 Var (const Var &other)
 Copy Construct.
Varoperator= (const Var &other)
 Copy operator.
bool IsBool () const
 Type getters.
bool IsInt () const
bool IsUnsignedInt () const
bool IsFloat () const
bool IsString () const
bool AsBool () const
 Value getters.
int AsInt () const
unsigned int AsUnsignedInt () const
float AsFloat () const
std::string AsString () const
std::string ToString ()
 ~Var ()
 Destructor.

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

Referenced by operator=(), and Var().

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

template<typename DisallowedType>
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 }

References Var().

◆ ~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 IsBool().

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

◆ AsFloat()

float AsFloat ( ) const
inline

Definition at line 122 of file BackendOptions.hpp.

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

References IsFloat().

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

◆ AsInt()

int AsInt ( ) const
inline

Definition at line 120 of file BackendOptions.hpp.

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

References IsInt().

Referenced by armnn::HasMatchingCapability(), armnn::ParseIntBackendOption(), armnn::ParseTuningLevel(), and ToString().

◆ AsString()

std::string AsString ( ) const
inline

Definition at line 123 of file BackendOptions.hpp.

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

References IsString().

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

◆ AsUnsignedInt()

unsigned int AsUnsignedInt ( ) const
inline

Definition at line 121 of file BackendOptions.hpp.

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

References IsUnsignedInt().

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

◆ IsBool()

bool IsBool ( ) const
inline

Type getters.

Definition at line 112 of file BackendOptions.hpp.

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

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

◆ IsFloat()

bool IsFloat ( ) const
inline

Definition at line 115 of file BackendOptions.hpp.

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

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

◆ IsInt()

bool IsInt ( ) const
inline

Definition at line 113 of file BackendOptions.hpp.

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

Referenced by AsInt(), armnn::HasMatchingCapability(), armnn::ParseIntBackendOption(), armnn::ParseTuningLevel(), and ToString().

◆ IsString()

bool IsString ( ) const
inline

Definition at line 116 of file BackendOptions.hpp.

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

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

◆ IsUnsignedInt()

bool IsUnsignedInt ( ) const
inline

Definition at line 114 of file BackendOptions.hpp.

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

Referenced by AsUnsignedInt(), armnn::HasMatchingCapability(), and 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 };

References Var().

◆ 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 AsBool(), AsFloat(), AsInt(), AsString(), AsUnsignedInt(), IsBool(), IsFloat(), IsInt(), IsString(), and IsUnsignedInt().

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


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