14 struct BackendOptions;
24 static const bool value = std::is_same<T, int>::value ||
25 std::is_same<T, float>::value ||
26 std::is_same<T, bool>::value ||
27 std::is_same<T, std::string>::value ||
28 std::is_same<T, const char*>::value;
38 explicit Var(
int i) : m_Vals(i), m_Type(VarTypes::Integer) {};
39 explicit Var(
float f) : m_Vals(f), m_Type(VarTypes::Float) {};
40 explicit Var(
bool b) : m_Vals(b), m_Type(VarTypes::
Boolean) {};
41 explicit Var(
const char* s) : m_Vals(s), m_Type(VarTypes::String) {};
42 explicit Var(std::string s) : m_Vals(s), m_Type(VarTypes::String) {};
45 template<
typename DisallowedType>
48 static_assert(CheckAllowed<DisallowedType>::value,
"Type is not allowed for Var<DisallowedType>.");
49 assert(
false &&
"Unreachable code");
54 : m_Type(other.m_Type)
58 case VarTypes::String:
60 new (&m_Vals.s) std::string(other.m_Vals.s);
65 DoOp(other, [](
auto& a,
auto& b)
78 if (m_Type == VarTypes::String)
83 m_Type = other.m_Type;
86 case VarTypes::String:
89 new (&m_Vals.s) std::string(other.m_Vals.s);
94 DoOp(other, [](
auto& a,
auto& b)
107 bool IsInt()
const {
return m_Type == VarTypes::Integer; }
108 bool IsFloat()
const {
return m_Type == VarTypes::Float; }
109 bool IsString()
const {
return m_Type == VarTypes::String; }
112 bool AsBool()
const { assert(IsBool());
return m_Vals.b; }
113 int AsInt()
const { assert(IsInt());
return m_Vals.i; }
114 float AsFloat()
const { assert(IsFloat());
return m_Vals.f; }
115 std::string
AsString()
const { assert(IsString());
return m_Vals.s; }
120 DoOp(*
this, [
this](
auto& a,
auto&)
126 template<
typename Func>
127 void DoOp(
const Var& other, Func func)
131 func(m_Vals.b, other.m_Vals.b);
133 else if (other.
IsInt())
135 func(m_Vals.i, other.m_Vals.i);
139 func(m_Vals.f, other.m_Vals.f);
143 func(m_Vals.s, other.m_Vals.s);
147 template<
typename Destructable>
148 void Destruct(Destructable& d)
150 if (std::is_destructible<Destructable>::value)
177 explicit Vals(
int i) : i(i) {};
178 explicit Vals(
float f) : f(f) {};
179 explicit Vals(
bool b) : b(b) {};
180 explicit Vals(
const char* s) : s(std::string(s)) {}
181 explicit Vals(std::string s) : s(s) {}
192 : m_Name(name), m_Value(value)
195 : m_Name(name), m_Value(value)
198 : m_Name(name), m_Value(value)
201 : m_Name(name), m_Value(value)
204 : m_Name(name), m_Value(value)
207 template<
typename DisallowedType>
211 static_assert(CheckAllowed<DisallowedType>::value,
"Type is not allowed for BackendOption.");
212 assert(
false &&
"Unreachable code");
221 std::string
GetName()
const {
return m_Name; }
230 : m_TargetBackend(backend)
234 : m_TargetBackend(backend)
245 m_Options.push_back(option);
250 m_Options.push_back(option);
262 std::vector<BackendOption> m_Options;
const BackendOption & GetOption(size_t idx) const
BackendOptions(BackendId backend, std::initializer_list< BackendOption > options)
Very basic type safe variant.
BackendOption(std::string name, bool value)
Var(const Var &other)
Copy Construct.
std::vector< BackendOptions > NetworkOptions
Copyright (c) 2020 ARM Limited.
BackendOptions(BackendId backend)
size_t GetOptionCount() const noexcept
void AddOption(BackendOption &&option)
Var & operator=(const Var &other)
Copy operator.
BackendOption(std::string name, int value)
std::string AsString() const
Var(DisallowedType)
Disallow implicit conversions from types not explicitly allowed below.
BackendOptions & operator=(const BackendOptions &other)=default
Struct for the users to pass backend specific options.
void AddOption(const BackendOption &option)
bool AsBool() const
Value getters.
std::string GetName() const
bool IsBool() const
Type getters.
BackendOption(std::string name, float value)
BackendOption(std::string name, const char *value)
BackendOption(std::string, DisallowedType)
const BackendId & GetBackendId() const noexcept
BackendOption(std::string name, std::string value)