A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::EnumValue Class Reference

Hold variables of type enum. More...

#include "enum.h"

+ Inheritance diagram for ns3::EnumValue:
+ Collaboration diagram for ns3::EnumValue:

Public Member Functions

 EnumValue ()
 
 EnumValue (int value)
 Construct from an explicit value.
 
Ptr< AttributeValueCopy () const override
 
bool DeserializeFromString (std::string value, Ptr< const AttributeChecker > checker) override
 
int Get () const
 
template<typename T >
bool GetAccessor (T &value) const
 Access the Enum value as type T.
 
std::string SerializeToString (Ptr< const AttributeChecker > checker) const override
 
void Set (int value)
 Set the value.
 
- Public Member Functions inherited from ns3::AttributeValue
 AttributeValue ()
 
virtual ~AttributeValue ()
 
virtual Ptr< AttributeValueCopy () const =0
 
virtual bool DeserializeFromString (std::string value, Ptr< const AttributeChecker > checker)=0
 
virtual std::string SerializeToString (Ptr< const AttributeChecker > checker) const =0
 
- Public Member Functions inherited from ns3::SimpleRefCount< AttributeValue >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 

Private Attributes

int m_value
 The stored integer value.
 

Detailed Description

Hold variables of type enum.

AttributeValue implementation for Enum.

This class can be used to hold variables of any kind of enum.

This is often used with ObjectFactory and Config to bind the value of a particular enum to an Attribute or Config name. For example,

Ptr<RateErrorModel> model = CreateObjectWithAttributes<RateErrorModel> (
"ErrorRate", DoubleValue (0.05),
Config::SetDefault ("ns3::RipNg::SplitHorizon",
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold variables of type enum.
Definition: enum.h:56
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
@ NO_SPLIT_HORIZON
No Split Horizon.
Definition: ripng.h:224
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:891
See also
AttributeValue

Definition at line 55 of file enum.h.

Constructor & Destructor Documentation

◆ EnumValue() [1/2]

ns3::EnumValue::EnumValue ( )

Definition at line 39 of file enum.cc.

References NS_LOG_FUNCTION.

◆ EnumValue() [2/2]

ns3::EnumValue::EnumValue ( int  value)

Construct from an explicit value.

Parameters
[in]valueThe value to begin with.

Definition at line 45 of file enum.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ Copy()

Ptr< AttributeValue > ns3::EnumValue::Copy ( ) const
overridevirtual
Returns
a deep copy of this class, wrapped into an Attribute object.

Implements ns3::AttributeValue.

Definition at line 66 of file enum.cc.

References NS_LOG_FUNCTION.

◆ DeserializeFromString()

bool ns3::EnumValue::DeserializeFromString ( std::string  value,
Ptr< const AttributeChecker checker 
)
overridevirtual
Parameters
[in]valueA string representation of the value
[in]checkerA pointer to the checker associated to the attribute.
Returns
true if the input string was correctly-formatted and could be successfully deserialized, false otherwise.

Upon return of this function, this AttributeValue instance contains the deserialized value. In most cases, this method will not make any use of the checker argument. However, in a very limited set of cases, the checker argument is needed to perform proper serialization. A nice example of code which needs it is the EnumValue::SerializeToString code.

Implements ns3::AttributeValue.

Definition at line 83 of file enum.cc.

References ns3::EnumChecker::GetValue(), m_value, NS_ASSERT, NS_LOG_FUNCTION, and ns3::PeekPointer().

+ Here is the call graph for this function:

◆ Get()

int ns3::EnumValue::Get ( ) const
Returns
The Enum value.

Definition at line 59 of file enum.cc.

References m_value, and NS_LOG_FUNCTION.

Referenced by ns3::EnumChecker::Check(), and ns3::LteHelper::InstallSingleEnbDevice().

+ Here is the caller graph for this function:

◆ GetAccessor()

template<typename T >
bool ns3::EnumValue::GetAccessor ( T &  value) const

Access the Enum value as type T.

Template Parameters
T[explicit] The type to cast to.
Parameters
[out]valueThe Enum value, as type T.
Returns
true.

Definition at line 80 of file enum.h.

References m_value.

◆ SerializeToString()

std::string ns3::EnumValue::SerializeToString ( Ptr< const AttributeChecker checker) const
overridevirtual
Parameters
[in]checkerThe checker associated to the attribute
Returns
A string representation of this value.

In most cases, this method will not make any use of the checker argument. However, in a very limited set of cases, the checker argument is needed to perform proper serialization. A nice example of code which needs it is the EnumValue::SerializeToString code.

Implements ns3::AttributeValue.

Definition at line 73 of file enum.cc.

References ns3::EnumChecker::GetName(), m_value, NS_ASSERT, NS_LOG_FUNCTION, and ns3::PeekPointer().

+ Here is the call graph for this function:

◆ Set()

void ns3::EnumValue::Set ( int  value)

Set the value.

Parameters
[in]valueThe value to adopt.

Definition at line 52 of file enum.cc.

References m_value, and NS_LOG_FUNCTION.

Member Data Documentation

◆ m_value

int ns3::EnumValue::m_value
private

The stored integer value.

The stored Enum instance.

Definition at line 75 of file enum.h.

Referenced by DeserializeFromString(), Get(), GetAccessor(), SerializeToString(), and Set().


The documentation for this class was generated from the following files: