A Discrete-Event Network Simulator
API
queue-size.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 //
3 // Copyright (c) 2018 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
19 //
20 
21 #ifndef QUEUE_SIZE_H
22 #define QUEUE_SIZE_H
23 
24 #include <string>
25 #include <iostream>
26 #include "ns3/attribute.h"
27 #include "ns3/attribute-helper.h"
28 #include "ns3/abort.h"
29 
30 namespace ns3 {
31 
43 {
46 };
47 
94 class QueueSize
95 {
96 public:
97  QueueSize ();
105  QueueSize (QueueSizeUnit unit, uint32_t value);
123  QueueSize (std::string size);
124 
130  bool operator < (const QueueSize& rhs) const;
131 
137  bool operator <= (const QueueSize& rhs) const;
138 
144  bool operator > (const QueueSize& rhs) const;
145 
151  bool operator >= (const QueueSize& rhs) const;
152 
158  bool operator == (const QueueSize& rhs) const;
159 
165  bool operator != (const QueueSize& rhs) const;
166 
171  QueueSizeUnit GetUnit () const;
172 
177  uint32_t GetValue () const;
178 
179 private:
180 
194  static bool DoParse (const std::string s, QueueSizeUnit *unit, uint32_t *value);
195 
196  // Uses DoParse
197  friend std::istream &operator >> (std::istream &is, QueueSize &size);
198 
200  uint32_t m_value;
201 };
202 
210 std::ostream &operator << (std::ostream &os, const QueueSize &size);
211 
219 std::istream &operator >> (std::istream &is, QueueSize &size);
220 
222 
223 
231 template <typename Item>
232 QueueSize operator+ (const QueueSize& lhs, const Ptr<Item>& rhs);
240 template <typename Item>
241 QueueSize operator+ (const Ptr<Item>& lhs, const QueueSize& rhs);
242 
243 
249 template <typename Item>
250 QueueSize operator+ (const QueueSize& lhs, const Ptr<Item>& rhs)
251 {
252  if (lhs.GetUnit () == QueueSizeUnit::PACKETS)
253  {
254  return QueueSize (lhs.GetUnit (), lhs.GetValue () + 1);
255  }
256  if (lhs.GetUnit () == QueueSizeUnit::BYTES)
257  {
258  return QueueSize (lhs.GetUnit (), lhs.GetValue () + rhs->GetSize ());
259  }
260  NS_FATAL_ERROR ("Unknown queue size mode");
261 }
262 
263 template <typename Item>
264 QueueSize operator+ (const Ptr<Item>& lhs, const QueueSize& rhs)
265 {
266  if (rhs.GetUnit () == QueueSizeUnit::PACKETS)
267  {
268  return QueueSize (rhs.GetUnit (), rhs.GetValue () + 1);
269  }
270  if (rhs.GetUnit () == QueueSizeUnit::BYTES)
271  {
272  return QueueSize (rhs.GetUnit (), rhs.GetValue () + lhs->GetSize ());
273  }
274  NS_FATAL_ERROR ("Unknown queue size mode");
275 }
276 
277 
278 } // namespace ns3
279 
280 #endif /* QUEUE_SIZE_H */
Class for representing queue sizes.
Definition: queue-size.h:95
bool operator>(const QueueSize &rhs) const
Definition: queue-size.cc:140
friend std::istream & operator>>(std::istream &is, QueueSize &size)
Stream extraction operator.
Definition: queue-size.cc:194
bool operator<(const QueueSize &rhs) const
Definition: queue-size.cc:126
bool operator<=(const QueueSize &rhs) const
Definition: queue-size.cc:133
QueueSizeUnit GetUnit() const
Get the underlying unit.
Definition: queue-size.cc:168
bool operator!=(const QueueSize &rhs) const
Definition: queue-size.cc:161
uint32_t m_value
queue size [bytes or packets]
Definition: queue-size.h:200
bool operator>=(const QueueSize &rhs) const
Definition: queue-size.cc:147
bool operator==(const QueueSize &rhs) const
Definition: queue-size.cc:154
QueueSizeUnit m_unit
unit
Definition: queue-size.h:199
static bool DoParse(const std::string s, QueueSizeUnit *unit, uint32_t *value)
Parse a string representing a QueueSize.
Definition: queue-size.cc:32
uint32_t GetValue() const
Get the underlying value.
Definition: queue-size.cc:174
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
int64x64_t operator+(const int64x64_t &lhs, const int64x64_t &rhs)
Addition operator.
Definition: int64x64.h:89
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition: queue-size.h:43
@ BYTES
Use number of bytes for queue size.
Definition: queue-size.h:45
@ PACKETS
Use number of packets for queue size.
Definition: queue-size.h:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:162
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:139