96 value =
static_cast<T
>(m_value);
124 void Add(T value, std::string name);
131 std::string
GetName(T value)
const;
138 T
GetValue(
const std::string name)
const;
150 using Value = std::pair<T, std::string>;
177template <
typename T,
typename... Ts>
182 checker->AddDefault(v, n);
197template <
typename T,
typename... Ts>
198Ptr<const AttributeChecker>
213inline Ptr<const AttributeChecker>
219template <
typename T,
typename T1>
220Ptr<const AttributeAccessor>
226template <
typename T,
typename T1,
typename T2>
227Ptr<const AttributeAccessor>
239 std::string name = p->GetName(m_value);
249 m_value = p->GetValue(value);
262 m_valueSet.emplace_front(value, name);
269 m_valueSet.emplace_back(value, name);
276 auto it = std::find_if(m_valueSet.begin(), m_valueSet.end(), [value](
Value v) {
277 return v.first == value;
281 "invalid enum value " <<
static_cast<int>(value)
282 <<
"! Missed entry in MakeEnumChecker?");
290 auto it = std::find_if(m_valueSet.begin(), m_valueSet.end(), [name](
Value v) {
291 return v.second == name;
294 it != m_valueSet.end(),
297 <<
" is not a valid enum value. Missed entry in MakeEnumChecker?\nAvailable values: "
298 << std::accumulate(m_valueSet.begin(),
301 [](std::string a,
Value v) {
308 return std::move(a) +
", " + v.second;
318 const auto p =
dynamic_cast<const EnumValue<T>*
>(&value);
323 auto pvalue = p->
Get();
324 auto it = std::find_if(m_valueSet.begin(), m_valueSet.end(), [pvalue](
Value v) {
325 return v.first == pvalue;
327 return (it != m_valueSet.end());
334 return "ns3::EnumValue<" +
Demangle(
typeid(T).name()) +
">";
348 std::ostringstream oss;
349 bool moreValues =
false;
350 for (
const auto& i : m_valueSet)
352 oss << (moreValues ?
"|" :
"") << i.second;
369 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< const AttributeAccessor > MakeAccessorHelper(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
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.
U * PeekPointer(const Ptr< U > &p)
std::string Demangle(const std::string &mangled)
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)