![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #ifndef WNS_LDK_COMPOUND_HPP 00029 #define WNS_LDK_COMPOUND_HPP 00030 00031 #include <WNS/ReferenceModifier.hpp> 00032 #include <WNS/ldk/CommandPool.hpp> 00033 //#include <WNS/ldk/CommandProxy.hpp> 00034 #include <WNS/SmartPtr.hpp> 00035 #include <WNS/osi/PDU.hpp> 00036 #include <WNS/Birthmark.hpp> 00037 #include <WNS/Assure.hpp> 00038 #include <WNS/TypeInfo.hpp> 00039 00040 /* 00041 * for compound journeys (JOURNEY) 00042 * Journey records the path of a compound through FUs. 00043 * this is expensive and should be made optional. 00044 * to find all changes due to this journey path, search for 00045 * the tag JOURNEY (within libwns and glue.) 00046 */ 00047 #include <list> 00048 #include <cstdio> 00049 00050 namespace wns { namespace ldk { 00051 00052 class FunctionalUnit; 00053 00054 struct Visit 00055 { 00056 Visit(simTimeType _t, const std::string& _location) : 00057 t(_t), 00058 location(_location) 00059 {} 00060 00061 simTimeType t; 00062 std::string location; 00063 00064 bool 00065 operator==(const Visit& other) const 00066 { 00067 return (t == other.t) && (location == other.location); 00068 } 00069 }; 00070 00074 class Compound : 00075 public virtual HasBirthmark, 00076 public wns::osi::PDU 00077 { 00078 public: 00079 typedef std::list<Visit> JourneyContainer; 00080 00081 Compound(CommandPool* commandPool = NULL, const wns::osi::PDUPtr& sdu = wns::osi::PDUPtr()) : 00082 wns::osi::PDU(commandPool, sdu.getPtr()), 00083 fu(NULL) 00084 {} 00085 00086 CommandPool* 00087 getCommandPool() const 00088 { 00089 assure(PDU::getPCI(), "PCI is NULL."); 00090 assure(dynamic_cast<CommandPool*>(PDU::getPCI()), "PCI is not of the desired type."); 00091 return static_cast<CommandPool*>(PDU::getPCI()); 00092 } // getCommandPool 00093 00094 osi::PDUPtr 00095 getData() const 00096 { 00097 if(getUserData()) { 00098 return osi::PDUPtr(getUserData()); 00099 } else { 00100 return osi::PDUPtr(); 00101 } 00102 } // getData 00103 00104 SmartPtr<Compound> 00105 copy() 00106 { 00107 return SmartPtr<Compound>(clone()); 00108 } // copy 00109 00110 void 00111 visit(const FunctionalUnit* fu) const; // JOURNEY 00112 00113 std::string 00114 dumpJourney() const // JOURNEY 00115 { 00116 std::stringstream ss; 00117 00118 for(JourneyContainer::iterator it = journey.begin(); 00119 it != journey.end(); 00120 ++it) { 00121 ss << "\n("; 00122 ss.width(11); 00123 ss.setf(std::ios_base::fixed, std::ios_base::floatfield); 00124 ss.precision(7); 00125 ss << std::right << it->t << ") " << it->location.c_str(); 00126 } 00127 00128 return ss.str(); 00129 00130 } // dumpJourney 00131 00132 const JourneyContainer& 00133 getJourney() const 00134 { 00135 return journey; 00136 } 00137 00138 void 00139 setCallingFU(FunctionalUnit* _fu) 00140 { 00141 fu = _fu; 00142 } 00143 00144 FunctionalUnit* 00145 getCallingFU() 00146 { 00147 return fu; 00148 } 00149 00150 virtual Compound* 00151 clone() 00152 { 00153 Compound* result = new Compound(new CommandPool(*this->getCommandPool()), getData()); 00154 result->setBirthmark(this->getBirthmark()); 00155 result->journey = journey; 00156 return result; 00157 } 00158 00159 #ifndef NDEBUG 00160 size_t 00161 calcObjSize() const 00162 { 00163 size_t sum = sizeof( *this ); 00164 sum += getCommandPool()->calcObjSize(); 00165 if (getUserData() != NULL) 00166 sum += getData()->calcObjSize(); 00167 return sum; 00168 } 00169 #endif 00170 00171 private: 00172 virtual Bit 00173 doGetLengthInBits() const 00174 { 00175 Bit commandPoolSize; 00176 Bit dataSize; 00177 00178 getCommandPool()->calculateSizes(commandPoolSize, dataSize); 00179 00180 return commandPoolSize + dataSize; 00181 } // getLengthInBits 00182 00183 00184 mutable JourneyContainer journey; // JOURNEY 00185 FunctionalUnit* fu; 00186 }; 00187 00188 typedef SmartPtr<Compound> CompoundPtr; 00189 00190 #ifdef WNS_SMARTPTR_DEBUGGING 00191 #define CompoundPtr(...) CompoundPtr(__FILE__, __LINE__, ##__VA_ARGS__) 00192 #endif 00193 00194 }} 00195 00196 00197 #endif // NOT defined WNS_LDK_COMPOUND_HPP 00198 00199 00200
1.5.5