Bugzilla – Full Text Bug Listing |
Summary: | Config::GetDefault | ||
---|---|---|---|
Product: | ns-3 | Reporter: | Nicola Baldo <nicola> |
Component: | core | Assignee: | Peter Barnes <pdbarnes> |
Status: | PATCH PENDING --- | ||
Severity: | enhancement | CC: | ns-bugs, pdbarnes, tommaso.pecorella |
Priority: | P5 | ||
Version: | pre-release | ||
Hardware: | All | ||
OS: | All | ||
Bug Depends on: | |||
Bug Blocks: | 2330 | ||
Attachments: |
std::string Config::GetDefault() patch
Patch for template <typename R> R Config::GetDefault() Patch for template <typename R> R Config::GetDefault() |
Description
Nicola Baldo
2013-03-18 13:55:57 EDT
Isn't this doing the same thing ? bool ns3::TypeId::LookupAttributeByName ( std::string name, struct AttributeInformation *info ) const I mean, you get the class' TypeId, then you use LookupAttributeByName, then you look into the AttributeInformation for the ns3::Ptr< const ns3::AttributeValue > initialValue, then you extract the value from it. Maybe it could be done in an easier way, however you can't know the attribute's type in advance, so the GetDefault function might have the very same implementation clumsiness. Unless you're searching for the default value of the attribute of another class. In this case it's "just" a bit more complex, as you'll need first to retrieve the TypeId for that class. Anyway, it can be done. If I'm right... T. I think the heart of the code needed is now in command-line.cc:439: void CommandLine::AddValue (const std::string &name, const std::string &attributePath) which does essentially what Tommaso suggests. @Nicola: which default do you want to return? AttributeInformation::initialValue or AttributeInformation::originalInitialValue > @Nicola: which default do you want to return?
> AttributeInformation::initialValue or
> AttributeInformation::originalInitialValue
The usage I have in mind is to return the default value that will be used for new objects, e.g., if the default value was changed from the cmd line, then the changed value should be returned. I guess this is AttributeInformation::initialValue, right?
Created attachment 1910 [details]
std::string Config::GetDefault() patch
This patch adds std::string Config::GetDefault (const std::string attributePath) As Tommaso noted it's hard to infer the actual type of the attribute (it could be any of the ~36 derivatives of AttributeValue), never mind the underlying object, so the patch just returns the initial value serialized to a string. If you think you might know the type of the attribute, I could try to write something like template<typename T> Ptr<T> Config::GetDefault (const std::string attributePath); which would attempt to create an initialized T. Of course T would have to be derived from AttributeValue for this to succeed, and you'd have to check that the return wasn't null. Created attachment 1945 [details]
Patch for template <typename R> R Config::GetDefault()
This is a patch implementing
template <typename R>
R Config::GetDefault (const std::string attributePath);
This is specialized for almost all the types underlying the various AttributeValue classes.
Usage is like
Box boxDefault = GetDefault<Box> (".../Building/Boundaries");
If the attribute path can't be converted to the requested type R it causes a fatal error.
Created attachment 1946 [details]
Patch for template <typename R> R Config::GetDefault()
Whoops, left off the doxygen.conf lines.
|