A Discrete-Event Network Simulator
API
mobility-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006,2007 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include <cmath>
22 
23 #include "mobility-model.h"
24 #include "ns3/trace-source-accessor.h"
25 
26 namespace ns3 {
27 
28 NS_OBJECT_ENSURE_REGISTERED (MobilityModel);
29 
30 TypeId
32 {
33  static TypeId tid = TypeId ("ns3::MobilityModel")
34  .SetParent<Object> ()
35  .SetGroupName ("Mobility")
36  .AddAttribute ("Position", "The current position of the mobility model.",
38  VectorValue (Vector (0.0, 0.0, 0.0)),
42  .AddAttribute ("Velocity", "The current velocity of the mobility model.",
44  VectorValue (Vector (0.0, 0.0, 0.0)), // ignored initial value.
47  .AddTraceSource ("CourseChange",
48  "The value of the position and/or velocity vector changed",
50  "ns3::MobilityModel::TracedCallback")
51  ;
52  return tid;
53 }
54 
56 {
57 }
58 
60 {
61 }
62 
63 Vector
65 {
66  return DoGetPosition ();
67 }
68 Vector
69 MobilityModel::GetPositionWithReference (const Vector& referencePosition) const
70 {
71  return DoGetPositionWithReference (referencePosition);
72 }
73 
74 // Default implementation ignores referencePosition
75 Vector
76 MobilityModel::DoGetPositionWithReference (const Vector& referencePosition) const
77 {
78  return DoGetPosition ();
79 }
80 
81 Vector
83 {
84  return DoGetVelocity ();
85 }
86 
87 void
88 MobilityModel::SetPosition (const Vector &position)
89 {
90  DoSetPosition (position);
91 }
92 
93 double
95 {
96  Vector oPosition = other->DoGetPosition ();
97  Vector position = DoGetPosition ();
98  return CalculateDistance (position, oPosition);
99 }
100 
101 double
103 {
104  return (GetVelocity () - other->GetVelocity ()).GetLength ();
105 }
106 
107 void
109 {
110  m_courseChangeTrace (this);
111 }
112 
113 int64_t
115 {
116  return DoAssignStreams (start);
117 }
118 
119 // Default implementation does nothing
120 int64_t
122 {
123  return 0;
124 }
125 
126 
127 } // namespace ns3
ns3::TracedCallback< Ptr< const MobilityModel > > m_courseChangeTrace
Used to alert subscribers that a change in direction, velocity, or position has occurred.
virtual ~MobilityModel()=0
Vector GetPositionWithReference(const Vector &referencePosition) const
This method may be used if the position returned may depend on some reference position provided.
static TypeId GetTypeId(void)
Register this type with the TypeId system.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
Vector GetVelocity(void) const
virtual Vector DoGetPosition(void) const =0
double GetRelativeSpeed(Ptr< const MobilityModel > other) const
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
virtual Vector DoGetPositionWithReference(const Vector &referencePosition) const
void NotifyCourseChange(void) const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
virtual void DoSetPosition(const Vector &position)=0
virtual int64_t DoAssignStreams(int64_t start)
The default implementation does nothing but return the passed-in parameter.
void SetPosition(const Vector &position)
virtual Vector DoGetVelocity(void) const =0
Vector GetPosition(void) const
A base class which provides memory management and object aggregation.
Definition: object.h:88
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
a unique identifier for an interface.
Definition: type-id.h:59
@ ATTR_GET
The attribute can be read.
Definition: type-id.h:64
@ ATTR_SET
The attribute can be written.
Definition: type-id.h:65
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
AttributeValue implementation for Vector.
Ptr< const AttributeAccessor > MakeVectorAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: vector.h:354
Ptr< const AttributeChecker > MakeVectorChecker(void)
Definition: vector.cc:41
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition: vector.cc:105
def start()
Definition: core.py:1853