NiceCluster.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 "NiceCluster.h"
00026 
00027 // Constructor *****************************************************************
00028 NiceCluster::NiceCluster()
00029 {
00030     WATCH_SET(cluster);
00031     WATCH(leader);
00032 
00033     setLeader(TransportAddress::UNSPECIFIED_NODE);
00034 
00035     last_LT = 0.0;
00036 
00037 } // NICECluster
00038 
00039 // Adds member to cluster ******************************************************
00040 void NiceCluster::add( const TransportAddress& member )
00041 {
00042 
00043     cluster.insert(member);
00044 
00045 } // add
00046 //
00047 // Clears all cluster contents *************************************************
00048 void NiceCluster::clear()
00049 {
00050 
00051     cluster.clear();
00052     setLeader(TransportAddress::UNSPECIFIED_NODE);
00053 
00054     last_LT = 0.0;
00055 
00056 } // clear
00057 
00058 // Check if cluster member *****************************************************
00059 bool NiceCluster::contains( const TransportAddress& member )
00060 {
00061 
00062     ConstClusterIterator it = cluster.find(member);
00063 
00064     if (it != cluster.end())
00065         return true;
00066 
00067     return false;
00068 
00069 } // contains
00070 //
00071 // Get cluster size ************************************************************
00072 int NiceCluster::getSize()
00073 {
00074 
00075     return cluster.size();
00076 
00077 } // getSize
00078 
00079 // Get address of specific member **********************************************
00080 const TransportAddress& NiceCluster::get( int i )
00081 {
00082 
00083     ConstClusterIterator it = cluster.begin();
00084 
00085     for (int j = 0; j < i; j++)
00086         it++;
00087 
00088     return *it;
00089 
00090 } // get
00091 
00092 void NiceCluster::remove(const TransportAddress& member)
00093 {
00094 
00095     cluster.erase(member);
00096 
00097 } // remove
00098 
00099 // set cluster leader **********************************************************
00100 void NiceCluster::setLeader(const TransportAddress& leader)
00101 {
00102 
00103     this->leader = leader;
00104 
00105 //      //cout << "Leader set to " << leader << endl;
00106 
00107 } // setLeader
00108 
00109 // get current cluster leader **************************************************
00110 const TransportAddress& NiceCluster::getLeader()
00111 {
00112 
00113     return leader;
00114 
00115 } // getLeader
00116 
00117 
00118 simtime_t NiceCluster::get_Last_LT()
00119 {
00120 
00121     return last_LT;
00122 
00123 }
00124 
00125 void NiceCluster::set_Last_LT()
00126 {
00127 
00128     last_LT = simTime();
00129 
00130 }
00131 
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3