From 25bb76ce206d1831a22e710f90da52a4fda0ea55 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 15 Feb 2008 05:38:29 +0100 Subject: [PATCH] macro-ify --- src/common/data-rate.cc | 11 ++--------- src/common/data-rate.h | 38 ++++--------------------------------- src/core/value-helper.h | 38 +++++++++++++++++++++++++++++++++++++ src/core/wscript | 1 + src/mobility/rectangle.cc | 9 +-------- src/mobility/rectangle.h | 33 +++----------------------------- src/mobility/vector.cc | 12 ++---------- src/mobility/vector.h | 36 +++-------------------------------- src/node/address.h | 40 ++++----------------------------------- src/node/mac48-address.cc | 12 ++---------- src/node/mac48-address.h | 36 ++++------------------------------- 11 files changed, 64 insertions(+), 202 deletions(-) create mode 100644 src/core/value-helper.h diff --git a/src/common/data-rate.cc b/src/common/data-rate.cc index ff4e7230e..a4b5282de 100644 --- a/src/common/data-rate.cc +++ b/src/common/data-rate.cc @@ -125,6 +125,8 @@ DoParse (const std::string s, uint64_t *v) namespace ns3 { +VALUE_HELPER_CPP (DataRate); + DataRate::DataRate () : m_bps (0) {} @@ -173,15 +175,6 @@ uint64_t DataRate::GetBitRate() const return m_bps; } -DataRate::DataRate (PValue value) -{ - *this = ClassValueHelperExtractFrom (value); -} -DataRate::operator PValue () const -{ - return ClassValueHelperConvertTo (this); -} - DataRate MakeDataRate (std::string rate) { uint64_t bps; diff --git a/src/common/data-rate.h b/src/common/data-rate.h index af2653d5c..fc596431c 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -28,7 +28,7 @@ #include "ns3/nstime.h" #include "ns3/default-value.h" #include "ns3/value.h" -#include "ns3/class-value-helper.h" +#include "ns3/value-helper.h" namespace ns3 { @@ -80,9 +80,8 @@ public: * \return The underlying bitrate in bits per second */ uint64_t GetBitRate() const; - - DataRate (PValue value); - operator PValue () const; + + VALUE_HELPER_HEADER_1 (DataRate); private: uint64_t m_bps; static uint64_t Parse(const std::string); @@ -93,16 +92,7 @@ DataRate MakeDataRate (std::string rate); std::ostream &operator << (std::ostream &os, const DataRate &rate); std::istream &operator >> (std::istream &is, DataRate &rate); -class DataRateValue : public Value {}; -class DataRateParamSpec : public ParamSpec {}; - -template -Ptr -MakeDataRateParamSpec (T1 a1, DataRate initialValue); - -template -Ptr -MakeDataRateParamSpec (T1 a1, T2 a2, DataRate initialValue); +VALUE_HELPER_HEADER_2 (DataRate); /** * \param lhs @@ -130,24 +120,4 @@ private: } //namespace ns3 -namespace ns3 { - -template -Ptr -MakeDataRateParamSpec (T1 a1, DataRate initialValue) -{ - return MakeClassValueHelperParamSpec - (a1, initialValue); -} - -template -Ptr -MakeDataRateParamSpec (T1 a1, T2 a2, DataRate initialValue) -{ - return MakeClassValueHelperParamSpec - (a1, a2, initialValue); -} - -} // namespace ns3 - #endif /* DATA_RATE_H */ diff --git a/src/core/value-helper.h b/src/core/value-helper.h new file mode 100644 index 000000000..f53fb95ce --- /dev/null +++ b/src/core/value-helper.h @@ -0,0 +1,38 @@ +#ifndef VALUE_HELPER_H +#define VALUE_HELPER_H + +#include "class-value-helper.h" + +#define VALUE_HELPER_HEADER_1(type) \ + type (PValue value); \ + operator PValue () const; + +#define VALUE_HELPER_HEADER_2(type) \ + class type##Value : public Value {}; \ + class type##ParamSpec : public ParamSpec {}; \ + template \ + Ptr Make##type##ParamSpec (T1 a1, \ + type initialValue) \ + { \ + return MakeClassValueHelperParamSpec< type , \ + type##Value, type##ParamSpec> (a1, initialValue); \ + } \ + template \ + Ptr Make##type##ParamSpec (T1 a1, T2 a2, \ + type initialValue) \ + { \ + return MakeClassValueHelperParamSpec (a1, a2, initialValue); \ + } + +#define VALUE_HELPER_CPP(type) \ + type::type (PValue value) \ + { \ + *this = ClassValueHelperExtractFrom (value); \ + } \ + type::operator PValue () const \ + { \ + return ClassValueHelperConvertTo (this); \ + } + +#endif /* VALUE_HELPER_H */ diff --git a/src/core/wscript b/src/core/wscript index e5cad486e..d1c8e55a1 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -114,5 +114,6 @@ def build(bld): 'enum-value.h', 'object-factory.h', 'class-value-helper.h', + 'value-helper.h', ] diff --git a/src/mobility/rectangle.cc b/src/mobility/rectangle.cc index 7fa815661..fcbea44db 100644 --- a/src/mobility/rectangle.cc +++ b/src/mobility/rectangle.cc @@ -119,14 +119,7 @@ Rectangle::CalculateIntersection (const Vector ¤t, const Vector &speed) co } -Rectangle::Rectangle (PValue value) -{ - *this = ClassValueHelperExtractFrom (value); -} -Rectangle::operator PValue () const -{ - return ClassValueHelperConvertTo (this); -} +VALUE_HELPER_CPP (Rectangle); std::ostream & operator << (std::ostream &os, const Rectangle &rectangle) diff --git a/src/mobility/rectangle.h b/src/mobility/rectangle.h index b4f4386af..29926ee84 100644 --- a/src/mobility/rectangle.h +++ b/src/mobility/rectangle.h @@ -21,7 +21,7 @@ #define RECTANGLE_H #include "ns3/value.h" -#include "ns3/class-value-helper.h" +#include "ns3/value-helper.h" namespace ns3 { @@ -62,40 +62,13 @@ public: double yMin; double yMax; - Rectangle (PValue value); - operator PValue () const; + VALUE_HELPER_HEADER_1 (Rectangle); }; std::ostream &operator << (std::ostream &os, const Rectangle &rectangle); std::istream &operator >> (std::istream &is, Rectangle &rectangle); - -class RectangleValue : public Value {}; -class RectangleParamSpec : public ParamSpec {}; - -template -Ptr MakeRectangleParamSpec (T1 a1, - Rectangle initialValue); -template -Ptr MakeRectangleParamSpec (T1 a1, T2 a2, - Rectangle initialValue); - -} // namespace ns3 - -namespace ns3 { - -template -Ptr MakeRectangleParamSpec (T1 a1, - Rectangle initialValue) -{ - return MakeClassValueHelperParamSpec (a1, initialValue); -} -template -Ptr MakeRectangleParamSpec (T1 a1, T2 a2, - Rectangle initialValue) -{ - return MakeClassValueHelperParamSpec (a1, a2, initialValue); -} +VALUE_HELPER_HEADER_2 (Rectangle); } // namespace ns3 diff --git a/src/mobility/vector.cc b/src/mobility/vector.cc index c44d5ca3c..7027aeb82 100644 --- a/src/mobility/vector.cc +++ b/src/mobility/vector.cc @@ -24,6 +24,8 @@ namespace ns3 { +VALUE_HELPER_CPP (Vector); + Vector::Vector (double _x, double _y, double _z) : x (_x), @@ -37,16 +39,6 @@ Vector::Vector () z (0.0) {} -Vector::Vector (PValue value) -{ - *this = ClassValueHelperExtractFrom (value); -} -Vector::operator PValue () const -{ - return ClassValueHelperConvertTo (this); -} - - double CalculateDistance (const Vector &a, const Vector &b) { diff --git a/src/mobility/vector.h b/src/mobility/vector.h index 118448337..b0e50337a 100644 --- a/src/mobility/vector.h +++ b/src/mobility/vector.h @@ -21,7 +21,7 @@ #define VECTOR_H #include "ns3/value.h" -#include "ns3/class-value-helper.h" +#include "ns3/value-helper.h" namespace ns3 { @@ -58,46 +58,16 @@ public: */ double z; - Vector (PValue value); - operator PValue () const; + VALUE_HELPER_HEADER_1 (Vector); }; double CalculateDistance (const Vector &a, const Vector &b); -class VectorValue : public Value {}; -class VectorParamSpec : public ParamSpec {}; +VALUE_HELPER_HEADER_2 (Vector); std::ostream &operator << (std::ostream &os, const Vector &vector); std::istream &operator >> (std::istream &is, Vector &vector); -template -Ptr -MakeVectorParamSpec (T1 a1, const Vector &initialValue); - -template -Ptr -MakeVectorParamSpec (T1 a1, T2 a2, - const Vector &initialValue); - -} // namespace ns3 - -namespace ns3 { - -template -Ptr -MakeVectorParamSpec (T1 a1, const Vector &initialValue) -{ - return MakeClassValueHelperParamSpec (a1, initialValue); -} - -template -Ptr -MakeVectorParamSpec (T1 a1, T2 a2, - const Vector &initialValue) -{ - return MakeClassValueHelperParamSpec (a1, a2, initialValue); -} - } // namespace ns3 #endif /* VECTOR_H */ diff --git a/src/node/address.h b/src/node/address.h index 911bda30d..6d23490ec 100644 --- a/src/node/address.h +++ b/src/node/address.h @@ -4,7 +4,7 @@ #include #include #include "ns3/value.h" -#include "ns3/class-value-helper.h" +#include "ns3/value-helper.h" namespace ns3 { @@ -154,8 +154,7 @@ public: */ static uint8_t Register (void); - Address (PValue value); - operator PValue () const; + VALUE_HELPER_HEADER_1 (Address); private: friend bool operator == (const Address &a, const Address &b); friend bool operator < (const Address &a, const Address &b); @@ -166,46 +165,15 @@ private: uint8_t m_data[MAX_SIZE]; }; +VALUE_HELPER_HEADER_2 (Address); + bool operator == (const Address &a, const Address &b); bool operator != (const Address &a, const Address &b); bool operator < (const Address &a, const Address &b); std::ostream& operator<< (std::ostream& os, const Address & address); std::istream& operator>> (std::istream& is, Address & address); -class AddressValue : public Value {}; -class AddressParamSpec : public ParamSpec {}; - -template -Ptr -MakeAddressParamSpec (T1 a1, Address initialValue); - -template -Ptr -MakeAddressParamSpec (T1 a1, T2 a2, Address initialValue); } // namespace ns3 -namespace ns3 { - -template -Ptr -MakeAddressParamSpec (T1 a1, Address initialValue) -{ - return MakeClassValueHelperParamSpec - (a1, initialValue); -} - -template -Ptr -MakeAddressParamSpec (T1 a1, T2 a2, Address initialValue) -{ - return MakeClassValueHelperParamSpec - (a1, a2, initialValue); -} - - - -} // namespace ns3 - - #endif /* ADDRESS_H */ diff --git a/src/node/mac48-address.cc b/src/node/mac48-address.cc index 0c4013da1..12c664b38 100644 --- a/src/node/mac48-address.cc +++ b/src/node/mac48-address.cc @@ -25,6 +25,8 @@ namespace ns3 { +VALUE_HELPER_CPP (Mac48Address); + #define ASCII_a (0x41) #define ASCII_z (0x5a) #define ASCII_A (0x61) @@ -150,16 +152,6 @@ Mac48Address::GetBroadcast (void) return broadcast; } -Mac48Address::Mac48Address (PValue value) -{ - *this = ClassValueHelperExtractFrom (value); -} -Mac48Address::operator PValue () const -{ - return ClassValueHelperConvertTo (this); -} - - bool operator == (const Mac48Address &a, const Mac48Address &b) { return memcmp (a.m_address, b.m_address, 6) == 0; diff --git a/src/node/mac48-address.h b/src/node/mac48-address.h index cac30976d..a427493ed 100644 --- a/src/node/mac48-address.h +++ b/src/node/mac48-address.h @@ -23,7 +23,7 @@ #include #include #include "ns3/value.h" -#include "ns3/class-value-helper.h" +#include "ns3/value-helper.h" namespace ns3 { @@ -96,8 +96,7 @@ public: */ static Mac48Address GetBroadcast (void); - Mac48Address (PValue value); - operator PValue () const; + VALUE_HELPER_HEADER_1 (Mac48Address); private: /** * \returns a new Address instance @@ -112,41 +111,14 @@ private: uint8_t m_address[6]; }; +VALUE_HELPER_HEADER_2 (Mac48Address); + bool operator == (const Mac48Address &a, const Mac48Address &b); bool operator != (const Mac48Address &a, const Mac48Address &b); bool operator < (const Mac48Address &a, const Mac48Address &b); std::ostream& operator<< (std::ostream& os, const Mac48Address & address); std::istream& operator>> (std::istream& is, const Mac48Address & address); -class Mac48AddressValue : public Value {}; -class Mac48AddressParamSpec : public ParamSpec {}; - -template -Ptr -MakeMac48AddressParamSpec (T1 a1, Mac48Address address); - -template -Ptr -MakeMac48AddressParamSpec (T1 a1, T2 a2, Mac48Address address); - -} // namespace ns3 - -namespace ns3 { - -template -Ptr -MakeMac48AddressParamSpec (T1 a1, Mac48Address address) -{ - return MakeClassValueHelperParamSpec (a1, address); -} - -template -Ptr -MakeMac48AddressParamSpec (T1 a1, T2 a2, Mac48Address address) -{ - return MakeClassValueHelperParamSpec (a1, a2, address); -} - } // namespace ns3 #endif /* MAC48_ADDRESS_H */