A Discrete-Event Network Simulator
API
vector.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #ifndef NS3_VECTOR_H
20 #define NS3_VECTOR_H
21 
22 #include "attribute-helper.h"
23 #include "attribute.h"
24 
31 namespace ns3
32 {
33 
45 class Vector3D
46 {
47  public:
55  Vector3D(double _x, double _y, double _z);
57  Vector3D();
58 
59  double x;
60  double y;
61  double z;
62 
67  double GetLength() const;
68 
73  double GetLengthSquared() const;
74 
81  friend double CalculateDistance(const Vector3D& a, const Vector3D& b);
82 
89  friend double CalculateDistanceSquared(const Vector3D& a, const Vector3D& b);
90 
99  friend std::ostream& operator<<(std::ostream& os, const Vector3D& vector);
100 
110  friend std::istream& operator>>(std::istream& is, Vector3D& vector);
111 
118  friend bool operator<(const Vector3D& a, const Vector3D& b);
119 
126  friend bool operator<=(const Vector3D& a, const Vector3D& b);
127 
134  friend bool operator>(const Vector3D& a, const Vector3D& b);
135 
142  friend bool operator>=(const Vector3D& a, const Vector3D& b);
143 
150  friend bool operator==(const Vector3D& a, const Vector3D& b);
151 
158  friend bool operator!=(const Vector3D& a, const Vector3D& b);
159 
166  friend Vector3D operator+(const Vector3D& a, const Vector3D& b);
167 
174  friend Vector3D operator-(const Vector3D& a, const Vector3D& b);
175 };
176 
182 class Vector2D
183 {
184  public:
191  Vector2D(double _x, double _y);
193  Vector2D();
194  double x;
195  double y;
196 
197  // works: /** \copydoc ns3::Vector3D::GetLength() */
199  double GetLength() const;
200 
202  double GetLengthSquared() const;
203 
210  friend double CalculateDistance(const Vector2D& a, const Vector2D& b);
211 
218  friend double CalculateDistanceSquared(const Vector2D& a, const Vector2D& b);
219 
228  friend std::ostream& operator<<(std::ostream& os, const Vector2D& vector);
229 
239  friend std::istream& operator>>(std::istream& is, Vector2D& vector);
240 
247  friend bool operator<(const Vector2D& a, const Vector2D& b);
248 
255  friend bool operator<=(const Vector2D& a, const Vector2D& b);
256 
263  friend bool operator>(const Vector2D& a, const Vector2D& b);
264 
271  friend bool operator>=(const Vector2D& a, const Vector2D& b);
272 
279  friend bool operator==(const Vector2D& a, const Vector2D& b);
280 
287  friend bool operator!=(const Vector2D& a, const Vector2D& b);
288 
295  friend Vector2D operator+(const Vector2D& a, const Vector2D& b);
296 
303  friend Vector2D operator-(const Vector2D& a, const Vector2D& b);
304 };
305 
306 double CalculateDistance(const Vector3D& a, const Vector3D& b);
307 double CalculateDistance(const Vector2D& a, const Vector2D& b);
308 double CalculateDistanceSquared(const Vector3D& a, const Vector3D& b);
309 double CalculateDistanceSquared(const Vector2D& a, const Vector2D& b);
310 std::ostream& operator<<(std::ostream& os, const Vector3D& vector);
311 std::ostream& operator<<(std::ostream& os, const Vector2D& vector);
312 std::istream& operator>>(std::istream& is, Vector3D& vector);
313 std::istream& operator>>(std::istream& is, Vector2D& vector);
314 bool operator<(const Vector3D& a, const Vector3D& b);
315 bool operator<(const Vector2D& a, const Vector2D& b);
316 
319 
324 typedef Vector3D Vector;
325 
331 
337 
338 // Document these by hand so they go in group attribute_Vector3D
354 
361 
362 } // namespace ns3
363 
364 #endif /* NS3_VECTOR_H */
Attribute helper (ATTRIBUTE_ )macros definition.
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a 2d vector
Definition: vector.h:183
friend std::istream & operator>>(std::istream &is, Vector2D &vector)
Input streamer.
Definition: vector.cc:212
friend bool operator!=(const Vector2D &a, const Vector2D &b)
Inequality operator.
Definition: vector.cc:254
friend std::ostream & operator<<(std::ostream &os, const Vector2D &vector)
Output streamer.
Definition: vector.cc:205
friend double CalculateDistanceSquared(const Vector2D &a, const Vector2D &b)
Calculate the squared Cartesian distance between two points.
Definition: vector.cc:130
double y
y coordinate of vector
Definition: vector.h:195
friend bool operator==(const Vector2D &a, const Vector2D &b)
Equality operator.
Definition: vector.cc:248
friend bool operator<=(const Vector2D &a, const Vector2D &b)
Less than or equal to comparison operator.
Definition: vector.cc:230
Vector2D()
Constructor: (0.0, 0.0)
Definition: vector.cc:73
friend bool operator<(const Vector2D &a, const Vector2D &b)
Less than comparison operator.
Definition: vector.cc:224
double x
x coordinate of vector
Definition: vector.h:194
friend Vector2D operator+(const Vector2D &a, const Vector2D &b)
Addition operator.
Definition: vector.cc:260
friend bool operator>(const Vector2D &a, const Vector2D &b)
Greater than comparison operator.
Definition: vector.cc:236
friend bool operator>=(const Vector2D &a, const Vector2D &b)
Greater than or equal to comparison operator.
Definition: vector.cc:242
friend Vector2D operator-(const Vector2D &a, const Vector2D &b)
Subtraction operator.
Definition: vector.cc:266
double GetLength() const
Compute the length (magnitude) of the vector.
Definition: vector.cc:88
friend double CalculateDistance(const Vector2D &a, const Vector2D &b)
Calculate the Cartesian distance between two points.
Definition: vector.cc:116
double GetLengthSquared() const
Compute the squared length of the vector.
Definition: vector.cc:102
a 3d vector
Definition: vector.h:46
double GetLength() const
Compute the length (magnitude) of the vector.
Definition: vector.cc:81
friend double CalculateDistance(const Vector3D &a, const Vector3D &b)
Calculate the Cartesian distance between two points.
Definition: vector.cc:109
friend bool operator>=(const Vector3D &a, const Vector3D &b)
Greater than or equal to comparison operator.
Definition: vector.cc:175
friend bool operator!=(const Vector3D &a, const Vector3D &b)
Inequality operator.
Definition: vector.cc:187
Vector3DValue VectorValue
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:330
friend Vector3D operator+(const Vector3D &a, const Vector3D &b)
Addition operator.
Definition: vector.cc:193
friend std::ostream & operator<<(std::ostream &os, const Vector3D &vector)
Output streamer.
Definition: vector.cc:137
double x
x coordinate of vector
Definition: vector.h:59
friend std::istream & operator>>(std::istream &is, Vector3D &vector)
Input streamer.
Definition: vector.cc:144
friend bool operator==(const Vector3D &a, const Vector3D &b)
Equality operator.
Definition: vector.cc:181
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
friend Vector3D operator-(const Vector3D &a, const Vector3D &b)
Subtraction operator.
Definition: vector.cc:199
friend bool operator>(const Vector3D &a, const Vector3D &b)
Greater than comparison operator.
Definition: vector.cc:169
Vector3DChecker VectorChecker
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:336
Vector3D()
Create vector (0.0, 0.0, 0.0)
Definition: vector.cc:58
double z
z coordinate of vector
Definition: vector.h:61
friend bool operator<=(const Vector3D &a, const Vector3D &b)
Less than or equal to comparison operator.
Definition: vector.cc:163
double y
y coordinate of vector
Definition: vector.h:60
double GetLengthSquared() const
Compute the squared length of the vector.
Definition: vector.cc:95
friend bool operator<(const Vector3D &a, const Vector3D &b)
Less than comparison operator.
Definition: vector.cc:157
friend double CalculateDistanceSquared(const Vector3D &a, const Vector3D &b)
Calculate the squared Cartesian distance between two points.
Definition: vector.cc:123
#define ATTRIBUTE_ACCESSOR_DEFINE(type)
Define the attribute accessor functions MakeTypeAccessor for class type.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeVectorChecker()
Definition: vector.cc:44
ATTRIBUTE_HELPER_HEADER(ValueClassTest)
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition: vector.cc:109
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:183
double CalculateDistanceSquared(const Vector3D &a, const Vector3D &b)
Definition: vector.cc:123
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159