|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // (C) 2005 Vojtech Janota 00003 // 00004 // This library is free software, you can redistribute it 00005 // and/or modify 00006 // it under the terms of the GNU Lesser General Public License 00007 // as published by the Free Software Foundation; 00008 // either version 2 of the License, or any later version. 00009 // The library 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. 00012 // See the GNU Lesser General Public License for more details. 00013 // 00014 00015 #include "Utils.h" 00016 #include "IntServ.h" 00017 00018 void removeDuplicates(std::vector<int>& vec) 00019 { 00020 for (unsigned int i = 0; i < vec.size(); i++) 00021 { 00022 unsigned int j; 00023 for (j = 0; j < i; j++) 00024 if (vec[j] == vec[i]) 00025 break; 00026 if (j < i) 00027 { 00028 vec.erase(vec.begin() + i); 00029 --i; 00030 } 00031 } 00032 } 00033 00034 int find(const EroVector& ERO, IPAddress node) 00035 { 00036 for (unsigned int i = 0; i < ERO.size(); i++) 00037 if (ERO[i].node == node) 00038 return i; 00039 ASSERT(false); 00040 return -1; // to prevent warning 00041 } 00042 00043 bool find(std::vector<int>& vec, int value) 00044 { 00045 for (unsigned int i = 0; i < vec.size(); i++) 00046 if (vec[i] == value) 00047 return true; 00048 return false; 00049 } 00050 00051 bool find(const IPAddressVector& vec, IPAddress addr) 00052 { 00053 for (unsigned int i = 0; i < vec.size(); i++) 00054 if (vec[i] == addr) 00055 return true; 00056 return false; 00057 } 00058 00059 void append(std::vector<int>& dest, const std::vector<int>& src) 00060 { 00061 for (unsigned int i = 0; i < src.size(); i++) 00062 dest.push_back(src[i]); 00063 } 00064 00065 cModule *getPayloadOwner(cPacket *msg) 00066 { 00067 while(msg->getEncapsulatedPacket()) 00068 msg = msg->getEncapsulatedPacket(); 00069 00070 if (msg->hasPar("owner")) 00071 return simulation.getModule(msg->par("owner")); 00072 else 00073 return NULL; 00074 } 00075 00076 /* 00077 void prepend(EroVector& dest, const EroVector& src, bool reverse) 00078 { 00079 ASSERT(dest.size() > 0); 00080 ASSERT(src.size() > 0); 00081 00082 int size = src.size(); 00083 for (unsigned int i = 0; i < size; i++) 00084 { 00085 int n = reverse? i: size - 1 - i; 00086 00087 if (dest[0] == src[n]) 00088 continue; 00089 00090 dest.insert(dest.begin(), src[n]); 00091 } 00092 } 00093 */ 00094 00095 00096