GAV.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // CERTI - HLA RunTime Infrastructure
00003 // Copyright (C) 2002-2005  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: GAV.cc,v 3.20 2009/04/04 13:53:25 gotthardp Exp $
00020 // ----------------------------------------------------------------------------
00021 
00022 #include "GAV.hh"
00023 #include "PrettyDebug.hh"
00024 #include <string.h>
00025 
00026 #include <algorithm>
00027 #include <assert.h>
00028 
00029 using std::list ;
00030 
00031 using namespace certi ;
00032 
00033 // ----------------------------------------------------------------------------
00034 // AttributeHandleValuePair
00035 // ----------------------------------------------------------------------------
00036 
00037 namespace certi {
00038 
00039 static pdCDebug D("GAV", "(gav) - ");
00040 
00041 // ----------------------------------------------------------------------------
00042 AttributeHandleValuePair::AttributeHandleValuePair(Handle handle,
00043                                                    const char *value,
00044                                                    ULong value_length)
00045 {
00046     _handle = handle ;
00047     _valueLength = value_length ;
00048 
00049     _value = new char[value_length];
00050     memcpy(_value, value, value_length);
00051 }
00052 
00053 // ----------------------------------------------------------------------------
00054 AttributeHandleValuePair::~AttributeHandleValuePair()
00055 {
00056     delete[] _value ;
00057 }
00058 
00059 // ----------------------------------------------------------------------------
00060 // AttributeHandleValuePairSet
00061 // ----------------------------------------------------------------------------
00062 AttributeHandleValuePairSet::AttributeHandleValuePairSet(ULong)
00063 {
00064     _order = RECEIVE ;
00065     _transport = RELIABLE ;
00066 }
00067 
00068 // ----------------------------------------------------------------------------
00069 AttributeHandleValuePairSet::~AttributeHandleValuePairSet()
00070 {
00071     empty();
00072 }
00073 
00074 // ----------------------------------------------------------------------------
00075 ULong
00076 AttributeHandleValuePairSet::size() const
00077 {
00078     return _set.size();
00079 }
00080 
00081 // ----------------------------------------------------------------------------
00082 Handle
00083 AttributeHandleValuePairSet::getHandle(ULong i) const
00084     throw (ArrayIndexOutOfBounds)
00085 {
00086     list<AttributeHandleValuePair *>::const_iterator j = _set.begin();
00087     for (ULong k = 0 ; j != _set.end(); j++, k++) {
00088         if (i == k)
00089             return (*j)->_handle ;
00090     }
00091 
00092     throw ArrayIndexOutOfBounds("");
00093 }
00094 
00095 // ----------------------------------------------------------------------------
00096 ULong
00097 AttributeHandleValuePairSet::getValueLength(ULong i) const
00098     throw (ArrayIndexOutOfBounds)
00099 {
00100     list<AttributeHandleValuePair *>::const_iterator j = _set.begin();
00101     for (ULong k = 0 ; j != _set.end(); j++, k++) {
00102         if (i == k)
00103             return (*j)->_valueLength ;
00104     }
00105 
00106     throw ArrayIndexOutOfBounds("");
00107 }
00108 
00109 // ----------------------------------------------------------------------------
00110 void
00111 AttributeHandleValuePairSet::getValue(ULong i,
00112                                          char *buff,
00113                                          ULong& value_length) const
00114     throw (ArrayIndexOutOfBounds)
00115 {
00116     list<AttributeHandleValuePair *>::const_iterator j = _set.begin();
00117     for (ULong k = 0 ; j != _set.end(); j++, k++) {
00118         if (i == k) {
00119             value_length = (*j)->_valueLength ;
00120             memcpy(buff, (*j)->_value, (*j)->_valueLength);
00121             return ;
00122         }
00123     }
00124 
00125     throw ArrayIndexOutOfBounds("");
00126 }
00127 
00128 // ----------------------------------------------------------------------------
00129 char *
00130 AttributeHandleValuePairSet::getValuePointer(ULong i,
00131                                                 ULong& value_length) const
00132     throw (ArrayIndexOutOfBounds)
00133 {
00134     list<AttributeHandleValuePair *>::const_iterator j = _set.begin();
00135     for (ULong k = 0 ; j != _set.end(); j++, k++) {
00136         if (i == k) {
00137             value_length = (*j)->_valueLength ;
00138             return (*j)->_value ;
00139         }
00140     }
00141 
00142     throw ArrayIndexOutOfBounds("");
00143 }
00144 
00145 // ----------------------------------------------------------------------------
00146 TransportType
00147 AttributeHandleValuePairSet::getTransportType(ULong) const
00148     throw (InvalidHandleValuePairSetContext)
00149 {
00150     return _transport ;
00151 }
00152 
00153 // ----------------------------------------------------------------------------
00154 OrderType
00155 AttributeHandleValuePairSet::getOrderType(ULong) const
00156     throw (ArrayIndexOutOfBounds, InvalidHandleValuePairSetContext)
00157 {
00158     return _order ;
00159 }
00160 
00161 // ----------------------------------------------------------------------------
00162 void
00163 AttributeHandleValuePairSet::add(Handle h,
00164                                     const char *buff,
00165                                     ULong value_length)
00166     throw (ValueLengthExceeded, ValueCountExceeded)
00167 {
00168     AttributeHandleValuePair *ahvp ;
00169     ahvp = new AttributeHandleValuePair(h, buff, value_length);
00170 
00171     _set.push_front(ahvp);
00172 }
00173 
00174 // ----------------------------------------------------------------------------
00175 void
00176 AttributeHandleValuePairSet::remove(Handle h)
00177     throw (ArrayIndexOutOfBounds)
00178 {
00179     list<AttributeHandleValuePair *>::iterator j ;
00180     for (j = _set.begin(); j != _set.end(); j++) {
00181         if ((*j)->_handle == h) {
00182             delete (*j);
00183             _set.erase(j);
00184             return ;
00185         }
00186     }
00187 
00188     throw ArrayIndexOutOfBounds("");
00189 }
00190 
00191 // ----------------------------------------------------------------------------
00192 void
00193 AttributeHandleValuePairSet::moveFrom(const AttributeHandleValuePairSet&,
00194                                          ULong&)
00195     throw (ValueCountExceeded, ArrayIndexOutOfBounds)
00196 {
00197     throw RTIinternalError("Unimplemented service");
00198 }
00199 
00200 // ----------------------------------------------------------------------------
00201 void
00202 AttributeHandleValuePairSet::empty()
00203 {
00204     while (!_set.empty()) {
00205         delete _set.front();
00206         _set.pop_front();
00207     }
00208 }
00209 
00210 // ----------------------------------------------------------------------------
00211 ULong
00212 AttributeHandleValuePairSet::start() const
00213 {
00214     //not implemented
00215     return 0 ;
00216 }
00217 
00218 // ----------------------------------------------------------------------------
00219 ULong
00220 AttributeHandleValuePairSet::valid(ULong) const
00221 {
00222     //not implemented
00223     return 0 ;
00224 }
00225 
00226 // ----------------------------------------------------------------------------
00227 ULong
00228 AttributeHandleValuePairSet::next(ULong) const
00229 {
00230     //not implemented
00231     return 0 ;
00232 }
00233 
00234 // ----------------------------------------------------------------------------
00235 // AttributeHandleSet
00236 // ----------------------------------------------------------------------------
00237 AttributeHandleSet::AttributeHandleSet(ULong size)
00238 {
00239 }
00240 
00241 AttributeHandleSet::~AttributeHandleSet()
00242 {
00243     empty();
00244 }
00245 
00246 // ----------------------------------------------------------------------------
00247 inline ULong
00248 AttributeHandleSet::size() const
00249 {
00250     return _set.size();
00251 }
00252 
00253 // ----------------------------------------------------------------------------
00254 AttributeHandle
00255 AttributeHandleSet::getHandle(ULong i) const
00256     throw (ArrayIndexOutOfBounds)
00257 {
00258     list<AttributeHandle>::const_iterator h ;
00259     ULong j ;
00260     for (j = 0, h = _set.begin(); h != _set.end(); h++, j++) {
00261         if (i == j)
00262             return (*h);
00263     }
00264 
00265     throw ArrayIndexOutOfBounds("");
00266 }
00267 
00268 // ----------------------------------------------------------------------------
00269 void
00270 AttributeHandleSet::add(AttributeHandle h)
00271     throw (ArrayIndexOutOfBounds, AttributeNotDefined)
00272 {
00273     _set.push_front(h);
00274 }
00275 
00276 // ----------------------------------------------------------------------------
00277 void
00278 AttributeHandleSet::remove(AttributeHandle h)
00279     throw (AttributeNotDefined)// not guaranteed safe while iterating
00280 {
00281     if (isMember(h) == true)
00282         _set.remove(h);
00283     else
00284         throw AttributeNotDefined("");
00285 }
00286 
00287 // ----------------------------------------------------------------------------
00288 void
00289 AttributeHandleSet::empty()
00290 {
00291     _set.clear();
00292 }
00293 
00294 // ----------------------------------------------------------------------------
00295 bool
00296 AttributeHandleSet::isEmpty() const
00297 {
00298     return _set.empty();
00299 }
00300 
00301 // ----------------------------------------------------------------------------
00302 bool
00303 AttributeHandleSet::isMember(AttributeHandle h) const
00304 {
00305     return find(_set.begin(), _set.end(), h) != _set.end();
00306 }
00307 
00308 // ----------------------------------------------------------------------------
00309 // FederateHandleSet
00310 // ----------------------------------------------------------------------------
00311 FederateHandleSet::~FederateHandleSet()
00312 {
00313     empty();
00314 }
00315 
00316 // ----------------------------------------------------------------------------
00317 inline ULong
00318 FederateHandleSet::size() const
00319 {
00320     return _set.size();
00321 }
00322 
00323 // ----------------------------------------------------------------------------
00324 FederateHandle
00325 FederateHandleSet::getHandle(ULong i) const
00326     throw (ArrayIndexOutOfBounds)
00327 {
00328     list<FederateHandle>::const_iterator h ;
00329     ULong j ;
00330     for (j = 0, h = _set.begin(); h != _set.end(); h++, j++) {
00331         if (i == j)
00332             return (*h);
00333     }
00334 
00335     throw ArrayIndexOutOfBounds("");
00336 }
00337 
00338 // ----------------------------------------------------------------------------
00339 void
00340 FederateHandleSet::add(FederateHandle h)
00341     throw (ValueCountExceeded)
00342 {
00343     _set.push_front(h);
00344 }
00345 
00346 // ----------------------------------------------------------------------------
00347 void
00348 FederateHandleSet::remove(FederateHandle h)
00349     throw (ArrayIndexOutOfBounds)
00350 {
00351     if (isMember(h) == true)
00352         _set.remove(h);
00353     else
00354         throw AttributeNotDefined("");
00355 }
00356 
00357 // ----------------------------------------------------------------------------
00358 void
00359 FederateHandleSet::empty()
00360 {
00361     _set.clear();
00362 }
00363 
00364 // ----------------------------------------------------------------------------
00365 bool
00366 FederateHandleSet::isMember(FederateHandle h) const
00367 {
00368     return find(_set.begin(), _set.end(), h) != _set.end();
00369 }
00370 
00371 // ----------------------------------------------------------------------------
00372 // ParameterHandleValuePair
00373 // ----------------------------------------------------------------------------
00374 
00375 ParameterHandleValuePair::ParameterHandleValuePair(Handle handle,
00376                                                    const char *value,
00377                                                    ULong value_length)
00378 {
00379     _handle = handle ;
00380     _valueLength = value_length ;
00381 
00382     _value = (char *) malloc(value_length);
00383     memcpy(_value, value, value_length);
00384 }
00385 
00386 // ----------------------------------------------------------------------------
00387 ParameterHandleValuePair::~ParameterHandleValuePair()
00388 {
00389     free(_value);
00390 }
00391 
00392 // ----------------------------------------------------------------------------
00393 // ParameterHandleValuePairSet
00394 // ----------------------------------------------------------------------------
00395 ParameterHandleValuePairSet::ParameterHandleValuePairSet(ULong)
00396 {
00397     _order = RECEIVE ;
00398     _transport = RELIABLE ;
00399 }
00400 
00401 ParameterHandleValuePairSet::~ParameterHandleValuePairSet()
00402 {
00403     empty();
00404 }
00405 
00406 // ----------------------------------------------------------------------------
00407 ULong
00408 ParameterHandleValuePairSet::size() const
00409 {
00410     return _set.size();
00411 }
00412 
00413 // ----------------------------------------------------------------------------
00414 Handle
00415 ParameterHandleValuePairSet::getHandle(ULong i) const
00416     throw (ArrayIndexOutOfBounds)
00417 {
00418     list<ParameterHandleValuePair *>::const_iterator j = _set.begin();
00419     for (ULong k = 0 ; j != _set.end(); j++, k++) {
00420         if (i == k)
00421             return (*j)->_handle ;
00422     }
00423 
00424     throw ArrayIndexOutOfBounds("");
00425 }
00426 
00427 // ----------------------------------------------------------------------------
00428 ULong
00429 ParameterHandleValuePairSet::getValueLength(ULong i) const
00430     throw (ArrayIndexOutOfBounds)
00431 {
00432     list<ParameterHandleValuePair *>::const_iterator j = _set.begin();
00433     for (ULong k = 0 ; j != _set.end(); j++, k++) {
00434         if (i == k)
00435             return (*j)->_valueLength ;
00436     }
00437 
00438     throw ArrayIndexOutOfBounds("");
00439 }
00440 
00441 // ----------------------------------------------------------------------------
00442 void
00443 ParameterHandleValuePairSet::getValue(ULong i,
00444                                          char *buff,
00445                                          ULong& value_length) const
00446     throw (ArrayIndexOutOfBounds)
00447 {
00448     list<ParameterHandleValuePair *>::const_iterator j = _set.begin();
00449     for (ULong k = 0 ; j != _set.end(); j++, k++) {
00450         if (i == k) {
00451             value_length = (*j)->_valueLength ;
00452             memcpy(buff, (*j)->_value, (*j)->_valueLength);
00453             return ;
00454         }
00455     }
00456 
00457     throw ArrayIndexOutOfBounds("");
00458 }
00459 
00460 // ----------------------------------------------------------------------------
00461 char *
00462 ParameterHandleValuePairSet::getValuePointer(ULong i,
00463                                                 ULong& value_length) const
00464     throw (ArrayIndexOutOfBounds)
00465 {
00466     list<ParameterHandleValuePair *>::const_iterator j = _set.begin();
00467     for (ULong k = 0 ; j != _set.end(); j++, k++) {
00468         if (i == k) {
00469             value_length = (*j)->_valueLength ;
00470             return (*j)->_value ;
00471         }
00472     }
00473 
00474     throw ArrayIndexOutOfBounds("");
00475 }
00476 
00477 // ----------------------------------------------------------------------------
00478 inline TransportType
00479 ParameterHandleValuePairSet::getTransportType() const
00480     throw (InvalidHandleValuePairSetContext)
00481 {
00482     return _transport ;
00483 }
00484 
00485 // ----------------------------------------------------------------------------
00486 inline OrderType
00487 ParameterHandleValuePairSet::getOrderType() const
00488     throw (InvalidHandleValuePairSetContext)
00489 {
00490     return _order ;
00491 }
00492 
00493 // ----------------------------------------------------------------------------
00494 void
00495 ParameterHandleValuePairSet::add(Handle h,
00496                                     const char *buff,
00497                                     ULong value_length)
00498     throw (ValueLengthExceeded, ValueCountExceeded)
00499 {
00500     ParameterHandleValuePair *phvp ;
00501     phvp = new ParameterHandleValuePair(h, buff, value_length);
00502 
00503     _set.push_front(phvp);
00504 }
00505 
00506 // ----------------------------------------------------------------------------
00507 void
00508 ParameterHandleValuePairSet::remove(Handle h)
00509     throw (ArrayIndexOutOfBounds)
00510 {
00511     list<ParameterHandleValuePair *>::iterator j ;
00512     for (j = _set.begin(); j != _set.end(); j++) {
00513         if ((*j)->_handle == h) {
00514             delete (*j);
00515             _set.erase(j);
00516             return ;
00517         }
00518     }
00519 
00520     throw ArrayIndexOutOfBounds("");
00521 }
00522 
00523 // ----------------------------------------------------------------------------
00524 void
00525 ParameterHandleValuePairSet::moveFrom(const ParameterHandleValuePairSet&,
00526                                          ULong&)
00527     throw (ValueCountExceeded, ArrayIndexOutOfBounds)
00528 {
00529     throw RTIinternalError("Unimplemented service");
00530 }
00531 
00532 // ----------------------------------------------------------------------------
00533 void
00534 ParameterHandleValuePairSet::empty()
00535 {
00536     while (!_set.empty()) {
00537         delete _set.front();
00538         _set.pop_front();
00539     }
00540 }
00541 
00542 // ----------------------------------------------------------------------------
00543 ULong
00544 ParameterHandleValuePairSet::start() const
00545 {
00546     //not implemented
00547     return 0 ;
00548 }
00549 
00550 // ----------------------------------------------------------------------------
00551 ULong
00552 ParameterHandleValuePairSet::valid(ULong) const
00553 {
00554     //not implemented
00555     return 0 ;
00556 }
00557 
00558 // ----------------------------------------------------------------------------
00559 ULong
00560 ParameterHandleValuePairSet::next(ULong) const
00561 {
00562     //not implemented
00563     return 0 ;
00564 }
00565 
00566 } // namespace certi
00567 
00568 // $Id: GAV.cc,v 3.20 2009/04/04 13:53:25 gotthardp Exp $
00569 

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