RTItypesImp.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // CERTI - HLA RunTime Infrastructure
00003 // Copyright (C) 2002-2006  ONERA
00004 //
00005 // This program is free software ; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public License
00007 // as published by the Free Software Foundation ; either version 2 of
00008 // the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful, but
00011 // WITHOUT ANY WARRANTY ; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this program ; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018 //
00019 // $Id: RTItypesImp.cc,v 3.3 2009/04/04 13:18:12 gotthardp Exp $
00020 // ----------------------------------------------------------------------------
00021 
00022 #include "certi.hh"
00023 
00024 #include "RTItypesImp.hh"
00025 #include "GAV.hh"
00026 #include "PrettyDebug.hh"
00027 
00028 #include <algorithm>
00029 #include <string.h>
00030 
00031 using namespace certi ;
00032 
00033 static PrettyDebug D("LIBRTI", __FILE__);
00034 static PrettyDebug G("GENDOC",__FILE__);
00035 
00036 
00037 // ----------------------------------------------------------------------------
00038 AttributeHandleValuePairSetImp::AttributeHandleValuePairSetImp(ULong size)
00039 {
00040     _order = RECEIVE;
00041     _transport = RELIABLE;
00042 
00043     _set.reserve(size);
00044 }
00045 
00046 AttributeHandleValuePairSetImp::AttributeHandleValuePairSetImp(const std::vector<AttributeHandleValuePair_t> &val)
00047     : _set(val)
00048 {
00049     _order = RECEIVE;
00050     _transport = RELIABLE;
00051 }
00052 
00053 AttributeHandleValuePairSetImp::~AttributeHandleValuePairSetImp()
00054 {
00055 }
00056 
00057 ULong AttributeHandleValuePairSetImp::size() const
00058 {
00059     return _set.size();
00060 }
00061 
00062 Handle AttributeHandleValuePairSetImp::getHandle(ULong i) const
00063     throw (RTI::ArrayIndexOutOfBounds)
00064 {
00065     if (i < size())
00066         return _set[i].first;
00067     else
00068         throw RTI::ArrayIndexOutOfBounds("");
00069 }
00070 
00071 ULong AttributeHandleValuePairSetImp::getValueLength(ULong i) const
00072     throw (RTI::ArrayIndexOutOfBounds)
00073 {
00074     if (i < size())
00075         return _set[i].second.size();
00076     else
00077         throw RTI::ArrayIndexOutOfBounds("");
00078 }
00079 
00080 void AttributeHandleValuePairSetImp::getValue(ULong i, char *buff, ULong &len) const
00081     throw (RTI::ArrayIndexOutOfBounds)
00082 {
00083     if (i < size()) {
00084         const AttributeHandleValuePair_t& item = _set[i];
00085         len = item.second.size();
00086         memcpy(buff, item.second.data(), len);
00087     }
00088     else
00089         throw RTI::ArrayIndexOutOfBounds("");
00090 }
00091 
00092 char *AttributeHandleValuePairSetImp::getValuePointer(ULong i, ULong &len) const
00093     throw (RTI::ArrayIndexOutOfBounds)
00094 {
00095     if (i < size()) {
00096         const AttributeHandleValuePair_t& item = _set[i];
00097         len = item.second.size();
00098         return (char *)item.second.data();
00099     }
00100     else
00101         throw RTI::ArrayIndexOutOfBounds("");
00102 }
00103 
00104 TransportType AttributeHandleValuePairSetImp::getTransportType(ULong) const
00105     throw (RTI::InvalidHandleValuePairSetContext)
00106 {
00107     return _transport;
00108 }
00109 
00110 OrderType AttributeHandleValuePairSetImp::getOrderType(ULong) const
00111     throw (RTI::ArrayIndexOutOfBounds, RTI::InvalidHandleValuePairSetContext)
00112 {
00113     return _order;
00114 }
00115 
00116 RTI::Region *AttributeHandleValuePairSetImp::getRegion(ULong) const
00117     throw (RTI::ArrayIndexOutOfBounds, RTI::InvalidHandleValuePairSetContext)
00118 {
00119     throw RTI::RTIinternalError("unimplemented function getRegion()");
00120 }
00121 
00122 void AttributeHandleValuePairSetImp::add(Handle h, const char *str, ULong len)
00123     throw (RTI::ValueLengthExceeded, RTI::ValueCountExceeded)
00124 {
00125     _set.push_back(AttributeHandleValuePair_t(h, std::string(str, len)));
00126 }
00127 
00128 void AttributeHandleValuePairSetImp::remove(Handle h)
00129     throw (RTI::ArrayIndexOutOfBounds)
00130 {
00131     for (std::vector<AttributeHandleValuePair_t>::iterator pos = _set.begin();
00132             pos != _set.end(); pos++) {
00133         if (pos->first == h) {
00134             _set.erase(pos);
00135             return;
00136         }
00137     }
00138 
00139     throw RTI::ArrayIndexOutOfBounds("");
00140 }
00141 
00142 void AttributeHandleValuePairSetImp::moveFrom(const AttributeHandleValuePairSet &, ULong &)
00143     throw (RTI::ValueCountExceeded, RTI::ArrayIndexOutOfBounds)
00144 {
00145     throw RTI::RTIinternalError("unimplemented function moveFrom()");
00146 }
00147 
00148 void AttributeHandleValuePairSetImp::empty()
00149 {
00150     _set.clear();
00151 }
00152 
00153 ULong AttributeHandleValuePairSetImp::start() const
00154 {
00155     // not implemented
00156     return 0 ;
00157 }
00158 
00159 ULong AttributeHandleValuePairSetImp::valid(ULong i) const
00160 {
00161     // not implemented
00162     return 0 ;
00163 }
00164 
00165 ULong AttributeHandleValuePairSetImp::next(ULong i) const
00166 {
00167     // not implemented
00168     return 0 ;
00169 }
00170 
00171 const std::vector<AttributeHandleValuePair_t>&
00172 AttributeHandleValuePairSetImp::getAttributeHandleValuePairs() const
00173 {
00174     return _set;
00175 }
00176 
00177 // ----------------------------------------------------------------------------
00178 AttributeHandleSetImp::AttributeHandleSetImp(ULong size)
00179 {
00180     _set.reserve(size);
00181 }
00182 
00183 AttributeHandleSetImp::AttributeHandleSetImp(const std::vector<AttributeHandle> &val)
00184     : _set(val)
00185 {
00186 }
00187 
00188 AttributeHandleSetImp::~AttributeHandleSetImp()
00189 {
00190 }
00191 
00192 ULong AttributeHandleSetImp::size() const
00193 {
00194     return _set.size();
00195 }
00196 
00197 AttributeHandle AttributeHandleSetImp::getHandle(ULong i) const
00198     throw (RTI::ArrayIndexOutOfBounds)
00199 {
00200     if (i < size())
00201         return _set[i];
00202     else
00203         throw RTI::ArrayIndexOutOfBounds("");
00204 }
00205 
00206 void AttributeHandleSetImp::add(AttributeHandle h)
00207     throw (RTI::ArrayIndexOutOfBounds, RTI::AttributeNotDefined)
00208 {
00209     _set.push_back(h);
00210 }
00211 
00212 void AttributeHandleSetImp::remove(AttributeHandle h)
00213     throw (RTI::AttributeNotDefined)
00214 {
00215     std::vector<AttributeHandle>::iterator pos = std::find(_set.begin(), _set.end(), h);
00216     if (pos != _set.end())
00217         _set.erase(pos);
00218     else
00219         throw RTI::ArrayIndexOutOfBounds("");
00220 }
00221 
00222 void AttributeHandleSetImp::empty()
00223 {
00224     _set.clear();
00225 }
00226 
00227 RTI::Boolean AttributeHandleSetImp::isEmpty() const
00228 {
00229     return RTI::Boolean(_set.empty());
00230 }
00231 
00232 RTI::Boolean AttributeHandleSetImp::isMember(AttributeHandle h) const
00233 {
00234     return RTI::Boolean(std::find(_set.begin(), _set.end(), h) != _set.end());
00235 }
00236 
00237 const std::vector<AttributeHandle>&
00238 AttributeHandleSetImp::getAttributeHandles() const
00239 {
00240     return _set;
00241 }
00242 
00243 // ----------------------------------------------------------------------------
00244 FederateHandleSetImp::FederateHandleSetImp(ULong size)
00245 {
00246     _set.reserve(size);
00247 }
00248 
00249 FederateHandleSetImp::~FederateHandleSetImp()
00250 {
00251 }
00252 
00253 ULong FederateHandleSetImp::size() const
00254 {
00255     return _set.size();
00256 }
00257 
00258 FederateHandle FederateHandleSetImp::getHandle(ULong i) const
00259     throw (RTI::ArrayIndexOutOfBounds)
00260 {
00261     if (i < size())
00262         return _set[i];
00263     else
00264         throw RTI::ArrayIndexOutOfBounds("");
00265 }
00266 
00267 void FederateHandleSetImp::add(FederateHandle h)
00268     throw (RTI::ValueCountExceeded)
00269 {
00270     _set.push_back(h);
00271 }
00272 
00273 void FederateHandleSetImp::remove(FederateHandle h)
00274     throw (RTI::ArrayIndexOutOfBounds)
00275 {
00276     std::vector<FederateHandle>::iterator pos = std::find(_set.begin(), _set.end(), h);
00277     if (pos != _set.end())
00278         _set.erase(pos);
00279     else
00280         throw RTI::ArrayIndexOutOfBounds("");
00281 }
00282 
00283 void FederateHandleSetImp::empty()
00284 {
00285     _set.clear();
00286 }
00287 
00288 RTI::Boolean FederateHandleSetImp::isMember(FederateHandle h) const
00289 {
00290     return RTI::Boolean(std::find(_set.begin(), _set.end(), h) != _set.end());
00291 }
00292 
00293 // ----------------------------------------------------------------------------
00294 ParameterHandleValuePairSetImp::ParameterHandleValuePairSetImp(ULong size)
00295 {
00296     _order = RECEIVE;
00297     _transport = RELIABLE;
00298 
00299     _set.reserve(size);
00300 }
00301 
00302 ParameterHandleValuePairSetImp::ParameterHandleValuePairSetImp(const std::vector<ParameterHandleValuePair_t> &val)
00303     : _set(val)
00304 {
00305     _order = RECEIVE;
00306     _transport = RELIABLE;
00307 }
00308 
00309 ParameterHandleValuePairSetImp::~ParameterHandleValuePairSetImp()
00310 {
00311 }
00312 
00313 ULong ParameterHandleValuePairSetImp::size() const
00314 {
00315     return _set.size();
00316 }
00317 
00318 Handle ParameterHandleValuePairSetImp::getHandle(ULong i) const
00319     throw (RTI::ArrayIndexOutOfBounds)
00320 {
00321     if (i < size())
00322         return _set[i].first;
00323     else
00324         throw RTI::ArrayIndexOutOfBounds("");
00325 }
00326 
00327 ULong ParameterHandleValuePairSetImp::getValueLength(ULong i) const
00328     throw (RTI::ArrayIndexOutOfBounds)
00329 {
00330     if (i < size())
00331         return _set[i].second.size();
00332     else
00333         throw RTI::ArrayIndexOutOfBounds("");
00334 }
00335 
00336 void ParameterHandleValuePairSetImp::getValue(ULong i, char *buff, ULong &len) const
00337     throw (RTI::ArrayIndexOutOfBounds)
00338 {
00339     if (i < size()) {
00340         const ParameterHandleValuePair_t& item = _set[i];
00341         len = item.second.size();
00342         memcpy(buff, item.second.data(), len);
00343     }
00344     else
00345         throw RTI::ArrayIndexOutOfBounds("");
00346 }
00347 
00348 char *ParameterHandleValuePairSetImp::getValuePointer(ULong i, ULong &len) const
00349     throw (RTI::ArrayIndexOutOfBounds)
00350 {
00351     if (i < size()) {
00352         const ParameterHandleValuePair_t& item = _set[i];
00353         len = item.second.size();
00354         return (char *)item.second.data();
00355     }
00356     else
00357         throw RTI::ArrayIndexOutOfBounds("");
00358 }
00359 
00360 TransportType ParameterHandleValuePairSetImp::getTransportType() const
00361     throw (RTI::InvalidHandleValuePairSetContext)
00362 {
00363     return _transport;
00364 }
00365 
00366 OrderType ParameterHandleValuePairSetImp::getOrderType() const
00367     throw (RTI::InvalidHandleValuePairSetContext)
00368 {
00369     return _order;
00370 }
00371 
00372 RTI::Region *ParameterHandleValuePairSetImp::getRegion() const
00373     throw (RTI::InvalidHandleValuePairSetContext)
00374 {
00375     throw RTI::RTIinternalError("unimplemented function getRegion()");
00376 }
00377 
00378 void ParameterHandleValuePairSetImp::add(Handle h, const char *str, ULong len)
00379     throw (RTI::ValueLengthExceeded, RTI::ValueCountExceeded)
00380 {
00381     _set.push_back(ParameterHandleValuePair_t(h, std::string(str, len)));
00382 }
00383 
00384 void ParameterHandleValuePairSetImp::remove(Handle h)
00385     throw (RTI::ArrayIndexOutOfBounds)
00386 {
00387     for (std::vector<ParameterHandleValuePair_t>::iterator pos = _set.begin();
00388             pos != _set.end(); pos++) {
00389         if (pos->first == h) {
00390             _set.erase(pos);
00391             return;
00392         }
00393     }
00394 
00395     throw RTI::ArrayIndexOutOfBounds("");
00396 }
00397 
00398 void ParameterHandleValuePairSetImp::moveFrom(const ParameterHandleValuePairSet &, ULong &)
00399     throw (RTI::ValueCountExceeded, RTI::ArrayIndexOutOfBounds)
00400 {
00401     throw RTI::RTIinternalError("unimplemented function moveFrom()");
00402 }
00403 
00404 void ParameterHandleValuePairSetImp::empty()
00405 {
00406     return _set.clear();
00407 }
00408 
00409 ULong ParameterHandleValuePairSetImp::start() const
00410 {
00411     // not implemented
00412     return 0;
00413 }
00414 
00415 ULong ParameterHandleValuePairSetImp::valid(ULong i) const
00416 {
00417     // not implemented
00418     return 0;
00419 }
00420 
00421 ULong ParameterHandleValuePairSetImp::next(ULong i) const
00422 {
00423     // not implemented
00424     return 0;
00425 }
00426 
00427 const std::vector<ParameterHandleValuePair_t> &
00428 ParameterHandleValuePairSetImp::getParameterHandleValuePairs() const
00429 {
00430     return _set;
00431 }
00432 
00433 // ----------------------------------------------------------------------------
00434 RTI::AttributeHandleValuePairSet *
00435 RTI::AttributeSetFactory::create(ULong size)
00436     throw (MemoryExhausted, ValueCountExceeded, HandleValuePairMaximumExceeded)
00437 {
00438     return new AttributeHandleValuePairSetImp(size);
00439 }
00440 
00441 // ----------------------------------------------------------------------------
00442 RTI::AttributeHandleSet *
00443 RTI::AttributeHandleSetFactory::create(ULong size)
00444     throw (MemoryExhausted, ValueCountExceeded)
00445 {
00446     return new AttributeHandleSetImp(size);
00447 }
00448 
00449 // ----------------------------------------------------------------------------
00450 RTI::FederateHandleSet *
00451 RTI::FederateHandleSetFactory::create(ULong size)
00452     throw (MemoryExhausted, ValueCountExceeded)
00453 {
00454     return new FederateHandleSetImp(size);
00455 }
00456 
00457 // ----------------------------------------------------------------------------
00458 RTI::ParameterHandleValuePairSet *
00459 RTI::ParameterSetFactory::create(ULong size)
00460     throw (MemoryExhausted, ValueCountExceeded, HandleValuePairMaximumExceeded)
00461 {
00462     return new ParameterHandleValuePairSetImp(size);
00463 }
00464 
00465 // ----------------------------------------------------------------------------
00466 RegionImp::RegionImp(RegionHandle h, SpaceHandle s, const std::vector<Extent> &ext)
00467     : handle(h), space(s), coExtents(ext)
00468 {
00469 }
00470 
00471 RegionImp::~RegionImp()
00472 {
00473 }
00474 
00475 ULong RegionImp::getRangeLowerBound(ExtentIndex index, DimensionHandle dimension) const
00476     throw (RTI::ArrayIndexOutOfBounds)
00477 {
00478     if (index < extents.size())
00479         return extents[index].getRangeLowerBound(dimension);
00480     else
00481         throw RTI::ArrayIndexOutOfBounds("Extent index above limit");
00482 }
00483 
00484 ULong RegionImp::getRangeUpperBound(ExtentIndex index, DimensionHandle dimension) const
00485     throw (RTI::ArrayIndexOutOfBounds)
00486 {
00487     if (index < extents.size())
00488         return extents[index].getRangeUpperBound(dimension);
00489     else
00490         throw RTI::ArrayIndexOutOfBounds("Extent index above limit");
00491 }
00492 
00493 void RegionImp::setRangeLowerBound(ExtentIndex index, DimensionHandle dimension, ULong val)
00494     throw (RTI::ArrayIndexOutOfBounds)
00495 {
00496     if (index < extents.size())
00497         extents[index].setRangeLowerBound(dimension, val);
00498     else
00499         throw RTI::ArrayIndexOutOfBounds("Extent index above limit");
00500 }
00501 
00502 void RegionImp::setRangeUpperBound(ExtentIndex index, DimensionHandle dimension, ULong val)
00503     throw (RTI::ArrayIndexOutOfBounds)
00504 {
00505     if (index < extents.size())
00506         extents[index].setRangeUpperBound(dimension, val);
00507     else
00508         throw RTI::ArrayIndexOutOfBounds("Extent index above limit");
00509 }
00510 
00511 SpaceHandle RegionImp::getSpaceHandle() const
00512     throw ()
00513 {
00514     return space;
00515 }
00516 
00517 ULong RegionImp::getNumberOfExtents() const
00518     throw ()
00519 {
00520     return coExtents.size();
00521 }
00522 
00523 ULong RegionImp::getRangeLowerBoundNotificationLimit(ExtentIndex index, DimensionHandle dimension) const
00524     throw (RTI::ArrayIndexOutOfBounds)
00525 {
00526     if (index < coExtents.size())
00527         return coExtents[index].getRangeLowerBound(dimension);
00528     else
00529         throw RTI::ArrayIndexOutOfBounds("Extent index above limit");
00530 }
00531 
00532 ULong RegionImp::getRangeUpperBoundNotificationLimit(ExtentIndex index, DimensionHandle dimension) const
00533     throw (RTI::ArrayIndexOutOfBounds)
00534 {
00535     if (index < coExtents.size())
00536         return coExtents[index].getRangeUpperBound(dimension);
00537     else
00538         throw RTI::ArrayIndexOutOfBounds("Extent index above limit");
00539 }
00540 
00541 // $Id: RTItypesImp.cc,v 3.3 2009/04/04 13:18:12 gotthardp Exp $

Generated on Thu Apr 30 15:53:50 2009 for CERTIDeveloperDocumentation by doxygen 1.5.5