diff --git a/src/mobility/vector.cc b/src/core/vector.cc similarity index 56% rename from src/mobility/vector.cc rename to src/core/vector.cc index 32da74326..03e96ce42 100644 --- a/src/mobility/vector.cc +++ b/src/core/vector.cc @@ -24,23 +24,39 @@ namespace ns3 { -ATTRIBUTE_HELPER_CPP (Vector); +ATTRIBUTE_HELPER_CPP (Vector3D); +ATTRIBUTE_HELPER_CPP (Vector2D); + // compatibility for mobility code +Ptr MakeVectorChecker (void) +{ + return MakeVector3DChecker (); +} -Vector::Vector (double _x, double _y, double _z) +Vector3D::Vector3D (double _x, double _y, double _z) : x (_x), y (_y), z (_z) {} -Vector::Vector () +Vector3D::Vector3D () : x (0.0), y (0.0), z (0.0) {} +Vector2D::Vector2D (double _x, double _y) + : x (_x), + y (_y) +{} + +Vector2D::Vector2D () + : x (0.0), + y (0.0) +{} + double -CalculateDistance (const Vector &a, const Vector &b) +CalculateDistance (const Vector3D &a, const Vector3D &b) { double dx = b.x - a.x; double dy = b.y - a.y; @@ -48,13 +64,21 @@ CalculateDistance (const Vector &a, const Vector &b) double distance = std::sqrt (dx * dx + dy * dy + dz * dz); return distance; } +double +CalculateDistance (const Vector2D &a, const Vector2D &b) +{ + double dx = b.x - a.x; + double dy = b.y - a.y; + double distance = std::sqrt (dx * dx + dy * dy); + return distance; +} -std::ostream &operator << (std::ostream &os, const Vector &vector) +std::ostream &operator << (std::ostream &os, const Vector3D &vector) { os << vector.x << ":" << vector.y << ":" << vector.z; return os; } -std::istream &operator >> (std::istream &is, Vector &vector) +std::istream &operator >> (std::istream &is, Vector3D &vector) { char c1, c2; is >> vector.x >> c1 >> vector.y >> c2 >> vector.z; @@ -65,5 +89,20 @@ std::istream &operator >> (std::istream &is, Vector &vector) } return is; } +std::ostream &operator << (std::ostream &os, const Vector2D &vector) +{ + os << vector.x << ":" << vector.y; + return os; +} +std::istream &operator >> (std::istream &is, Vector2D &vector) +{ + char c1; + is >> vector.x >> c1 >> vector.y; + if (c1 != ':') + { + is.setstate (std::ios_base::failbit); + } + return is; +} } // namespace ns3 diff --git a/src/core/vector.h b/src/core/vector.h new file mode 100644 index 000000000..434765e9e --- /dev/null +++ b/src/core/vector.h @@ -0,0 +1,126 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ +#ifndef NS3_VECTOR_H +#define NS3_VECTOR_H + +#include "ns3/attribute.h" +#include "ns3/attribute-helper.h" + +namespace ns3 { + +/** + * \brief a 3d vector + */ +class Vector3D +{ +public: + /** + * \param _x x coordinate of vector + * \param _y y coordinate of vector + * \param _z z coordinate of vector + * + * Create vector (_x, _y, _z) + */ + Vector3D (double _x, double _y, double _z); + /** + * Create vector (0.0, 0.0, 0.0) + */ + Vector3D (); + /** + * x coordinate of vector + */ + double x; + /** + * y coordinate of vector + */ + double y; + /** + * z coordinate of vector + */ + double z; +}; + +/** + * \brief a 3d vector + */ +class Vector2D +{ +public: + /** + * \param _x x coordinate of vector + * \param _y y coordinate of vector + * + * Create vector (_x, _y) + */ + Vector2D (double _x, double _y); + /** + * Create vector vector (0.0, 0.0) + */ + Vector2D (); + /** + * x coordinate of vector + */ + double x; + /** + * y coordinate of vector + */ + double y; +}; + +/** + * \param a one point + * \param b another point + * \returns the cartesian distance between a and b. + */ +double CalculateDistance (const Vector3D &a, const Vector3D &b); + +/** + * \param a one point + * \param b another point + * \returns the cartesian distance between a and b. + */ +double CalculateDistance (const Vector2D &a, const Vector2D &b); + +/** + * \class ns3::Vector3DValue + * \brief hold objects of type ns3::Vector3D + */ +/** + * \class ns3::Vector2DValue + * \brief hold objects of type ns3::Vector2D + */ +ATTRIBUTE_HELPER_HEADER (Vector3D); +ATTRIBUTE_HELPER_HEADER (Vector2D); + +std::ostream &operator << (std::ostream &os, const Vector3D &vector); +std::istream &operator >> (std::istream &is, Vector3D &vector); +std::ostream &operator << (std::ostream &os, const Vector2D &vector); +std::istream &operator >> (std::istream &is, Vector2D &vector); + +// for compatibility with mobility models +typedef Vector3D Vector; +typedef Vector3DValue VectorValue; +typedef Vector3DChecker VectorChecker; +ATTRIBUTE_ACCESSOR_DEFINE(Vector); +Ptr MakeVectorChecker (void); + +} // namespace ns3 + +#endif /* NS3_VECTOR_H */ diff --git a/src/core/wscript b/src/core/wscript index 1c8a5de37..b75c99e8b 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -78,6 +78,7 @@ def build(bld): 'config.cc', 'callback.cc', 'names.cc', + 'vector.cc', ] headers = bld.new_task_gen('ns3header') @@ -123,6 +124,7 @@ def build(bld): 'deprecated.h', 'abort.h', 'names.h', + 'vector.h', ] if sys.platform == 'win32': diff --git a/src/mobility/constant-position-mobility-model.h b/src/mobility/constant-position-mobility-model.h index 31aa2e978..ee9c894c7 100644 --- a/src/mobility/constant-position-mobility-model.h +++ b/src/mobility/constant-position-mobility-model.h @@ -21,7 +21,6 @@ #define CONSTANT_POSITION_MOBILITY_MODEL_H #include "mobility-model.h" -#include "vector.h" namespace ns3 { diff --git a/src/mobility/constant-velocity-helper.h b/src/mobility/constant-velocity-helper.h index 3430381e6..95346d4a1 100644 --- a/src/mobility/constant-velocity-helper.h +++ b/src/mobility/constant-velocity-helper.h @@ -21,7 +21,7 @@ #define CONSTANT_VELOCITY_HELPER_H #include "ns3/nstime.h" -#include "vector.h" +#include "ns3/vector.h" namespace ns3 { diff --git a/src/mobility/constant-velocity-mobility-model.h b/src/mobility/constant-velocity-mobility-model.h index 6db3312ec..8936c3ad0 100644 --- a/src/mobility/constant-velocity-mobility-model.h +++ b/src/mobility/constant-velocity-mobility-model.h @@ -21,8 +21,8 @@ #define CONSTANT_VELOCITY_MOBILITY_MODEL_H #include -#include "mobility-model.h" #include "ns3/nstime.h" +#include "mobility-model.h" #include "constant-velocity-helper.h" namespace ns3 { diff --git a/src/mobility/mobility-model.h b/src/mobility/mobility-model.h index 1d58baf9e..6fd268c37 100644 --- a/src/mobility/mobility-model.h +++ b/src/mobility/mobility-model.h @@ -20,8 +20,7 @@ #ifndef MOBILITY_MODEL_H #define MOBILITY_MODEL_H -#include "vector.h" - +#include "ns3/vector.h" #include "ns3/object.h" #include "ns3/traced-callback.h" diff --git a/src/mobility/position-allocator.h b/src/mobility/position-allocator.h index e9756896c..da6f49f0b 100644 --- a/src/mobility/position-allocator.h +++ b/src/mobility/position-allocator.h @@ -22,7 +22,7 @@ #include "ns3/object.h" #include "ns3/random-variable.h" -#include "vector.h" +#include "ns3/vector.h" namespace ns3 { diff --git a/src/mobility/rectangle.cc b/src/mobility/rectangle.cc index 6a0c5e221..ee5e29f0f 100644 --- a/src/mobility/rectangle.cc +++ b/src/mobility/rectangle.cc @@ -18,7 +18,7 @@ * Author: Mathieu Lacage */ #include "rectangle.h" -#include "vector.h" +#include "ns3/vector.h" #include "ns3/assert.h" #include "ns3/fatal-error.h" #include diff --git a/src/mobility/rectangle.h b/src/mobility/rectangle.h index fcc8fc1cb..90d147736 100644 --- a/src/mobility/rectangle.h +++ b/src/mobility/rectangle.h @@ -22,11 +22,10 @@ #include "ns3/attribute.h" #include "ns3/attribute-helper.h" +#include "ns3/vector.h" namespace ns3 { -class Vector; - /** * \brief a 2d rectangle */ diff --git a/src/mobility/vector.h b/src/mobility/vector.h deleted file mode 100644 index e3e3191aa..000000000 --- a/src/mobility/vector.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#ifndef VECTOR_H -#define VECTOR_H - -#include "ns3/attribute.h" -#include "ns3/attribute-helper.h" - -namespace ns3 { - -/** - * \brief a 3d cartesian position vector - * - * Unit is meters. - */ -class Vector -{ -public: - /** - * \param _x x coordinate of vector vector - * \param _y y coordinate of vector vector - * \param _z z coordinate of vector vector - * - * Create vector vector (_x, _y, _z) - */ - Vector (double _x, double _y, double _z); - /** - * Create vector vector (0.0, 0.0, 0.0) - */ - Vector (); - /** - * x coordinate of vector vector - */ - double x; - /** - * y coordinate of vector vector - */ - double y; - /** - * z coordinate of vector vector - */ - double z; -}; - -/** - * \param a one point - * \param b another point - * \returns the cartesian distance between a and b. - */ -double CalculateDistance (const Vector &a, const Vector &b); - -/** - * \class ns3::VectorValue - * \brief hold objects of type ns3::Vector - */ - -ATTRIBUTE_HELPER_HEADER (Vector); - -std::ostream &operator << (std::ostream &os, const Vector &vector); -std::istream &operator >> (std::istream &is, Vector &vector); - -} // namespace ns3 - -#endif /* VECTOR_H */ diff --git a/src/mobility/wscript b/src/mobility/wscript index ad368ebbf..6bcfd2e5c 100644 --- a/src/mobility/wscript +++ b/src/mobility/wscript @@ -3,7 +3,6 @@ def build(bld): mobility = bld.create_ns3_module('mobility', ['core', 'simulator']) mobility.source = [ - 'vector.cc', 'hierarchical-mobility-model.cc', 'mobility-model.cc', 'position-allocator.cc', @@ -20,7 +19,6 @@ def build(bld): headers = bld.new_task_gen('ns3header') headers.module = 'mobility' headers.source = [ - 'vector.h', 'hierarchical-mobility-model.h', 'mobility-model.h', 'position-allocator.h',