ObjectAttribute.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // CERTI - HLA RunTime Infrastructure
00003 // Copyright (C) 2002-2005  ONERA
00004 //
00005 // This file is part of CERTI-libCERTI
00006 //
00007 // CERTI-libCERTI is free software ; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public License
00009 // as published by the Free Software Foundation ; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // CERTI-libCERTI is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY ; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015 // Lesser General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public
00018 // License along with this program ; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00020 // USA
00021 //
00022 // $Id: ObjectAttribute.cc,v 3.17 2007/07/06 09:25:19 erk Exp $
00023 // ----------------------------------------------------------------------------
00024 
00025 
00026 
00027 #include "ObjectAttribute.hh"
00028 #include "RTIRegion.hh"
00029 #include "PrettyDebug.hh"
00030 
00031 #include <iostream>
00032 
00033 using std::cout ;
00034 using std::endl ;
00035 using std::list ;
00036 
00037 namespace certi {
00038 
00039 static pdCDebug D("OBJECTATTRIBUTE", "(Obj_Attr) - ");
00040 
00041 // ----------------------------------------------------------------------------
00043 ObjectAttribute::ObjectAttribute(AttributeHandle new_handle,
00044                                  FederateHandle new_owner,
00045                                  ObjectClassAttribute *associated_attribute)
00046     : handle(new_handle), owner(new_owner), divesting(false), space(0),
00047       source(associated_attribute), region(0)
00048 {
00049 }
00050 
00051 // ----------------------------------------------------------------------------
00053 ObjectAttribute::~ObjectAttribute()
00054 {
00055 }
00056 
00057 // ----------------------------------------------------------------------------
00059 void
00060 ObjectAttribute::display() const
00061 {
00062     if (handle != 0)
00063         cout << "Attribute " << handle << " ; Owner " << owner << endl ;
00064 }
00065 
00066 // ----------------------------------------------------------------------------
00068 FederateHandle
00069 ObjectAttribute::getOwner() const
00070 {
00071     return owner ;
00072 }
00073 
00074 // ----------------------------------------------------------------------------
00076 void
00077 ObjectAttribute::setOwner(FederateHandle newOwner)
00078 {
00079     owner = newOwner ;
00080 }
00081 
00082 // ----------------------------------------------------------------------------
00084 bool
00085 ObjectAttribute::beingDivested() const
00086 {
00087     return divesting ;
00088 }
00089 
00090 // ----------------------------------------------------------------------------
00092 void
00093 ObjectAttribute::setDivesting(bool divestingState)
00094 {
00095     divesting = divestingState ;
00096 }
00097 
00098 // ----------------------------------------------------------------------------
00100 int
00101 ObjectAttribute::isCandidate(FederateHandle candidate) const
00102 {
00103     list<FederateHandle>::const_iterator i = ownerCandidates.begin();
00104     for (int j = 1 ; i != ownerCandidates.end(); i++, j++) {
00105         if ((*i) == candidate)
00106             return j ;
00107     }
00108 
00109     return 0 ;
00110 }
00111 
00112 // ----------------------------------------------------------------------------
00114 void
00115 ObjectAttribute::addCandidate(FederateHandle candidate)
00116 {
00117     ownerCandidates.push_front(candidate);
00118 }
00119 
00120 // ----------------------------------------------------------------------------
00121 // Removes a candidate from list.
00122 void
00123 ObjectAttribute::removeCandidate(FederateHandle candidate)
00124 {
00125     ownerCandidates.remove(candidate);
00126 }
00127 
00128 // ----------------------------------------------------------------------------
00129 // Returns the federate candidate at position in list.
00130 FederateHandle
00131 ObjectAttribute::getCandidate(unsigned int indice) const
00132     throw (RTIinternalError)
00133 {
00134     if ((indice <= 0) || (indice > ownerCandidates.size()))
00135         throw RTIinternalError("");
00136 
00137     list<FederateHandle>::const_iterator i = ownerCandidates.begin();
00138     for (unsigned int j = 1 ; i != ownerCandidates.end(); i++, j++) {
00139         if (j == indice)
00140             return (*i);
00141     }
00142     throw RTIinternalError("");
00143 }
00144 
00145 // ----------------------------------------------------------------------------
00146 bool
00147 ObjectAttribute::hasCandidates() const
00148 {
00149     return (!ownerCandidates.empty());
00150 }
00151 
00152 // ----------------------------------------------------------------------------
00153 AttributeHandle
00154 ObjectAttribute::getHandle() const
00155 {
00156     return handle ;
00157 }
00158 
00159 // ----------------------------------------------------------------------------
00160 void
00161 ObjectAttribute::setHandle(AttributeHandle h)
00162 {
00163     handle = h ;
00164 }
00165 
00166 // ----------------------------------------------------------------------------
00167 SpaceHandle
00168 ObjectAttribute::getSpace() const
00169 {
00170     return space ;
00171 }
00172 
00173 // ----------------------------------------------------------------------------
00174 void
00175 ObjectAttribute::setSpace(SpaceHandle h)
00176 {
00177     space = h ;
00178 }
00179 
00180 // ----------------------------------------------------------------------------
00181 /* Associate this attribute with a DDM region
00182  */
00183 void
00184 ObjectAttribute::associate(RTIRegion *r)
00185 {
00186     region = r ;
00187 }
00188 
00189 // ----------------------------------------------------------------------------
00190 /* Unassociate attribute from the provided region. If the attribute is
00191    associated with a different region, nothing is changed.
00192  */
00193 void
00194 ObjectAttribute::unassociate(RTIRegion *r)
00195 {
00196     if (region == r)
00197     region = 0 ;
00198 }
00199 
00200 } //namespace certi
00201 
00202 // $Id: ObjectAttribute.cc,v 3.17 2007/07/06 09:25:19 erk Exp $

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