From f778c2c483d23c142f29658f9a0ae88bedb8b856 Mon Sep 17 00:00:00 2001 From: Natale Patriciello Date: Wed, 1 Jul 2015 15:28:22 +0200 Subject: [PATCH 14/18] API for deprecating attributes and trace sources added --- src/core/model/type-id.cc | 160 +++++++++++++++++++++++++++++++++++++++++++++- src/core/model/type-id.h | 66 +++++++++++++++++++ 2 files changed, 224 insertions(+), 2 deletions(-) diff --git a/src/core/model/type-id.cc b/src/core/model/type-id.cc index 31d4a99..25a277e 100644 --- a/src/core/model/type-id.cc +++ b/src/core/model/type-id.cc @@ -102,18 +102,28 @@ public: Ptr initialValue, Ptr spec, Ptr checker); + void AddDeprecatedAttribute (uint16_t uid, const std::string &oldName, + const std::string &oldClass, const std::string &msg); void SetAttributeInitialValue(uint16_t uid, uint32_t i, Ptr initialValue); uint32_t GetAttributeN (uint16_t uid) const; + uint32_t GetDeprecatedAttributeN (uint16_t uid) const; struct TypeId::AttributeInformation GetAttribute(uint16_t uid, uint32_t i) const; + struct TypeId::DeprecatedAttributeInformation GetDeprecatedAttribute (uint16_t uid, + uint32_t i) const; void AddTraceSource (uint16_t uid, std::string name, std::string help, Ptr accessor, std::string callback); + void AddDeprecatedTraceSource(uint16_t uid, const std::string &oldName, + const std::string &oldClass, const std::string &msg); uint32_t GetTraceSourceN (uint16_t uid) const; + uint32_t GetDeprecatedTraceSourceN (uint16_t uid) const; struct TypeId::TraceSourceInformation GetTraceSource(uint16_t uid, uint32_t i) const; + struct TypeId::DeprecatedTraceSourceInformation GetDeprecatedTraceSource (uint16_t uid, + uint32_t i) const; bool MustHideFromDocumentation (uint16_t uid) const; private: @@ -131,7 +141,9 @@ private: Callback constructor; bool mustHideFromDocumentation; std::vector attributes; + std::vector deprecatedAttributes; std::vector traceSources; + std::vector deprecatedTraceSources; }; typedef std::vector::const_iterator Iterator; @@ -436,6 +448,20 @@ IidManager::AddAttribute (uint16_t uid, info.checker = checker; information->attributes.push_back (info); } + +void +IidManager::AddDeprecatedAttribute(uint16_t uid, const std::string &oldName, + const std::string &oldClass, const std::string &msg) +{ + NS_LOG_FUNCTION (this << oldName << oldClass); + struct IidInformation *information = LookupInformation (uid); + struct TypeId::DeprecatedAttributeInformation info; + info.oldName = oldName; + info.oldClass = oldClass; + info.msg = msg; + information->deprecatedAttributes.push_back (info); +} + void IidManager::SetAttributeInitialValue(uint16_t uid, uint32_t i, @@ -447,8 +473,6 @@ IidManager::SetAttributeInitialValue(uint16_t uid, information->attributes[i].initialValue = initialValue; } - - uint32_t IidManager::GetAttributeN (uint16_t uid) const { @@ -456,6 +480,15 @@ IidManager::GetAttributeN (uint16_t uid) const struct IidInformation *information = LookupInformation (uid); return information->attributes.size (); } + +uint32_t +IidManager::GetDeprecatedAttributeN (uint16_t uid) const +{ + NS_LOG_FUNCTION (this << uid); + struct IidInformation *information = LookupInformation (uid); + return information->deprecatedAttributes.size (); +} + struct TypeId::AttributeInformation IidManager::GetAttribute(uint16_t uid, uint32_t i) const { @@ -465,6 +498,15 @@ IidManager::GetAttribute(uint16_t uid, uint32_t i) const return information->attributes[i]; } +struct TypeId::DeprecatedAttributeInformation +IidManager::GetDeprecatedAttribute (uint16_t uid, uint32_t i) const +{ + NS_LOG_FUNCTION (this << uid << i); + struct IidInformation *information = LookupInformation (uid); + NS_ASSERT (i < information->deprecatedAttributes.size ()); + return information->deprecatedAttributes[i]; +} + bool IidManager::HasTraceSource (uint16_t uid, std::string name) @@ -514,6 +556,20 @@ IidManager::AddTraceSource (uint16_t uid, source.callback = callback; information->traceSources.push_back (source); } + +void +IidManager::AddDeprecatedTraceSource (uint16_t uid, const std::string &oldName, + const std::string &oldClass, const std::string &msg) +{ + NS_LOG_FUNCTION (this << uid << oldName << oldClass); + struct IidInformation *information = LookupInformation (uid); + struct TypeId::DeprecatedTraceSourceInformation source; + source.oldName = oldName; + source.oldClass = oldClass; + source.msg = msg; + information->deprecatedTraceSources.push_back (source); +} + uint32_t IidManager::GetTraceSourceN (uint16_t uid) const { @@ -521,6 +577,15 @@ IidManager::GetTraceSourceN (uint16_t uid) const struct IidInformation *information = LookupInformation (uid); return information->traceSources.size (); } + +uint32_t +IidManager::GetDeprecatedTraceSourceN (uint16_t uid) const +{ + NS_LOG_FUNCTION (this << uid); + struct IidInformation *information = LookupInformation (uid); + return information->deprecatedTraceSources.size (); +} + struct TypeId::TraceSourceInformation IidManager::GetTraceSource(uint16_t uid, uint32_t i) const { @@ -529,6 +594,16 @@ IidManager::GetTraceSource(uint16_t uid, uint32_t i) const NS_ASSERT (i < information->traceSources.size ()); return information->traceSources[i]; } + +struct TypeId::DeprecatedTraceSourceInformation +IidManager::GetDeprecatedTraceSource(uint16_t uid, uint32_t i) const +{ + NS_LOG_FUNCTION (this << uid << i); + struct IidInformation *information = LookupInformation (uid); + NS_ASSERT (i < information->deprecatedTraceSources.size ()); + return information->deprecatedTraceSources[i]; +} + bool IidManager::MustHideFromDocumentation (uint16_t uid) const { @@ -631,6 +706,23 @@ TypeId::LookupAttributeByName (std::string name, struct TypeId::AttributeInforma } nextTid = tid.GetParent (); } while (nextTid != tid); + + nextTid = *this; + do { + tid = nextTid; + for (uint32_t i = 0; i < tid.GetDeprecatedAttributeN (); ++i) + { + struct TypeId::DeprecatedAttributeInformation tmp = tid.GetDeprecatedAttribute (i); + if (tmp.oldName == name) + { + NS_LOG_UNCOND ("ATTENTION: Deprecated attribute " << name << + " in class " << tmp.oldClass << "." << tmp.msg); + return false; + } + } + nextTid = tid.GetParent (); + } while (nextTid != tid); + return false; } @@ -750,6 +842,22 @@ TypeId::AddAttribute (std::string name, return *this; } +TypeId +TypeId::DeprecateAttribute (const std::string &oldName, const std::string &oldClass, + const std::string &msg) +{ + Singleton::Get ()->AddDeprecatedAttribute (m_tid, oldName, oldClass, msg); + return *this; +} + +TypeId +TypeId::DeprecateTraceSource (const std::string &oldName, const std::string &oldClass, + const std::string &msg) +{ + Singleton::Get ()->AddDeprecatedTraceSource (m_tid, oldName, oldClass, msg); + return *this; +} + bool TypeId::SetAttributeInitialValue(uint32_t i, Ptr initialValue) @@ -783,12 +891,28 @@ TypeId::GetAttributeN (void) const uint32_t n = Singleton::Get ()->GetAttributeN (m_tid); return n; } + +uint32_t +TypeId::GetDeprecatedAttributeN (void) const +{ + NS_LOG_FUNCTION (this); + uint32_t n = Singleton::Get ()->GetDeprecatedAttributeN (m_tid); + return n; +} struct TypeId::AttributeInformation TypeId::GetAttribute(uint32_t i) const { NS_LOG_FUNCTION (this << i); return Singleton::Get ()->GetAttribute(m_tid, i); } + +struct TypeId::DeprecatedAttributeInformation +TypeId::GetDeprecatedAttribute (uint32_t i) const +{ + NS_LOG_FUNCTION (this << i); + return Singleton::Get ()->GetDeprecatedAttribute (m_tid, i); +} + std::string TypeId::GetAttributeFullName (uint32_t i) const { @@ -803,6 +927,14 @@ TypeId::GetTraceSourceN (void) const NS_LOG_FUNCTION (this); return Singleton::Get ()->GetTraceSourceN (m_tid); } + +uint32_t +TypeId::GetDeprecatedTraceSourceN (void) const +{ + NS_LOG_FUNCTION (this); + return Singleton::Get ()->GetDeprecatedTraceSourceN (m_tid); +} + struct TypeId::TraceSourceInformation TypeId::GetTraceSource(uint32_t i) const { @@ -810,6 +942,13 @@ TypeId::GetTraceSource(uint32_t i) const return Singleton::Get ()->GetTraceSource(m_tid, i); } +struct TypeId::DeprecatedTraceSourceInformation +TypeId::GetDeprecatedTraceSource (uint32_t i) const +{ + NS_LOG_FUNCTION (this << i); + return Singleton::Get ()->GetDeprecatedTraceSource (m_tid, i); +} + TypeId TypeId::AddTraceSource (std::string name, std::string help, @@ -856,6 +995,23 @@ TypeId::LookupTraceSourceByName (std::string name) const } nextTid = tid.GetParent (); } while (nextTid != tid); + + nextTid = *this; + do { + tid = nextTid; + for (uint32_t i = 0; i < tid.GetDeprecatedTraceSourceN (); ++i) + { + struct TypeId::DeprecatedTraceSourceInformation tmp = tid.GetDeprecatedTraceSource (i); + if (tmp.oldName == name) + { + NS_LOG_UNCOND ("ATTENTION: Deprecated attribute " << name << + " in class " << tmp.oldClass << "." << tmp.msg); + return 0; + } + } + nextTid = tid.GetParent (); + } while (nextTid != tid); + return 0; } diff --git a/src/core/model/type-id.h b/src/core/model/type-id.h index 57de930..7f8d2a4 100644 --- a/src/core/model/type-id.h +++ b/src/core/model/type-id.h @@ -81,6 +81,16 @@ public: std::string callback; Ptr accessor; }; + struct DeprecatedAttributeInformation { + std::string oldName; + std::string oldClass; + std::string msg; + }; + struct DeprecatedTraceSourceInformation { + std::string oldName; + std::string oldClass; + std::string msg; + }; /** * Type of hash values @@ -190,12 +200,26 @@ public: * \returns the number of attributes associated to this TypeId */ uint32_t GetAttributeN (void) const; + + /** + * \return the number of deprecated attributes associated to this TypeId + */ + uint32_t GetDeprecatedAttributeN (void) const; + /** * \param i index into attribute array * \returns the information associated to attribute whose * index is i. */ struct TypeId::AttributeInformation GetAttribute(uint32_t i) const; + + /** + * \param i index into deprecated attribute array + * \returns the information associated to attribute whose + * index is i. + */ + struct TypeId::DeprecatedAttributeInformation GetDeprecatedAttribute (uint32_t i) const; + /** * \param i index into attribute array * \returns the full name associated to the attribute whose @@ -220,6 +244,12 @@ public: * \returns the number of trace sources defined in this TypeId. */ uint32_t GetTraceSourceN (void) const; + + /** + * \returns the number of deprecated trace sources defined in this TypeId. + */ + uint32_t GetDeprecatedTraceSourceN (void) const; + /** * \param i index into trace source array. * \returns detailed information about the requested trace source. @@ -227,6 +257,12 @@ public: struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const; /** + * \param i index into deprecated trace source array. + * \returns detailed information about the requested deprecated trace source. + */ + struct TypeId::DeprecatedTraceSourceInformation GetDeprecatedTraceSource (uint32_t i) const; + + /** * \param tid the TypeId of the base class. * \return this TypeId instance. * @@ -296,6 +332,21 @@ public: Ptr checker); /** + * \brief Deprecate an attribute by printing a message to the user + * + * If the user tries to attach to the attribute declared with this method, + * a warning message is printed, indicating where he/she can found the new + * attribute class and name. + * + * \param oldName old name of the attribute + * \param oldClass old class of the attribute + * \param msg optional message to be printed + * \return this TypeId instance + */ + TypeId DeprecateAttribute (const std::string &oldName, const std::string &oldClass, + const std::string &msg); + + /** * \param i the attribute to manipulate * \param initialValue the new initial value to use for this attribute. * \returns true if the call was successfuly, false otherwise. @@ -352,6 +403,21 @@ public: Ptr accessor, std::string callback); + /** + * \brief Deprecate a trace source by printing a message to the user + * + * If the user tries to attach to the trace source declared with this method, + * a warning message is printed, indicating where he/she can found the new + * attribute class and name. + * + * \param oldName old name of the trace source + * \param oldClass old class of the trace source + * \param msg optional message to print to the user + * \return this TypeId instance + */ + TypeId DeprecateTraceSource (const std::string &oldName, const std::string &oldClass, + const std::string &msg); + TypeId HideFromDocumentation (void); /** -- 2.4.4