macro-ify

This commit is contained in:
Mathieu Lacage
2008-02-15 05:38:29 +01:00
parent e94efb4a11
commit 25bb76ce20
11 changed files with 64 additions and 202 deletions

View File

@@ -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<DataRate,DataRateValue> (value);
}
DataRate::operator PValue () const
{
return ClassValueHelperConvertTo<DataRate,DataRateValue> (this);
}
DataRate MakeDataRate (std::string rate)
{
uint64_t bps;

View File

@@ -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 <typename T1>
Ptr<ParamSpec>
MakeDataRateParamSpec (T1 a1, DataRate initialValue);
template <typename T1, typename T2>
Ptr<ParamSpec>
MakeDataRateParamSpec (T1 a1, T2 a2, DataRate initialValue);
VALUE_HELPER_HEADER_2 (DataRate);
/**
* \param lhs
@@ -130,24 +120,4 @@ private:
} //namespace ns3
namespace ns3 {
template <typename T1>
Ptr<ParamSpec>
MakeDataRateParamSpec (T1 a1, DataRate initialValue)
{
return MakeClassValueHelperParamSpec<DataRate,DataRateValue,DataRateParamSpec>
(a1, initialValue);
}
template <typename T1, typename T2>
Ptr<ParamSpec>
MakeDataRateParamSpec (T1 a1, T2 a2, DataRate initialValue)
{
return MakeClassValueHelperParamSpec<DataRate,DataRateValue,DataRateParamSpec>
(a1, a2, initialValue);
}
} // namespace ns3
#endif /* DATA_RATE_H */

38
src/core/value-helper.h Normal file
View File

@@ -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 <typename T1> \
Ptr<ParamSpec> Make##type##ParamSpec (T1 a1, \
type initialValue) \
{ \
return MakeClassValueHelperParamSpec< type , \
type##Value, type##ParamSpec> (a1, initialValue); \
} \
template <typename T1, typename T2> \
Ptr<ParamSpec> Make##type##ParamSpec (T1 a1, T2 a2, \
type initialValue) \
{ \
return MakeClassValueHelperParamSpec<type, \
type##Value,type##ParamSpec> (a1, a2, initialValue); \
}
#define VALUE_HELPER_CPP(type) \
type::type (PValue value) \
{ \
*this = ClassValueHelperExtractFrom<type,type##Value> (value); \
} \
type::operator PValue () const \
{ \
return ClassValueHelperConvertTo<type,type##Value> (this); \
}
#endif /* VALUE_HELPER_H */

View File

@@ -114,5 +114,6 @@ def build(bld):
'enum-value.h',
'object-factory.h',
'class-value-helper.h',
'value-helper.h',
]

View File

@@ -119,14 +119,7 @@ Rectangle::CalculateIntersection (const Vector &current, const Vector &speed) co
}
Rectangle::Rectangle (PValue value)
{
*this = ClassValueHelperExtractFrom<Rectangle,RectangleValue> (value);
}
Rectangle::operator PValue () const
{
return ClassValueHelperConvertTo<Rectangle,RectangleValue> (this);
}
VALUE_HELPER_CPP (Rectangle);
std::ostream &
operator << (std::ostream &os, const Rectangle &rectangle)

View File

@@ -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 <typename T1>
Ptr<ParamSpec> MakeRectangleParamSpec (T1 a1,
Rectangle initialValue);
template <typename T1, typename T2>
Ptr<ParamSpec> MakeRectangleParamSpec (T1 a1, T2 a2,
Rectangle initialValue);
} // namespace ns3
namespace ns3 {
template <typename T1>
Ptr<ParamSpec> MakeRectangleParamSpec (T1 a1,
Rectangle initialValue)
{
return MakeClassValueHelperParamSpec<Rectangle,RectangleValue,RectangleParamSpec> (a1, initialValue);
}
template <typename T1, typename T2>
Ptr<ParamSpec> MakeRectangleParamSpec (T1 a1, T2 a2,
Rectangle initialValue)
{
return MakeClassValueHelperParamSpec<Rectangle,RectangleValue,RectangleParamSpec> (a1, a2, initialValue);
}
VALUE_HELPER_HEADER_2 (Rectangle);
} // namespace ns3

View File

@@ -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<Vector,VectorValue> (value);
}
Vector::operator PValue () const
{
return ClassValueHelperConvertTo<Vector,VectorValue> (this);
}
double
CalculateDistance (const Vector &a, const Vector &b)
{

View File

@@ -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 <typename T1>
Ptr<ParamSpec>
MakeVectorParamSpec (T1 a1, const Vector &initialValue);
template <typename T1, typename T2>
Ptr<ParamSpec>
MakeVectorParamSpec (T1 a1, T2 a2,
const Vector &initialValue);
} // namespace ns3
namespace ns3 {
template <typename T1>
Ptr<ParamSpec>
MakeVectorParamSpec (T1 a1, const Vector &initialValue)
{
return MakeClassValueHelperParamSpec<Vector,VectorValue,VectorParamSpec> (a1, initialValue);
}
template <typename T1, typename T2>
Ptr<ParamSpec>
MakeVectorParamSpec (T1 a1, T2 a2,
const Vector &initialValue)
{
return MakeClassValueHelperParamSpec<Vector,VectorValue,VectorParamSpec> (a1, a2, initialValue);
}
} // namespace ns3
#endif /* VECTOR_H */

View File

@@ -4,7 +4,7 @@
#include <stdint.h>
#include <ostream>
#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 <typename T1>
Ptr<ParamSpec>
MakeAddressParamSpec (T1 a1, Address initialValue);
template <typename T1, typename T2>
Ptr<ParamSpec>
MakeAddressParamSpec (T1 a1, T2 a2, Address initialValue);
} // namespace ns3
namespace ns3 {
template <typename T1>
Ptr<ParamSpec>
MakeAddressParamSpec (T1 a1, Address initialValue)
{
return MakeClassValueHelperParamSpec<Address,AddressValue,AddressParamSpec>
(a1, initialValue);
}
template <typename T1, typename T2>
Ptr<ParamSpec>
MakeAddressParamSpec (T1 a1, T2 a2, Address initialValue)
{
return MakeClassValueHelperParamSpec<Address,AddressValue,AddressParamSpec>
(a1, a2, initialValue);
}
} // namespace ns3
#endif /* ADDRESS_H */

View File

@@ -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<Mac48Address,Mac48AddressValue> (value);
}
Mac48Address::operator PValue () const
{
return ClassValueHelperConvertTo<Mac48Address,Mac48AddressValue> (this);
}
bool operator == (const Mac48Address &a, const Mac48Address &b)
{
return memcmp (a.m_address, b.m_address, 6) == 0;

View File

@@ -23,7 +23,7 @@
#include <stdint.h>
#include <ostream>
#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 <typename T1>
Ptr<ParamSpec>
MakeMac48AddressParamSpec (T1 a1, Mac48Address address);
template <typename T1, typename T2>
Ptr<ParamSpec>
MakeMac48AddressParamSpec (T1 a1, T2 a2, Mac48Address address);
} // namespace ns3
namespace ns3 {
template <typename T1>
Ptr<ParamSpec>
MakeMac48AddressParamSpec (T1 a1, Mac48Address address)
{
return MakeClassValueHelperParamSpec<Mac48Address,Mac48AddressValue,Mac48AddressParamSpec> (a1, address);
}
template <typename T1, typename T2>
Ptr<ParamSpec>
MakeMac48AddressParamSpec (T1 a1, T2 a2, Mac48Address address)
{
return MakeClassValueHelperParamSpec<Mac48Address,Mac48AddressValue,Mac48AddressParamSpec> (a1, a2, address);
}
} // namespace ns3
#endif /* MAC48_ADDRESS_H */