A Discrete-Event Network Simulator
API
data-rate.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 //
3 // Copyright (c) 2006 Georgia Tech Research Corporation
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License version 2 as
7 // published by the Free Software Foundation;
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 //
18 // Author: Rajib Bhattacharjea<raj.b@gatech.edu>
19 //
20 
21 #ifndef DATA_RATE_H
22 #define DATA_RATE_H
23 
24 #include <string>
25 #include <iostream>
26 #include <stdint.h>
27 #include "ns3/nstime.h"
28 #include "ns3/attribute.h"
29 #include "ns3/attribute-helper.h"
30 #include "ns3/deprecated.h"
31 
32 namespace ns3 {
33 
88 class DataRate
89 {
90 public:
91  DataRate ();
100  DataRate (uint64_t bps);
119  DataRate (std::string rate);
120 
127 
134 
141 
148 
158  DataRate operator * (double rhs);
159 
169  DataRate& operator *= (double rhs);
170 
178  DataRate operator * (uint64_t rhs);
179 
187  DataRate& operator *= (uint64_t rhs);
188 
189 
195  bool operator < (const DataRate& rhs) const;
196 
202  bool operator <= (const DataRate& rhs) const;
203 
209  bool operator > (const DataRate& rhs) const;
210 
216  bool operator >= (const DataRate& rhs) const;
217 
223  bool operator == (const DataRate& rhs) const;
224 
230  bool operator != (const DataRate& rhs) const;
231 
239  Time CalculateBytesTxTime (uint32_t bytes) const;
240 
248  Time CalculateBitsTxTime (uint32_t bits) const;
249 
254  uint64_t GetBitRate () const;
255 
256 private:
257 
272  static bool DoParse (const std::string s, uint64_t *v);
273 
274  // Uses DoParse
275  friend std::istream &operator >> (std::istream &is, DataRate &rate);
276 
277  uint64_t m_bps;
278 };
279 
287 std::ostream &operator << (std::ostream &os, const DataRate &rate);
288 
296 std::istream &operator >> (std::istream &is, DataRate &rate);
297 
299 
300 
309 double operator* (const DataRate& lhs, const Time& rhs);
318 double operator* (const Time& lhs, const DataRate& rhs);
319 
320 namespace TracedValueCallback {
321 
329 typedef void (* DataRate)(DataRate oldValue,
330  DataRate newValue);
331 
332 } // namespace TracedValueCallback
333 
334 } // namespace ns3
335 
336 #endif /* DATA_RATE_H */
bool operator==(const DataRate &rhs) const
Definition: data-rate.cc:265
DataRate operator*(double rhs)
Scales the DataRate.
Definition: data-rate.cc:223
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
bool operator!=(const DataRate &rhs) const
Definition: data-rate.cc:270
bool operator>(const DataRate &rhs) const
Definition: data-rate.cc:255
bool operator<=(const DataRate &rhs) const
Definition: data-rate.cc:250
DataRate operator+(DataRate rhs)
Definition: data-rate.cc:199
uint64_t m_bps
data rate [bps]
Definition: data-rate.h:277
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:160
bool operator<(const DataRate &rhs) const
Definition: data-rate.cc:245
static bool DoParse(const std::string s, uint64_t *v)
Parse a string representing a DataRate into an uint64_t.
Definition: data-rate.cc:34
DataRate operator-(DataRate rhs)
Definition: data-rate.cc:210
uint64_t GetBitRate() const
Get the underlying bitrate.
Definition: data-rate.cc:287
Class for representing data rates.
Definition: data-rate.h:88
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition: int64x64.h:117
DataRate & operator+=(DataRate rhs)
Definition: data-rate.cc:204
friend std::istream & operator>>(std::istream &is, DataRate &rate)
Stream extraction operator.
Definition: data-rate.cc:310
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time CalculateBitsTxTime(uint32_t bits) const
Calculate transmission time.
Definition: data-rate.cc:281
DataRate & operator*=(double rhs)
Scales the DataRate.
Definition: data-rate.cc:228
DataRate & operator-=(DataRate rhs)
Definition: data-rate.cc:216
Time CalculateBytesTxTime(uint32_t bytes) const
Calculate transmission time.
Definition: data-rate.cc:275
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type
bool operator>=(const DataRate &rhs) const
Definition: data-rate.cc:260