diff --git a/src/common/data-rate.cc b/src/common/data-rate.cc index 5e8358804..564664a7e 100644 --- a/src/common/data-rate.cc +++ b/src/common/data-rate.cc @@ -185,6 +185,36 @@ uint64_t DataRate::GetBitRate() const return m_bps; } +DataRate::DataRate (PValue value) +{ + *this = ClassValueHelperExtractFrom (value); +} +DataRate::operator PValue () const +{ + return ClassValueHelperConvertTo (this); +} + +std::ostream &operator << (std::ostream &os, const DataRate &rate) +{ + os << rate.GetBitRate () << "bps"; + return os; +} +std::istream &operator >> (std::istream &is, DataRate &rate) +{ + std::string value; + is >> value; + uint64_t v; + bool ok = DoParse (value, &v); + if (!ok) + { + is.setstate (std::ios_base::failbit); + } + rate = DataRate (v); + return is; +} + + + double operator*(const DataRate& lhs, const Time& rhs) { return rhs.GetSeconds()*lhs.GetBitRate(); diff --git a/src/common/data-rate.h b/src/common/data-rate.h index 3607f4916..39ade9d21 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -27,6 +27,8 @@ #include #include "ns3/nstime.h" #include "ns3/default-value.h" +#include "ns3/value.h" +#include "ns3/class-value-helper.h" namespace ns3 { @@ -94,10 +96,27 @@ class DataRate */ uint64_t GetBitRate() const; - private: + DataRate (PValue value); + operator PValue () const; +private: uint64_t m_bps; static uint64_t Parse(const std::string); }; + +std::ostream &operator << (std::ostream &os, const DataRate &rate); +std::istream &operator >> (std::istream &is, DataRate &rate); + +class DataRateValue : public Value {}; +class DataRateParamSpec : public Value {}; + +template +Ptr +MakeDataRateParamSpec (T1 a1, DataRate initialValue); + +template +Ptr +MakeDataRateParamSpec (T1 a1, T2 a2, DataRate initialValue); + /** * \param lhs * \param rhs @@ -122,6 +141,26 @@ private: DataRate m_value; }; -};//namespace ns3 +} //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 */