rework the NS_XX_ENSURE_REGISTERED macros and make sure we typecheck the input to TraceContext::Add and TraceContext::Get methods
--- a/src/common/header.h Wed Aug 08 10:06:58 2007 +0200
+++ b/src/common/header.h Wed Aug 08 10:18:55 2007 +0200
@@ -37,15 +37,13 @@
* Note: This macro is _absolutely_ needed if you try to run a
* distributed simulation.
*/
-#define NS_HEADER_ENSURE_REGISTERED(x) \
-namespace { \
-static class thisisaveryverylongclassname \
-{ \
-public: \
- thisisaveryverylongclassname () \
- { uint32_t uid; uid = x::GetUid ();} \
-} g_thisisanotherveryveryverylongname; \
-}
+#define NS_HEADER_ENSURE_REGISTERED(x) \
+static class thisisaveryverylongclassname ##x \
+{ \
+ public: \
+ thisisaveryverylongclassname ##x () \
+ { uint32_t uid; uid = x::GetUid ();} \
+} g_thisisanotherveryveryverylongname ## x;
namespace ns3 {
--- a/src/common/tag.h Wed Aug 08 10:06:58 2007 +0200
+++ b/src/common/tag.h Wed Aug 08 10:18:55 2007 +0200
@@ -21,6 +21,27 @@
#ifndef TAG_H
#define TAG_H
+/**
+ * \relates Tag
+ * \brief this macro should be instantiated exactly once for each
+ * new type of Tag
+ *
+ * This macro will ensure that your new Tag type is registered
+ * within the tag registry. In most cases, this macro
+ * is not really needed but, for safety, please, use it all the
+ * time.
+ *
+ * Note: This macro is _absolutely_ needed if you try to run a
+ * distributed simulation.
+ */
+#define NS_TAG_ENSURE_REGISTERED(x) \
+static class thisisaveryverylongclassname ##x \
+{ \
+ public: \
+ thisisaveryverylongclassname ##x () \
+ { uint32_t uid; uid = x::GetUid ();} \
+} g_thisisanotherveryveryverylongname ## x;
+
namespace ns3 {
class Tag
--- a/src/common/tags.h Wed Aug 08 10:06:58 2007 +0200
+++ b/src/common/tags.h Wed Aug 08 10:18:55 2007 +0200
@@ -26,30 +26,6 @@
#include <vector>
#include "buffer.h"
-/**
- * \ingroup tag
- * \brief this macro should be instantiated exactly once for each
- * new type of Tag
- *
- * This macro will ensure that your new Tag type is registered
- * within the tag registry. In most cases, this macro
- * is not really needed but, for safety, please, use it all the
- * time.
- *
- * Note: This macro is _absolutely_ needed if you try to run a
- * distributed simulation.
- */
-#define NS_TAG_ENSURE_REGISTERED(x) \
-namespace { \
-static class thisisaveryverylongclassname \
-{ \
-public: \
- thisisaveryverylongclassname () \
- { uint32_t uid; uid = x::GetUid ();} \
-} g_thisisanotherveryveryverylongname; \
-}
-
-
namespace ns3 {
template <typename T>
--- a/src/common/trace-context-element.h Wed Aug 08 10:06:58 2007 +0200
+++ b/src/common/trace-context-element.h Wed Aug 08 10:18:55 2007 +0200
@@ -6,12 +6,12 @@
#define NS_TRACE_CONTEXT_ELEMENT_ENSURE_REGISTERED(x) \
namespace { \
-static class thisisaveryverylongclassname \
+static class thisisaveryverylongclassname ##x \
{ \
public: \
- thisisaveryverylongclassname () \
+ thisisaveryverylongclassname ##x () \
{ uint32_t uid; uid = x::GetUid ();} \
- } g_thisisanotherveryveryverylongname; \
+ } g_thisisanotherveryveryverylongname ##x ; \
}
namespace ns3 {
--- a/src/common/trace-context.h Wed Aug 08 10:06:58 2007 +0200
+++ b/src/common/trace-context.h Wed Aug 08 10:18:55 2007 +0200
@@ -24,6 +24,7 @@
#include <stdint.h>
#include <vector>
#include "ns3/fatal-error.h"
+#include "trace-context-element.h"
namespace ns3 {
@@ -85,7 +86,7 @@
template <typename T>
bool SafeGet (T &context) const;
template <typename T>
- bool SafeAdd (T &context);
+ bool SafeAdd (const T &context);
uint8_t *CheckPresent (uint8_t uid) const;
bool DoAdd (uint8_t uid, uint8_t const *buffer);
@@ -106,6 +107,10 @@
void
TraceContext::Add (T const &context)
{
+ const TraceContextElement *parent;
+ // if the following assignment fails, it is because the input
+ // to this function is not a subclass of the TraceContextElement class.
+ parent = &context;
uint8_t *data = (uint8_t *) &context;
bool ok = DoAdd (T::GetUid (), data);
if (!ok)
@@ -117,6 +122,10 @@
void
TraceContext::Get (T &context) const
{
+ TraceContextElement *parent;
+ // if the following assignment fails, it is because the input
+ // to this function is not a subclass of the TraceContextElement class.
+ parent = &context;
uint8_t *data = (uint8_t *) &context;
bool found = DoGet (T::GetUid (), data);
if (!found)
@@ -128,14 +137,22 @@
bool
TraceContext::SafeGet (T &context) const
{
+ TraceContextElement *parent;
+ // if the following assignment fails, it is because the input
+ // to this function is not a subclass of the TraceContextElement class.
+ parent = &context;
uint8_t *data = (uint8_t *) &context;
bool found = DoGet (T::GetUid (), data);
return found;
}
template <typename T>
bool
-TraceContext::SafeAdd (T &context)
+TraceContext::SafeAdd (const T &context)
{
+ const TraceContextElement *parent;
+ // if the following assignment fails, it is because the input
+ // to this function is not a subclass of the TraceContextElement class.
+ parent = &context;
uint8_t *data = (uint8_t *) &context;
bool ok = DoAdd (T::GetUid (), data);
return ok;
--- a/src/common/trailer.h Wed Aug 08 10:06:58 2007 +0200
+++ b/src/common/trailer.h Wed Aug 08 10:18:55 2007 +0200
@@ -37,15 +37,13 @@
* Note: This macro is _absolutely_ needed if you try to run a
* distributed simulation.
*/
-#define NS_TRAILER_ENSURE_REGISTERED(x) \
-namespace { \
-static class thisisaveryverylongclassname \
-{ \
-public: \
- thisisaveryverylongclassname () \
- { uint32_t uid; uid = x::GetUid ();} \
-} g_thisisanotherveryveryverylongname; \
-}
+#define NS_TRAILER_ENSURE_REGISTERED(x) \
+static class thisisaveryverylongclassname ##x \
+{ \
+ public: \
+ thisisaveryverylongclassname ##x () \
+ { uint32_t uid; uid = x::GetUid ();} \
+} g_thisisanotherveryveryverylongname ##x;
namespace ns3 {
--- a/src/internet-node/arp-header.cc Wed Aug 08 10:06:58 2007 +0200
+++ b/src/internet-node/arp-header.cc Wed Aug 08 10:18:55 2007 +0200
@@ -23,9 +23,9 @@
#include "ns3/address-utils.h"
#include "arp-header.h"
-NS_HEADER_ENSURE_REGISTERED (ns3::ArpHeader);
+namespace ns3 {
-namespace ns3 {
+NS_HEADER_ENSURE_REGISTERED (ArpHeader);
uint32_t
ArpHeader::GetUid (void)
--- a/src/internet-node/ipv4-header.cc Wed Aug 08 10:06:58 2007 +0200
+++ b/src/internet-node/ipv4-header.cc Wed Aug 08 10:18:55 2007 +0200
@@ -26,9 +26,9 @@
NS_DEBUG_COMPONENT_DEFINE ("Ipv4Header");
-NS_HEADER_ENSURE_REGISTERED (ns3::Ipv4Header);
+namespace ns3 {
-namespace ns3 {
+NS_HEADER_ENSURE_REGISTERED (Ipv4Header);
bool Ipv4Header::m_calcChecksum = false;
--- a/src/internet-node/udp-header.cc Wed Aug 08 10:06:58 2007 +0200
+++ b/src/internet-node/udp-header.cc Wed Aug 08 10:18:55 2007 +0200
@@ -22,9 +22,9 @@
#include "udp-header.h"
#include "ipv4-checksum.h"
-NS_HEADER_ENSURE_REGISTERED (ns3::UdpHeader);
+namespace ns3 {
-namespace ns3 {
+NS_HEADER_ENSURE_REGISTERED (UdpHeader);
bool UdpHeader::m_calcChecksum = false;
--- a/src/node/ethernet-header.cc Wed Aug 08 10:06:58 2007 +0200
+++ b/src/node/ethernet-header.cc Wed Aug 08 10:18:55 2007 +0200
@@ -27,9 +27,9 @@
NS_DEBUG_COMPONENT_DEFINE ("EthernetHeader");
-NS_HEADER_ENSURE_REGISTERED (ns3::EthernetHeader);
+namespace ns3 {
-namespace ns3 {
+NS_HEADER_ENSURE_REGISTERED (EthernetHeader);
uint32_t
EthernetHeader::GetUid (void)
--- a/src/node/ethernet-trailer.cc Wed Aug 08 10:06:58 2007 +0200
+++ b/src/node/ethernet-trailer.cc Wed Aug 08 10:18:55 2007 +0200
@@ -26,9 +26,9 @@
NS_DEBUG_COMPONENT_DEFINE ("EthernetTrailer");
-NS_TRAILER_ENSURE_REGISTERED (ns3::EthernetTrailer);
+namespace ns3 {
-namespace ns3 {
+NS_TRAILER_ENSURE_REGISTERED (EthernetTrailer);
bool EthernetTrailer::m_calcFcs = false;
--- a/src/node/llc-snap-header.cc Wed Aug 08 10:06:58 2007 +0200
+++ b/src/node/llc-snap-header.cc Wed Aug 08 10:18:55 2007 +0200
@@ -23,10 +23,9 @@
#include "ns3/assert.h"
#include <string>
-NS_HEADER_ENSURE_REGISTERED (ns3::LlcSnapHeader);
+namespace ns3 {
-
-namespace ns3 {
+NS_HEADER_ENSURE_REGISTERED (LlcSnapHeader);
uint32_t
LlcSnapHeader::GetUid (void)