a replacement for ClassIdDefaultValue
This commit is contained in:
94
src/core/interface-id-default-value.cc
Normal file
94
src/core/interface-id-default-value.cc
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "interface-id-default-value.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
InterfaceIdDefaultValue::InterfaceIdDefaultValue (std::string name,
|
||||
std::string help,
|
||||
InterfaceId iid,
|
||||
std::string defaultValue)
|
||||
: DefaultValueBase (name, help),
|
||||
m_defaultName (defaultValue),
|
||||
m_name (defaultValue),
|
||||
m_interfaceId (iid)
|
||||
{
|
||||
DefaultValueList::Add (this);
|
||||
}
|
||||
InterfaceId
|
||||
InterfaceIdDefaultValue::GetValue (void) const
|
||||
{
|
||||
return InterfaceId::LookupByName (m_name);
|
||||
}
|
||||
void
|
||||
InterfaceIdDefaultValue::SetValue (InterfaceId interfaceId)
|
||||
{
|
||||
m_name = interfaceId.GetName ();
|
||||
}
|
||||
void
|
||||
InterfaceIdDefaultValue::SetValue (std::string name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
bool
|
||||
InterfaceIdDefaultValue::DoParseValue (const std::string &value)
|
||||
{
|
||||
for (uint32_t i = 0; i < InterfaceId::GetRegisteredN (); i++)
|
||||
{
|
||||
InterfaceId iid = InterfaceId::GetRegistered (i);
|
||||
do {
|
||||
if (iid.GetName () == value &&
|
||||
iid.HasConstructor ())
|
||||
{
|
||||
// check that it really supports the requested interface.
|
||||
InterfaceId tmp = iid;
|
||||
do {
|
||||
if (tmp == m_interfaceId)
|
||||
{
|
||||
m_name = value;
|
||||
return true;
|
||||
}
|
||||
} while (tmp != Object::iid ());
|
||||
}
|
||||
iid = iid.GetParent ();
|
||||
} while (iid != Object::iid ());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string
|
||||
InterfaceIdDefaultValue::DoGetType (void) const
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "(";
|
||||
bool first = true;
|
||||
for (uint32_t i = 0; i < InterfaceId::GetRegisteredN (); i++)
|
||||
{
|
||||
InterfaceId iid = InterfaceId::GetRegistered (i);
|
||||
// can this interface id be used to create objects ?
|
||||
if (iid.HasConstructor ())
|
||||
{
|
||||
InterfaceId tmp = iid;
|
||||
// doe this interface id supports the requested interface id ?
|
||||
do {
|
||||
if (tmp == m_interfaceId)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
oss << "|";
|
||||
first = false;
|
||||
}
|
||||
oss << iid.GetName ();
|
||||
}
|
||||
} while (tmp != Object::iid ());
|
||||
}
|
||||
}
|
||||
oss << ")";
|
||||
return oss.str ();
|
||||
}
|
||||
|
||||
std::string
|
||||
InterfaceIdDefaultValue::DoGetDefaultValue (void) const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
51
src/core/interface-id-default-value.h
Normal file
51
src/core/interface-id-default-value.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef INTERFACE_ID_DEFAULT_VALUE_H
|
||||
#define INTERFACE_ID_DEFAULT_VALUE_H
|
||||
|
||||
#include "default-value.h"
|
||||
#include "object.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class InterfaceIdDefaultValue : public DefaultValueBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \param name the name of this default value.
|
||||
* \param help the help text associated to this default value
|
||||
* \param iid the interface id which all objects created
|
||||
* through this "default value" must support.
|
||||
* \param defaultValue the name of the object to create
|
||||
* by default.
|
||||
*/
|
||||
InterfaceIdDefaultValue (std::string name,
|
||||
std::string help,
|
||||
InterfaceId iid,
|
||||
std::string defaultValue);
|
||||
/**
|
||||
* \returns the InterfaceId of the object selected by the user.
|
||||
*/
|
||||
InterfaceId GetValue (void) const;
|
||||
/**
|
||||
* \param interfaceId the new ClassId selected.
|
||||
*
|
||||
* Override the currently-selected value.
|
||||
*/
|
||||
void SetValue (InterfaceId interfaceId);
|
||||
/**
|
||||
* \param name the new object selected.
|
||||
*
|
||||
* Override the currently-selected value.
|
||||
*/
|
||||
void SetValue (std::string name);
|
||||
private:
|
||||
virtual bool DoParseValue (const std::string &value);
|
||||
virtual std::string DoGetType (void) const;
|
||||
virtual std::string DoGetDefaultValue (void) const;
|
||||
std::string m_defaultName;
|
||||
std::string m_name;
|
||||
InterfaceId m_interfaceId;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* INTERFACE_ID_DEFAULT_VALUE_H */
|
||||
@@ -52,6 +52,7 @@ def build(bld):
|
||||
'trace-source.cc',
|
||||
'type-traits-test.cc',
|
||||
'array-trace-resolver.cc',
|
||||
'interface-id-default-value.cc',
|
||||
]
|
||||
|
||||
if sys.platform == 'win32':
|
||||
@@ -95,5 +96,6 @@ def build(bld):
|
||||
'array-trace-resolver.h',
|
||||
'trace-doc.h',
|
||||
'int-to-type.h',
|
||||
'interface-id-default-value.h',
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user