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: Object.cc,v 3.24 2008/09/24 12:53:11 erk Exp $ 00023 // ---------------------------------------------------------------------------- 00024 00025 00026 00027 #include "Object.hh" 00028 #include "ObjectAttribute.hh" 00029 #include "RTIRegion.hh" 00030 00031 #include <iostream> 00032 #include <cstring> 00033 #include <algorithm> 00034 #include <functional> 00035 00036 using std::cout ; 00037 using std::endl ; 00038 using std::deque ; 00039 using std::list ; 00040 00041 namespace certi { 00042 00043 // ---------------------------------------------------------------------------- 00045 Object::Object(FederateHandle the_owner, const char *the_name) 00046 : Owner(the_owner), handle(0) 00047 { 00048 setName(the_name); 00049 } 00050 00051 template <class T> 00052 struct delme : public std::unary_function<T, void> { 00053 void operator() (T& x) { 00054 delete x; 00055 } 00056 }; 00057 00058 // ---------------------------------------------------------------------------- 00060 Object::~Object() 00061 { 00062 sf.clear(); 00063 // We should delete the pointee because it belongs to the object. 00064 for (std::deque<ObjectAttribute *>::iterator i = attributeState.begin(); i!=attributeState.end();++i) { 00065 delete (*i); 00066 } 00067 attributeState.clear(); 00068 } 00069 00070 // ---------------------------------------------------------------------------- 00072 void 00073 Object::display() const 00074 { 00075 cout << " Instance: handle =" << handle ; 00076 00077 if (name.length() > 0) 00078 cout << ", name=\"" << name << "\"" << endl ; 00079 else 00080 cout << ", (No name)." << endl ; 00081 } 00082 00083 // ---------------------------------------------------------------------------- 00084 void 00085 Object::addAttribute(ObjectAttribute * new_attribute) 00086 { 00087 attributeState.push_front(new_attribute); 00088 } 00089 00090 // ---------------------------------------------------------------------------- 00092 ObjectAttribute * 00093 Object::getAttribute(AttributeHandle the_attribute) const 00094 throw (AttributeNotDefined) 00095 { 00096 deque<ObjectAttribute *>::const_iterator i ; 00097 for (i = attributeState.begin(); i != attributeState.end(); i++) { 00098 if ((*i)->getHandle() == the_attribute) 00099 return (*i); 00100 } 00101 00102 throw AttributeNotDefined(""); 00103 } 00104 00105 // ---------------------------------------------------------------------------- 00106 ObjectClassHandle 00107 Object::getClass() const 00108 { 00109 return classHandle ; 00110 } 00111 00112 // ---------------------------------------------------------------------------- 00113 void 00114 Object::setClass(ObjectClassHandle h) 00115 { 00116 classHandle = h ; 00117 } 00118 00119 // ---------------------------------------------------------------------------- 00120 FederateHandle 00121 Object::getOwner() const 00122 { 00123 return Owner ; 00124 } 00125 00126 // ---------------------------------------------------------------------------- 00127 void 00128 Object::setOwner(FederateHandle the_federate) 00129 { 00130 Owner = the_federate ; 00131 } 00132 00133 // ---------------------------------------------------------------------------- 00135 bool 00136 Object::isAttributeOwnedByFederate(FederateHandle the_federate, 00137 AttributeHandle the_attribute) const 00138 throw (AttributeNotDefined, RTIinternalError) 00139 { 00140 deque<ObjectAttribute *>::const_iterator i ; 00141 for (i = attributeState.begin(); i != attributeState.end(); i++) { 00142 if ((*i)->getHandle() == the_attribute) { 00143 return (*i)->getOwner() == the_federate ; 00144 } 00145 } 00146 00147 throw AttributeNotDefined("Instance doesn't have this attribute handle"); 00148 } 00149 00150 // ---------------------------------------------------------------------------- 00152 void 00153 Object::unassociate(RTIRegion *region) 00154 { 00155 deque<ObjectAttribute *>::const_iterator i ; 00156 for (i = attributeState.begin(); i != attributeState.end(); i++) { 00157 (*i)->unassociate(region); 00158 } 00159 } 00160 00161 } // namespace certi 00162 00163 // $Id: Object.cc,v 3.24 2008/09/24 12:53:11 erk Exp $