106 value =
static_cast<T
>(m_value);
114 return Create<EnumValue>(*
this);
134 void Add(T value, std::string name);
141 std::string
GetName(T value)
const;
148 T
GetValue(
const std::string name)
const;
160 using Value = std::pair<T, std::string>;
187template <
typename T,
typename... Ts>
192 checker->AddDefault(v, n);
207template <
typename T,
typename... Ts>
208Ptr<const AttributeChecker>
223inline Ptr<const AttributeChecker>
229template <
typename T,
typename T1>
230Ptr<const AttributeAccessor>
233 return MakeAccessorHelper<EnumValue<T>>(a1);
236template <
typename T,
typename T1,
typename T2>
237Ptr<const AttributeAccessor>
240 return MakeAccessorHelper<EnumValue<T>>(a1, a2);
249 std::string name = p->GetName(m_value);
259 m_value = p->GetValue(value);
272 m_valueSet.emplace_front(value, name);
279 m_valueSet.emplace_back(value, name);
286 auto it = std::find_if(m_valueSet.begin(), m_valueSet.end(), [value](
Value v) {
287 return v.first == value;
291 "invalid enum value " <<
static_cast<int>(value)
292 <<
"! Missed entry in MakeEnumChecker?");
300 auto it = std::find_if(m_valueSet.begin(), m_valueSet.end(), [name](
Value v) {
301 return v.second == name;
304 it != m_valueSet.end(),
307 <<
" is not a valid enum value. Missed entry in MakeEnumChecker?\nAvailable values: "
308 << std::accumulate(m_valueSet.begin(),
311 [](std::string a,
Value v) {
318 return std::move(a) +
", " + v.second;
328 const auto p =
dynamic_cast<const EnumValue<T>*
>(&value);
333 auto pvalue = p->
Get();
334 auto it = std::find_if(m_valueSet.begin(), m_valueSet.end(), [pvalue](
Value v) {
335 return v.first == pvalue;
337 return (it != m_valueSet.end());
344 return "ns3::EnumValue<" + std::string(
typeid(T).name()) +
">";
358 std::ostringstream oss;
359 bool moreValues =
false;
360 for (
const auto& i : m_valueSet)
362 oss << (moreValues ?
"|" :
"") << i.second;
372 return ns3::Create<EnumValue<T>>();
379 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...
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.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)