OverSim
ProxNodeHandle.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
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 
25 #include "ProxNodeHandle.h"
26 
27 // This is the usual value for SimTime::getMaxTime(), may change with a different SimTime scale.
28 // This value is declared directly a constant, since SimTime::getMaxTime()
29 // isn't set yet when the program starts.
30 #define MAXTIME_DBL 9223372036//.854775807
31 
32 const Prox Prox::PROX_SELF(0, 1);
35 const Prox Prox::PROX_WAITING(MAXTIME_DBL, 0.999);
36 
37 Prox::operator double() { return proximity; };
38 Prox::operator simtime_t() { return (proximity >= MAXTIME_DBL)
39  ? MAXTIME : proximity; };
40 
42 Prox::Prox(simtime_t prox) : proximity(SIMTIME_DBL(prox)), accuracy(1) {}
43 Prox::Prox(simtime_t prox, double acc) : proximity(SIMTIME_DBL(prox)), accuracy(acc) {}
44 Prox::Prox(double prox, double acc) : proximity(prox), accuracy(acc) {}
45 
46 bool Prox::operator==(Prox p) const { return proximity == p.proximity && accuracy == p.accuracy; }
47 bool Prox::operator!=(Prox p) const { return !(*this == p); }
48 
49 
50 // predefined node handle
52 
54 : NodeHandle(nodeHandle), prox(prox)
55 {
56  //...
57 }
58 
59 ProxNodeHandle::ProxNodeHandle(const NodeHandle& nodeHandle, const Prox& prox)
60 : NodeHandle(nodeHandle), prox(prox)
61 {
62  //...
63 }
64 
65 
66 // predefined node handle
68 
70 : TransportAddress(transportAddress), prox(prox)
71 {
72  //...
73 }
74 
76 : TransportAddress(transportAddress), prox(prox)
77 {
78  //...
79 }
80 
81 
82 std::ostream& operator<<(std::ostream& os, const Prox& prox)
83 {
84  if (prox == Prox::PROX_SELF) os << "[self]";
85  else if (prox == Prox::PROX_UNKNOWN) os << "[unknown]";
86  else if (prox == Prox::PROX_WAITING) os << "[waiting]";
87  else if (prox == Prox::PROX_TIMEOUT) os << "[timeout]";
88  else {
89  os << prox.proximity;
90  if (prox.accuracy != 1) os << " (a=" << prox.accuracy << ")";
91  }
92  return os;
93 }
94 
95 std::ostream& operator<<(std::ostream& os,
96  const ProxTransportAddress& address)
97 {
98  os << static_cast<const TransportAddress&>(address)
99  << ", rtt=" << address.getProx();
100 
101  return os;
102 }
103