00001 00002 /************************************************************************/ 00003 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */ 00004 /* 1993-2002, thereinafter the Software */ 00005 /* */ 00006 /* The Software has been developped within the Siames Project. */ 00007 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */ 00008 /* property rights */ 00009 /* */ 00010 /* The Software has been registered with the Agence pour la Protection */ 00011 /* des Programmes (APP) under registration number */ 00012 /* IDDN.FR.001.510008.00.S.P.2001.000.41200 */ 00013 /* */ 00014 /* This file may be distributed under the terms of the Q Public License */ 00015 /* version 1.0 as defined by Trolltech AS of Norway and appearing in */ 00016 /* the file LICENSE.QPL included in the packaging of this file. */ 00017 /* */ 00018 /* Licensees holding valid specific licenses issued by INRIA, CNRS or */ 00019 /* Universite Rennes 1 for the software may use this file in */ 00020 /* acordance with that specific license */ 00021 /************************************************************************/ 00022 00023 #if !defined OMK_ATTRIBUTE_INL 00024 #define OMK_ATTRIBUTE_INL 00025 00026 #include "OMKSimpleTypeT.inl" 00027 #include "OMKInput.h" 00028 #include "OMKOutput.h" 00029 #include "OMKParametersAccessor.inl" 00030 #include "OMKValuedEvent.h" 00031 #include "OMKValuedEventListenerCallBack.h" 00032 #include "OMKExtensibleSimulatedObject.h" 00033 00034 00035 //================================================================= 00036 // IAttributeBaseT 00037 //================================================================= 00038 //----------------------------------------------------------------- 00039 template< typename PrmType > 00040 OMK::IAttributeBaseT< PrmType >::IAttributeBaseT( const Name& id ) 00041 : IAttribute( id ) 00042 { 00043 } 00044 //----------------------------------------------------------------- 00045 00046 template< typename PrmType > 00047 OMK::IAttributeBaseT< PrmType >::~IAttributeBaseT() 00048 { 00049 } 00050 //----------------------------------------------------------------- 00051 00052 template< typename PrmType > 00053 bool OMK::IAttributeBaseT< PrmType >::loadParameters( const OMK::ConfigurationParameterDescriptor * node, 00054 const std::string* aliasName ) 00055 { 00056 // Try to retrieve a value, ignores if cannot 00057 if( OMK::ParametersAccessor::get( node, aliasName ? *aliasName : getId().getCString(), *this ) ) 00058 { 00059 std::ostringstream msg ; 00060 msg << "Information for " << OMK::debugMsg( this ) << std::endl 00061 << ">>> :-) Initial value is :" 00062 << std::endl << this->get() ; 00063 OMTRACEID( OMK_DEBUG_OMK_ATTR, msg.str() ) ; 00064 } 00065 00066 return IAttribute::loadParameters( node, aliasName ) ; 00067 } 00068 //----------------------------------------------------------------- 00069 00070 00071 //================================================================= 00072 // IAttributeBaseT 00073 //================================================================= 00074 //----------------------------------------------------------------- 00075 template< typename PrmType, typename ModelType, typename AccessorType > 00076 OMK::IAttributeT< PrmType, ModelType, AccessorType >::IAttributeT( const Name& id, const AccessorType& init ) 00077 : OMK::IAttributeBaseT< PrmType >( id ), 00078 _accessor( init ), 00079 _input( 0 ), 00080 _output( 0 ) 00081 { 00082 } 00083 //----------------------------------------------------------------- 00084 00085 template< typename PrmType, typename ModelType, typename AccessorType > 00086 OMK::IAttributeT< PrmType, ModelType, AccessorType >::~IAttributeT() 00087 { 00088 // disconnect and delete the associated input 00089 if( _input ) 00090 { 00091 _input->disconnect() ; 00092 this->_owner->deleteInput( _input->getName() ) ; 00093 _input = 0 ; 00094 } 00095 // The output cannot be delete it stay alive but is no more updated 00096 } 00097 //----------------------------------------------------------------- 00098 00099 template< typename PrmType, typename ModelType, typename AccessorType > 00100 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::activateSetByEvent() 00101 { 00102 if( !this->_currentValueListener ) 00103 { 00104 this->_currentValueListener = new IdAndValueEventListener 00105 ( * this->_owner, this, 00106 (typename IdAndValueEventListener::CallBackFct)&OMK::IAttributeT< PrmType, ModelType, AccessorType >::processSetValue, 00107 EventId::CURRENT_ATTRIBUTE_VALUE ) ; 00108 OMTRACEID( OMK_DEBUG_OMK_ATTR, 00109 "Information for " << OMK::debugMsg( this ) << std::endl 00110 << ">>> :-) Set by event is activated!" ) ; 00111 } 00112 } 00113 //----------------------------------------------------------------- 00114 00115 template< typename PrmType, typename ModelType, typename AccessorType > 00116 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::activateSetByEventOf() 00117 { 00118 if( !this->_currentValueOfListener ) 00119 { 00120 this->_currentValueOfListener = new ValuedEventListenerCallBack< OMK::IAttributeT< PrmType, ModelType, AccessorType >, ModelType > 00121 ( * this->_owner, this, 00122 ( typename ValuedEventListenerCallBack< OMK::IAttributeT< PrmType, ModelType, AccessorType >, ModelType >::CallBackFct)&OMK::IAttributeT< PrmType, ModelType, AccessorType >::processSetValueOf, 00123 this->_currentValueOfId ) ; 00124 OMTRACEID( OMK_DEBUG_OMK_ATTR, 00125 "Information for " << OMK::debugMsg( this ) << std::endl 00126 << ">>> :-) Set by event \"" << this->_currentValueOfId.getCString() 00127 << "\" is activated!" ) ; 00128 } 00129 } 00130 //----------------------------------------------------------------- 00131 00132 template< typename PrmType, typename ModelType, typename AccessorType > 00133 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::createInput() 00134 { 00135 OMASSERTM( !_input, "There is already an input!" ) ; 00136 00137 _input = &this->_owner->template addInput< ModelType >( getId() ) ; 00138 } 00139 //----------------------------------------------------------------- 00140 00141 template< typename PrmType, typename ModelType, typename AccessorType > 00142 OMK::InputNT* OMK::IAttributeT< PrmType, ModelType, AccessorType >::createInput( const Name& name ) 00143 { 00144 return &this->_owner->template addInput< ModelType >( name ) ; 00145 } 00146 //----------------------------------------------------------------- 00147 00148 template< typename PrmType, typename ModelType, typename AccessorType > 00149 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::createOutput() 00150 { 00151 if( !_output ) 00152 { 00153 _output = &this->_owner->template addOutput< ModelType >( getId() ) ; 00154 } 00155 setValueToOutput() ; 00156 } 00157 //----------------------------------------------------------------- 00158 00159 template< typename PrmType, typename ModelType, typename AccessorType > 00160 OMK::InputNT* OMK::IAttributeT< PrmType, ModelType, AccessorType >::getInput() 00161 { 00162 return _input ; 00163 } 00164 //----------------------------------------------------------------- 00165 00166 template< typename PrmType, typename ModelType, typename AccessorType > 00167 OMK::OutputNT* OMK::IAttributeT< PrmType, ModelType, AccessorType >::getOutput() 00168 { 00169 return _output ; 00170 } 00171 //----------------------------------------------------------------- 00172 00173 template< typename PrmType, typename ModelType, typename AccessorType > 00174 OMK::Input< ModelType >* OMK::IAttributeT< PrmType, ModelType, AccessorType >::getInputT() 00175 { 00176 return _input ; 00177 } 00178 //----------------------------------------------------------------- 00179 00180 template< typename PrmType, typename ModelType, typename AccessorType > 00181 OMK::Output< ModelType >* OMK::IAttributeT< PrmType, ModelType, AccessorType >::getOutputT() 00182 { 00183 return _output ; 00184 } 00185 //----------------------------------------------------------------- 00186 00187 template< typename PrmType, typename ModelType, typename AccessorType > 00188 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::getValueFromInput() 00189 { 00190 if( _input && _input->getConnectedOutput() ) 00191 { 00192 set( static_cast< const PrmType & >( _input->get() ) ) ; 00193 } 00194 } 00195 //----------------------------------------------------------------- 00196 00197 template< typename PrmType, typename ModelType, typename AccessorType > 00198 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::getValueFromInput( OMK::InputNT* input ) 00199 { 00200 Input< ModelType >*typedInput = dynamic_cast< Input< ModelType >* >( input ) ; 00201 if( typedInput && typedInput->getConnectedOutput() ) 00202 { 00203 set( static_cast< const PrmType & >( typedInput->get() ) ) ; 00204 } 00205 } 00206 //----------------------------------------------------------------- 00207 00208 template< typename PrmType, typename ModelType, typename AccessorType > 00209 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::getValueFromInput( PrmType& value, OMK::InputNT* input, int deltaT ) const 00210 { 00211 Input< ModelType >*typedInput = dynamic_cast< Input< ModelType >* >( input ) ; 00212 if( typedInput && typedInput->getConnectedOutput() ) 00213 { 00214 value = static_cast< const PrmType & >( typedInput->get( deltaT ) ) ; 00215 } 00216 } 00217 //----------------------------------------------------------------- 00218 00219 template< typename PrmType, typename ModelType, typename AccessorType > 00220 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::setValueToOutput() 00221 { 00222 if( _output ) 00223 { 00224 _output->set( ModelType( get() ) ) ; 00225 } 00226 } 00227 //----------------------------------------------------------------- 00228 template< typename PrmType, typename ModelType, typename AccessorType > 00229 bool OMK::IAttributeT< PrmType, ModelType, AccessorType >::processSetValueOf( ValuedEvent< ModelType > *e ) 00230 { 00231 set( static_cast< const PrmType & >( e->value ) ) ; 00232 return true ; 00233 } 00234 //----------------------------------------------------------------- 00235 00236 template< typename PrmType, typename ModelType, typename AccessorType > 00237 bool OMK::IAttributeT< PrmType, ModelType, AccessorType >::processSetValue( IdAndValueEvent *e ) 00238 { 00239 bool ok = e && ( getId() == e->value.getValue().first ) ; 00240 if( ok ) 00241 { 00242 set( static_cast< const PrmType & >( e->value.getValue().second ) ) ; 00243 } 00244 return ok ; 00245 } 00246 //----------------------------------------------------------------- 00247 00248 template< typename PrmType, typename ModelType, typename AccessorType > 00249 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::sendIdAndValue( const Name &receiver, const EventIdentifier& eventId, const Name &attributeId ) 00250 { 00251 this->_owner->sendValuedEvent( receiver, eventId, IdAndValueType( IdAndValuePrm( attributeId, ModelType( get() ) ) ) ) ; 00252 } 00253 //----------------------------------------------------------------- 00254 00255 template< typename PrmType, typename ModelType, typename AccessorType > 00256 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::sendValue( const Name &receiver, const EventIdentifier& eventId ) 00257 { 00258 this->_owner->sendValuedEvent( receiver, eventId, ModelType( get() ) ) ; 00259 } 00260 //----------------------------------------------------------------- 00261 00262 template< typename PrmType, typename ModelType, typename AccessorType > 00263 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::fireIdAndValue( const EventIdentifier& eventId, const Name &attributeId ) 00264 { 00265 this->_owner->fireValuedSignal( eventId, IdAndValueType( IdAndValuePrm( getId(), ModelType( get() ) ) ) ) ; 00266 } 00267 //----------------------------------------------------------------- 00268 00269 template< typename PrmType, typename ModelType, typename AccessorType > 00270 void OMK::IAttributeT< PrmType, ModelType, AccessorType >::fireValue( const EventIdentifier& eventId ) 00271 { 00272 this->_owner->fireValuedSignal( eventId, ModelType( get() ) ) ; 00273 } 00274 00275 //----------------------------------------------------------------- 00276 00277 00278 #endif // defined OMK_ATTRIBUTE_INL
Documentation generated on Mon Jun 9 11:45:55 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |