29 #include <type_traits>
100 template <
typename T>
107 template <
typename T>
111 value =
static_cast<T
>(m_value);
115 template <
typename T>
119 return Create<EnumValue>(*
this);
122 template <
typename T>
139 void Add(T value, std::string name);
146 std::string
GetName(T value)
const;
153 T
GetValue(
const std::string name)
const;
165 using Value = std::pair<T, std::string>;
192 template <
typename T,
typename... Ts>
197 checker->AddDefault(v, n);
212 template <
typename T,
typename... Ts>
213 Ptr<const AttributeChecker>
227 template <
typename T>
228 inline Ptr<const AttributeChecker>
234 template <
typename T,
typename T1>
235 Ptr<const AttributeAccessor>
238 return MakeAccessorHelper<EnumValue<T>>(a1);
241 template <
typename T,
typename T1,
typename T2>
242 Ptr<const AttributeAccessor>
245 return MakeAccessorHelper<EnumValue<T>>(a1, a2);
248 template <
typename T>
254 std::string name = p->GetName(m_value);
258 template <
typename T>
264 m_value = p->GetValue(value);
268 template <
typename T>
273 template <
typename T>
277 m_valueSet.emplace_front(value, name);
280 template <
typename T>
284 m_valueSet.emplace_back(value, name);
287 template <
typename T>
291 auto it = std::find_if(m_valueSet.begin(), m_valueSet.end(), [value](
Value v) {
292 return v.first == value;
296 "invalid enum value " <<
static_cast<int>(value)
297 <<
"! Missed entry in MakeEnumChecker?");
301 template <
typename T>
305 auto it = std::find_if(m_valueSet.begin(), m_valueSet.end(), [name](
Value v) {
306 return v.second == name;
309 it != m_valueSet.end(),
312 <<
" is not a valid enum value. Missed entry in MakeEnumChecker?\nAvailable values: "
313 << std::accumulate(m_valueSet.begin(),
316 [](std::string a,
Value v) {
323 return std::move(a) +
", " + v.second;
329 template <
typename T>
338 auto pvalue = p->
Get();
339 auto it = std::find_if(m_valueSet.begin(), m_valueSet.end(), [pvalue](
Value v) {
340 return v.first == pvalue;
342 return (it != m_valueSet.end());
345 template <
typename T>
349 return "ns3::EnumValue<" + std::string(
typeid(T).name()) +
">";
352 template <
typename T>
359 template <
typename T>
363 std::ostringstream oss;
364 bool moreValues =
false;
365 for (
const auto& i : m_valueSet)
367 oss << (moreValues ?
"|" :
"") << i.second;
373 template <
typename T>
377 return ns3::Create<EnumValue<T>>();
380 template <
typename T>
384 const auto src =
dynamic_cast<const EnumValue<T>*
>(&source);
ns3::MakeAccessorHelper declarations and template implementations.
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Represent the type of an attribute.
Hold a value for an Attribute.
Ptr< AttributeValue > Create() const override
void Add(T value, std::string name)
Add a new value.
bool HasUnderlyingTypeInformation() const override
std::list< Value > ValueSet
Type of container for storing Enum values and symbol names.
std::string GetName(T value) const
Get the enum symbol name by value.
bool Copy(const AttributeValue &src, AttributeValue &dst) const override
Copy the source to the destination.
void AddDefault(T value, std::string name)
Add a default value.
std::string GetValueTypeName() const override
T GetValue(const std::string name) const
Get the enum value by name.
bool Check(const AttributeValue &value) const override
std::pair< T, std::string > Value
Type for the pair value, name.
ValueSet m_valueSet
The stored Enum values and symbol names.
std::string GetUnderlyingTypeInformation() const override
Hold variables of type enum.
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
T m_value
The stored value.
bool GetAccessor(T &value) const
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Ptr< AttributeValue > Copy() const override
Smart pointer class similar to boost::intrusive_ptr.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
U * PeekPointer(const Ptr< U > &p)
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.