ProxNodeHandle.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00025 #include "ProxNodeHandle.h"
00026 
00027 // This is the usual value for SimTIme::getMaxTime(), may change with a different SimTime scale.
00028 // This value is declared directly a constant, since SimTime::getMaxTime()
00029 // isn't set yet when the program starts.
00030 #define MAXTIME_DBL 9223372036.854775807
00031 
00032 const Prox Prox::PROX_SELF(0, 1);
00033 const Prox Prox::PROX_UNKNOWN(MAXTIME_DBL, 0);
00034 const Prox Prox::PROX_TIMEOUT(MAXTIME_DBL, 1);
00035 //const Prox Prox::PROX_WAITING = {MAXTIME_DBL, 0.6};
00036 
00037 Prox::operator double() { return proximity; };
00038 Prox::operator simtime_t() { return (proximity >= MAXTIME_DBL)
00039                                    ? MAXTIME : proximity; };
00040 
00041 Prox::Prox() {}
00042 Prox::Prox(simtime_t prox) : proximity(SIMTIME_DBL(prox)), accuracy(1) {}
00043 Prox::Prox(simtime_t prox, double acc) : proximity(SIMTIME_DBL(prox)), accuracy(acc) {}
00044 Prox::Prox(double prox, double acc) : proximity(prox), accuracy(acc) {}
00045 
00046 bool Prox::operator==(Prox p) const { return proximity == p.proximity && accuracy == p.accuracy; }
00047 bool Prox::operator!=(Prox p) const { return !(*this == p); }
00048 
00049 
00050 // predefined node handle
00051 const ProxNodeHandle ProxNodeHandle::UNSPECIFIED_NODE;
00052 
00053 ProxNodeHandle::ProxNodeHandle()
00054 {
00055     // TODO Auto-generated constructor stub
00056 
00057 }
00058 
00059 ProxNodeHandle::~ProxNodeHandle()
00060 {
00061     // TODO Auto-generated destructor stub
00062 }
00063 
00064 ProxNodeHandle::ProxNodeHandle(const NodeHandle& nodeHandle)
00065 : NodeHandle(nodeHandle), prox(prox)
00066 {
00067     //...
00068 }
00069 
00070 ProxNodeHandle::ProxNodeHandle(const NodeHandle& nodeHandle, const Prox& prox)
00071 : NodeHandle(nodeHandle), prox(prox)
00072 {
00073     //...
00074 }
00075 
00076 std::ostream& operator<<(std::ostream& os, const Prox& prox)
00077 {
00078     if (prox == Prox::PROX_SELF) os << "[self]";
00079     else if (prox == Prox::PROX_UNKNOWN) os << "[unknown]";
00080     else if (prox == Prox::PROX_TIMEOUT) os << "[timeout]";
00081     else {
00082         os << prox.proximity;
00083         if (prox.accuracy != 1) os << " (a=" << prox.accuracy << ")";
00084     }
00085    return os;
00086 }
00087 
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3