111 value =
static_cast<T
>(m_value);
119 return Create<EnumValue>(*
this);
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>;
192template <
typename T,
typename... Ts>
197 checker->AddDefault(v, n);
212template <
typename T,
typename... Ts>
213Ptr<const AttributeChecker>
228inline Ptr<const AttributeChecker>
234template <
typename T,
typename T1>
235Ptr<const AttributeAccessor>
238 return MakeAccessorHelper<EnumValue<T>>(a1);
241template <
typename T,
typename T1,
typename T2>
242Ptr<const AttributeAccessor>
245 return MakeAccessorHelper<EnumValue<T>>(a1, a2);
254 std::string name = p->GetName(m_value);
264 m_value = p->GetValue(value);
277 m_valueSet.emplace_front(value, name);
284 m_valueSet.emplace_back(value, name);
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?");
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;
333 const auto p =
dynamic_cast<const EnumValue<T>*
>(&value);
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());
349 return "ns3::EnumValue<" + std::string(
typeid(T).name()) +
">";
363 std::ostringstream oss;
364 bool moreValues =
false;
365 for (
const auto& i : m_valueSet)
367 oss << (moreValues ?
"|" :
"") << i.second;
377 return ns3::Create<EnumValue<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.
AttributeChecker implementation for EnumValue.
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.
void Set(T value)
Set the value.
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
T m_value
The stored value.
bool GetAccessor(T &value) const
Access the Enum value as type T.
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< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.