00001 /* 00002 * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #ifndef PsSimulatedObjectHEADER 00019 #define PsSimulatedObjectHEADER 00020 00021 //include ancestor classes 00022 #include "PsFlowable.h" 00023 00024 //include member class 00025 #include "PsNameToPointerMap.h" 00026 00027 //include PsList, cause declaration is guarded by pre-processing directives 00028 #include "PsList.h" 00029 00030 //include definition of PsPolatorNT::defaultPrecisionLevel 00031 #include "PsPolatorNT.h" 00032 00033 00034 #include <iostream> 00035 class PsObjectDescriptor ; 00036 00037 class PsEvent ; 00038 template <typename Type> class PsValuedEvent ; 00039 class PsEventIdentifier ; 00040 class PsEventListener ; 00041 00042 class PsName ; 00043 class PsnObjectHandle ; 00044 class PsController ; 00045 00046 class PsInputNT ; 00047 class PsOutputNT ; 00048 class PsPolatorNT ; 00049 template <typename Type> class PsInput ; 00050 template <typename Type> class PsAbstractInput ; 00051 template <typename Type> class PsSensitiveInput ; 00052 template <typename Type> class PsSensitiveNotifyingInput ; 00053 template <typename Type> class PsOutput ; 00054 template <typename Type> class PsControlParameter ; 00055 template <typename Type> class PsInputAlias ; 00056 template <typename Type> class PsSensitiveInputAlias ; 00057 template <typename Type> class PsSensitiveNotifyingInputAlias ; 00058 template <typename Type> class PsOutputAlias ; 00059 00060 class PsSimulatedObjectCreator ; 00061 class PsConfigurationParameterDescriptor ; 00062 00063 #include "PsSimpleSimulatedObjectCreator.h" 00064 00078 class PsSimulatedObject : public PsFlowable 00079 { 00080 00081 public: 00084 00085 PsSimulatedObject ( PsController & ctrl, const PsObjectDescriptor & objectDescription ); 00086 00088 virtual ~PsSimulatedObject() ; 00090 00094 00100 template <typename Type> list<const PsObjectDescriptor *> * listSonsOfType ( ) ; 00101 00102 00107 template <typename Type> list<const PsObjectDescriptor *> * listBrothersOfType ( ) ; 00108 00109 00114 template <typename Type> list<const PsObjectDescriptor *> * listDescendantsOfType ( ) ; 00115 00116 00121 virtual bool isAncestor ( const PsName & name ); 00122 00126 virtual PsSimulatedObject * getFather () const ; 00127 00130 virtual const PsObjectDescriptor & getFathersDescriptor () const ; 00131 00132 00134 00135 00139 00141 virtual const PsName & getName () const; 00142 00144 virtual PsController & getController () const; 00145 00147 PsnObjectHandle * getObjectHandle () const ; 00148 00150 void setObjectHandle ( PsnObjectHandle * objectHandle) ; 00151 00154 const PsObjectDescriptor & getObjectDescriptor () const ; 00155 00156 00158 virtual const PsNameToPointerMap < PsInputNT > & getInputTable () const ; 00159 00160 00162 virtual const PsNameToPointerMap < PsOutputNT > & getOutputTable () const ; 00163 00164 00166 virtual const PsNameToPointerMap < PsOutputNT > & getControlParameterTable () const ; 00167 00168 00170 virtual const list < PsEventListener * > & getEventListeners () const ; 00171 00172 00177 virtual PsInputNT * getPointerToInputNamed ( const PsName & inputName ) const; 00178 00179 00184 virtual PsOutputNT * getPointerToOutputNamed ( const PsName & outputName) const; 00185 00186 00191 virtual PsOutputNT * getPointerToControlParameterNamed ( const PsName & parameterName ) const ; 00192 00193 00195 virtual const PsConfigurationParameterDescriptor * getConfigurationParameters () const ; 00197 00198 00199 00202 00203 00204 00208 virtual void init() ; 00209 00210 00213 virtual void compute (); 00214 00215 00219 virtual void finish (); 00220 00221 00225 virtual void extract (istream & in = cin) ; 00226 00227 00231 virtual void insertInStream (ostream & out = cout) const; 00232 00233 00235 virtual void unpack (PsIncomingSynchronisationMessage &) ; 00236 00238 virtual void unpackAllValues (PsIncomingSynchronisationMessage &) ; 00239 00241 virtual void pack (PsOutgoingSynchronisationMessage &) const ; 00242 00244 virtual void packAllValues (PsOutgoingSynchronisationMessage &) const ; 00245 00246 00247 00251 virtual void prepareEventProcessing ( list <PsEvent *> & ) ; 00252 00253 00257 virtual bool processEvent (PsEvent *) ; 00258 00259 00262 virtual void eventsProcessed ( list <PsEvent *> & ) ; 00263 00264 00270 virtual bool processEventsASAP () const ; 00271 00272 00277 virtual void addEventListener ( PsEventListener & ) ; 00278 00279 00283 void registerEventListenerForEvent ( PsEventListener & eventListener, 00284 const PsEventIdentifier & eventId ) ; 00285 00286 00288 00289 00290 00297 void fireSignal(const PsEventIdentifier & sig); 00298 00299 00304 template <typename UserType> 00305 void fireValuedSignal( const PsEventIdentifier & sig, const UserType & value ); 00306 00307 00313 virtual bool registerForSignalBy ( const PsEventIdentifier & sig , 00314 const PsName & producer ); 00315 00316 00323 virtual bool registerForSignalBy ( const PsEventIdentifier & sig , 00324 const PsName & producer, 00325 const PsEventIdentifier & eventId ); 00326 00327 00333 virtual bool registerForSignalBy ( const PsEventIdentifier & sig , 00334 PsSimulatedObject * producer ); 00335 00336 00342 virtual bool registerForSignalBy ( const PsEventIdentifier & sig , 00343 PsSimulatedObject & producer ); 00344 00345 00352 virtual bool registerForSignalBy ( const PsEventIdentifier & sig , 00353 PsSimulatedObject * producer, 00354 const PsEventIdentifier & eventId ); 00355 00356 00357 00364 virtual bool registerForSignalBy ( const PsEventIdentifier & sig , 00365 PsSimulatedObject & producer, 00366 const PsEventIdentifier & eventId ); 00367 00368 00369 00374 virtual bool registerForSignal ( const PsEventIdentifier & sig ); 00375 00381 virtual bool registerForSignal ( const PsEventIdentifier & sig , 00382 const PsEventIdentifier & eventId ); 00383 00389 virtual bool cancelRegistrationForSignalBy ( const PsEventIdentifier & sig , const PsName & producer ); 00390 00391 00397 virtual bool cancelRegistrationForSignalBy ( const PsEventIdentifier & sig , PsSimulatedObject * producer ); 00398 00399 00400 00406 virtual bool cancelRegistrationForSignalBy ( const PsEventIdentifier & sig , PsSimulatedObject & producer ); 00407 00408 00409 00414 virtual bool cancelRegistrationForSignal ( const PsEventIdentifier & sig ); 00416 00427 template <typename Type> PsInput<Type> & addInput( const PsName & inputName, 00428 bool makeConnectable = false, 00429 int precisionLevel = PsPolatorNT::defaultPrecisionLevel ) ; 00430 00431 00439 template <typename Type> PsSensitiveInput<Type> & addSensitiveInput (const PsName & inputName, 00440 bool makeConnectable = false, 00441 int precisionLevel = PsPolatorNT::defaultPrecisionLevel ) ; 00442 00443 00451 template <typename Type> PsSensitiveNotifyingInput<Type> & addSensitiveNotifyingInput( const PsName & inputName, 00452 bool makeConnectable = false, 00453 int precisionLevel = PsPolatorNT::defaultPrecisionLevel ) ; 00454 00455 00460 void deleteInput( const PsName & inputName) ; 00461 00462 00468 template <typename Type> PsOutput<Type> & addOutput( const PsName & outputName, 00469 PsPolatorNT * polator = 0 ) ; 00470 00471 00477 template <typename Type> PsControlParameter<Type> & addControlParameter( const PsName & controlParameterName, 00478 PsPolatorNT * polator = 0 ) ; 00479 00480 00490 template <typename Type> 00491 PsInputAlias<Type> & addInputAlias (const PsName & aliasName, 00492 const PsName & aliasedObjectName, 00493 const PsName & aliasedInputName, 00494 int precisionLevel = PsPolatorNT::defaultPrecisionLevel ) ; 00495 00496 00506 template <typename Type> 00507 PsSensitiveInputAlias<Type> & addSensitiveInputAlias( const PsName & aliasName, 00508 const PsName & aliasedObjectName, 00509 const PsName & aliasedInputName, 00510 int precisionLevel = PsPolatorNT::defaultPrecisionLevel ) ; 00511 00512 00522 template <typename Type> PsSensitiveNotifyingInputAlias<Type> & 00523 addSensitiveNotifyingInputAlias( const PsName & aliasName, 00524 const PsName & aliasedObjectName, 00525 const PsName & aliasedInputName, 00526 int precisionLevel = PsPolatorNT::defaultPrecisionLevel ) ; 00527 00528 00536 template <typename Type> PsOutputAlias<Type> & addOutputAlias( const PsName & aliasName, 00537 const PsName & aliasedObjectName, 00538 const PsName & aliasedOutputName, 00539 PsPolatorNT * interp = 0 ) ; 00540 00542 00543 00547 00551 virtual const PsDate & getSimulatedDate () const ; 00552 00557 float getPeriod( ) const ; 00558 00560 00564 00569 void sendEvent (const PsName & receiver , const PsEventIdentifier & eventId) ; 00570 00571 00576 void sendEvent ( PsSimulatedObject * receiver , const PsEventIdentifier & eventId) ; 00577 00578 00583 void sendEvent ( PsSimulatedObject & receiver , const PsEventIdentifier & eventId) ; 00584 00585 00591 template <typename UserType> 00592 void sendValuedEvent (const PsName & receiver , const PsEventIdentifier & eventId, const UserType & userInfo) ; 00593 00594 00600 template <typename UserType> 00601 void sendValuedEvent ( PsSimulatedObject * receiver , const PsEventIdentifier & eventId , const UserType & userInfo) ; 00602 00603 00609 template <typename UserType> 00610 void sendValuedEvent ( PsSimulatedObject & receiver , const PsEventIdentifier & eventId , const UserType & userInfo) ; 00611 00612 00617 void sendEvent ( const PsEvent & event ) ; 00618 00619 00624 void sendEvent ( PsEvent * event ) ; 00625 00627 00631 00636 virtual void addInstanceCreator(const PsName & className, PsSimulatedObjectCreator * instanceCreator ); 00637 00642 template <typename SimulatedObject> 00643 void generateAndAddInstanceCreatorFor( const PsName & className); 00644 00645 00648 virtual const PsNameToPointerMap < PsSimulatedObjectCreator > & getEncapsulatedClassesTable () const ; 00649 00654 virtual PsSimulatedObject * createInstanceOfEncapsulatedClass( const PsObjectDescriptor & objectDescriptor ) const ; 00656 00657 00658 protected: 00659 00661 PsController & _controller; 00662 00664 const PsObjectDescriptor & _objectDescriptor ; 00665 00666 friend class PsInputNT ; 00668 PsNameToPointerMap<PsInputNT> _inputTable ; 00669 00671 PsNameToPointerMap<PsOutputNT> _outputTable ; 00672 00674 PsNameToPointerMap<PsOutputNT> _controlParameterTable ; 00675 00677 list <PsEventListener *> _listOfEventListeners ; 00678 00680 PsnObjectHandle * _objectHandle ; 00681 00683 PsNameToPointerMap < PsSimulatedObjectCreator > _encapsulatedClassesTable ; 00684 00685 }; // PsSimulatedObject 00686 00687 00688 00689 //----------------------------------- IMPLEMENTATION OF TEMPLATE MEMBER FUNCTIONS --------------------- 00690 00691 #include "PsController.h" 00692 #include "PsValuedEvent.h" 00693 #include "PsObjectDescriptor.h" 00694 #include "PsUnallowedOverloadingException.h" 00695 00696 template <typename Type> 00697 list<const PsObjectDescriptor *> * PsSimulatedObject::listSonsOfType ( ) 00698 { 00699 return getObjectDescriptor().template listSonsOfType<Type>( ); 00700 } 00701 00702 00703 00704 template <typename Type> 00705 list<const PsObjectDescriptor *> * PsSimulatedObject::listBrothersOfType ( ) 00706 { 00707 assert ( getObjectDescriptor().getFathersObjectDescriptor() != NULL ) ; 00708 return getObjectDescriptor().getFathersObjectDescriptor()->template listSonsOfType<Type> ( ); 00709 } 00710 00711 00712 00713 template <typename Type> 00714 list<const PsObjectDescriptor *> * PsSimulatedObject::listDescendantsOfType ( ) 00715 { 00716 return getObjectDescriptor().template listDescendantsOfType<Type>( ); 00717 } 00718 00719 00720 template <typename UserType> 00721 void PsSimulatedObject::fireValuedSignal( const PsEventIdentifier & sig, const UserType & value ) 00722 { 00723 PsValuedEvent<UserType> event ( sig, getSimulatedDate(), getName(), getName(), value) ; 00724 if ( getObjectHandle() != NULL ) 00725 { 00726 getObjectHandle()->sendEventsForSignal( event , sig ) ; 00727 } 00728 else 00729 { 00730 getController().broadcastEventsForSignal ( event, sig ) ; 00731 } 00732 } 00733 00734 template <typename Type> 00735 PsInput<Type> & PsSimulatedObject::addInput( const PsName & inputName, 00736 bool makeConnectable, 00737 int precisionLevel ) 00738 { 00739 PsInputNT * redefinedInput = _inputTable.getObjectOfIndex ( inputName ); 00740 PsInput<Type> * input ; 00741 if ( redefinedInput == NULL ) 00742 { 00743 input = _controller.template createInput<Type> ( inputName, *this, makeConnectable, precisionLevel ) ; 00744 } 00745 else 00746 { 00747 input = dynamic_cast<PsInput<Type> *> ( redefinedInput ) ; 00748 if ( input == NULL ) 00749 { 00750 throw PsUnallowedOverloadingException(inputName, getName() ) ; 00751 } 00752 else 00753 { 00754 cerr<<"Warning : input "<<inputName<<" of object "<<getName() 00755 <<" already defined. No new input created : reference to old one used"<<endl; 00756 } 00757 } 00758 return *input ; 00759 } 00760 00761 00762 00763 template <typename Type> 00764 PsSensitiveInput<Type> & PsSimulatedObject::addSensitiveInput (const PsName & inputName, 00765 bool makeConnectable, 00766 int precisionLevel ) 00767 { 00768 PsInputNT * redefinedInput = _inputTable.getObjectOfIndex ( inputName ); 00769 PsSensitiveInput<Type> * input ; 00770 if ( redefinedInput == NULL ) 00771 { 00772 input = _controller.template createSensitiveInput<Type>( inputName, *this, makeConnectable, precisionLevel ); 00773 } 00774 else 00775 { 00776 input = dynamic_cast <PsSensitiveInput<Type> *> ( redefinedInput ) ; 00777 if ( input == NULL ) 00778 { 00779 throw PsUnallowedOverloadingException( inputName, getName() ) ; 00780 } 00781 else 00782 { 00783 cerr<<"Warning : sensitiveInput "<<inputName<<" of object "<<getName() 00784 <<" already defined. No new sensitiveInput created : reference to old one used"<<endl; 00785 } 00786 } 00787 return *input ; 00788 } 00789 00790 00791 00792 template <typename Type> 00793 PsSensitiveNotifyingInput<Type> & PsSimulatedObject::addSensitiveNotifyingInput( const PsName & inputName, 00794 bool makeConnectable, 00795 int precisionLevel ) 00796 { 00797 PsInputNT * redefinedInput = _inputTable.getObjectOfIndex ( inputName ); 00798 PsSensitiveNotifyingInput<Type> * input ; 00799 if ( redefinedInput == NULL ) 00800 { 00801 input = _controller.template createSensitiveNotifyingInput<Type>(inputName, *this, makeConnectable, precisionLevel) ; 00802 } 00803 else 00804 { 00805 input = dynamic_cast <PsSensitiveNotifyingInput<Type> * > ( redefinedInput ) ; 00806 if ( input == NULL ) 00807 { 00808 throw PsUnallowedOverloadingException ( inputName, getName() ) ; 00809 } 00810 else 00811 { 00812 cerr<<"Warning : sensitiveNotifyingInput "<<inputName<<" of object "<<getName() 00813 <<" already defined. No new sensitiveNotifyingInput created : reference to old one used"<<endl; 00814 } 00815 } 00816 return *input ; 00817 } 00818 00819 00820 00821 template <typename Type> 00822 PsOutput<Type> & PsSimulatedObject::addOutput( const PsName & outputName, 00823 PsPolatorNT * polator ) 00824 { 00825 PsOutputNT * redefinedOutput = _outputTable.getObjectOfIndex ( outputName ) ; 00826 PsOutput<Type> * output ; 00827 if ( redefinedOutput == NULL ) 00828 { 00829 output = _controller.template createOutput<Type>(outputName, *this, polator ) ; 00830 } 00831 else 00832 { 00833 output = dynamic_cast <PsOutput<Type> *> ( redefinedOutput ) ; 00834 if ( output == NULL ) 00835 { 00836 throw PsUnallowedOverloadingException ( outputName, getName() ) ; 00837 } 00838 else 00839 { 00840 cerr<<"Warning : output "<<outputName<<" of object "<<getName() 00841 <<" already defined. No new output created : reference to old one used"<<endl; 00842 } 00843 } 00844 00845 _outputTable.addObjectWithIndex (outputName, output) ; 00846 return *output ; 00847 } 00848 00849 00850 00851 template <typename Type> 00852 PsControlParameter<Type> & PsSimulatedObject::addControlParameter( const PsName & controlParameterName, 00853 PsPolatorNT * polator ) 00854 { 00855 PsOutputNT * redefinedControlParameter = _controlParameterTable.getObjectOfIndex ( controlParameterName ) ; 00856 PsControlParameter<Type> * controlParameter ; 00857 if ( redefinedControlParameter == NULL ) 00858 { 00859 controlParameter = _controller.template createControlParameter<Type>( controlParameterName, *this, polator); 00860 } 00861 else 00862 { 00863 controlParameter = dynamic_cast < PsControlParameter<Type> * > ( redefinedControlParameter ) ; 00864 if ( controlParameter == NULL ) 00865 { 00866 throw PsUnallowedOverloadingException ( controlParameterName, getName() ) ; 00867 } 00868 else 00869 { 00870 cerr<<"Warning : controlParameter "<<controlParameterName<<" of "<<getName() 00871 <<" already defined. No new controlParameter created : reference to old one used"<<endl; 00872 } 00873 } 00874 PsOutputNT * realControlParameter = dynamic_cast<PsOutputNT *>(controlParameter) ; 00875 assert ( realControlParameter != NULL ) ; 00876 _controlParameterTable.addObjectWithIndex (controlParameterName, realControlParameter) ; 00877 return *controlParameter ; 00878 } 00879 00880 00881 00882 template <typename Type> 00883 PsInputAlias<Type> & PsSimulatedObject::addInputAlias (const PsName & aliasName, 00884 const PsName & aliasedObjectName, 00885 const PsName & aliasedInputName, 00886 int precisionLevel ) 00887 { 00888 PsInputNT * redefinedInput = _inputTable.getObjectOfIndex ( aliasName ) ; 00889 PsInputAlias<Type> * alias = NULL ; 00890 00891 if ( redefinedInput == NULL ) 00892 { 00893 // make sure aliasedObjectName is an ancestor of object 00894 if ( isAncestor( aliasedObjectName ) ) 00895 { 00896 PsSimulatedObject * obj = _controller.getPointerToSimulatedObjectNamed (aliasedObjectName) ; 00897 PsInputNT * input = obj->_inputTable.getObjectOfIndex( aliasedInputName ); 00898 PsAbstractInput<Type> * realInput = dynamic_cast <PsAbstractInput<Type> *> (input) ; 00899 00900 if (realInput != NULL) 00901 { 00902 if (obj != NULL) 00903 { 00904 alias = _controller.template createInputAlias<Type>( aliasName, *this, realInput, precisionLevel ); 00905 } 00906 else 00907 { 00908 PsController::error("imposible aliasing ") ; 00909 } 00910 } 00911 else 00912 { 00913 PsController::error("impossible aliasing, probably because of type mismatch") ; 00914 } 00915 } 00916 else 00917 { 00918 cerr << "PsSimulatedObject::createInputAlias " << aliasedObjectName << " isn't the father of " 00919 << getName() << " : aliasing is therefore impossible for alias named " << aliasedInputName << endl ; 00920 PsController::error(""); 00921 } 00922 } 00923 else 00924 { 00925 alias = dynamic_cast <PsInputAlias<Type> * > ( redefinedInput ); 00926 if ( alias == NULL ) 00927 { 00928 throw PsUnallowedOverloadingException ( aliasName, getName() ) ; 00929 } 00930 else 00931 { 00932 cerr<<"Warning : inputAlias "<<aliasName<<" of object "<<getName() 00933 <<" already defined. No new inputAlias created : reference to old one used"<<endl; 00934 } 00935 } 00936 return *alias ; 00937 } 00938 00939 00940 00941 template <typename Type> 00942 PsSensitiveInputAlias<Type> & PsSimulatedObject::addSensitiveInputAlias( const PsName & aliasName, 00943 const PsName & aliasedObjectName, 00944 const PsName & aliasedInputName, 00945 int precisionLevel ) 00946 { 00947 PsInputNT * redefinedInput = _inputTable.getObjectOfIndex ( aliasName ) ; 00948 PsSensitiveInputAlias<Type> * alias = NULL ; 00949 00950 if ( redefinedInput == NULL ) 00951 { 00952 // make sure aliasedObjectName is an ancestor of object 00953 if (isAncestor(aliasedObjectName)) 00954 { 00955 PsSimulatedObject * obj = _controller.getPointerToSimulatedObjectNamed (aliasedObjectName) ; 00956 PsInputNT * input = obj->_inputTable.getObjectOfIndex( aliasedInputName ); 00957 PsAbstractInput<Type> * realInput = dynamic_cast <PsAbstractInput<Type> *> (input) ; 00958 if (realInput != NULL) 00959 { 00960 if (obj != NULL) 00961 { 00962 alias = _controller.template createSensitiveInputAlias<Type>(aliasName,*this,realInput,precisionLevel); 00963 } 00964 else 00965 { 00966 PsController::error("Impossible aliasing ") ; 00967 } 00968 } 00969 else 00970 { 00971 PsController::error("impossible aliasing, probably because of type mismatch") ; 00972 } 00973 } 00974 else 00975 { 00976 cerr << "PsSimulatedObject::addSensitiveInputAlias " << aliasedObjectName << " isn't the father of " 00977 << getName() << " : cannot create an alias of " << aliasedInputName << endl ; 00978 throw PsUserException("") ; 00979 } 00980 } 00981 else 00982 { 00983 alias = dynamic_cast <PsSensitiveInputAlias<Type> * > ( redefinedInput ); 00984 if ( alias == NULL ) 00985 { 00986 throw PsUnallowedOverloadingException ( aliasName, getName() ) ; 00987 } 00988 else 00989 { 00990 cerr<<"Warning : sensitiveInputAlias "<<aliasName<<" of object "<<getName() 00991 <<" already defined. No new sensitiveInputAlias created : reference to old one used"<<endl; 00992 } 00993 } 00994 return *alias ; 00995 } 00996 00997 00998 template <typename Type> 00999 PsSensitiveNotifyingInputAlias<Type> & 01000 PsSimulatedObject::addSensitiveNotifyingInputAlias( const PsName & aliasName, 01001 const PsName & aliasedObjectName, 01002 const PsName & aliasedInputName, 01003 int precisionLevel 01004 ) 01005 { 01006 PsInputNT * redefinedInput = _inputTable.getObjectOfIndex ( aliasName ) ; 01007 PsSensitiveNotifyingInputAlias<Type> * alias = NULL ; 01008 01009 if ( redefinedInput == NULL ) 01010 { 01011 // make sure aliasedObjectName is an ancestor of object 01012 if( isAncestor( aliasedObjectName ) ) 01013 { 01014 PsSimulatedObject * obj = _controller.getPointerToSimulatedObjectNamed (aliasedObjectName) ; 01015 PsInputNT * input = obj->_inputTable.getObjectOfIndex ( aliasedInputName); 01016 PsAbstractInput<Type> * realInput; 01017 realInput = dynamic_cast <PsAbstractInput<Type> *> (input) ; 01018 if (realInput != NULL) 01019 { 01020 if (obj != NULL) 01021 { 01022 alias = _controller.template createSensitiveNotifyingInputAlias<Type>( aliasName, *this, realInput, precisionLevel); 01023 } 01024 else 01025 { 01026 throw PsUserException("Impossible aliasing ") ; 01027 } 01028 } 01029 else 01030 { 01031 PsController::error("alias type mismatch"); 01032 } 01033 } 01034 else 01035 { 01036 cerr << "PsSimulatedObject::addSensitiveSeignalingInputAlias " << aliasedObjectName 01037 << " isn' the father of " 01038 << getName() << " : creation of alias named " << aliasedInputName << " impossible" << endl ; 01039 throw PsUserException(""); 01040 } 01041 } 01042 else 01043 { 01044 alias = dynamic_cast <PsSensitiveNotifyingInputAlias<Type> * > ( redefinedInput ); 01045 if ( alias == NULL ) 01046 { 01047 throw PsUnallowedOverloadingException ( aliasName, getName() ) ; 01048 } 01049 else 01050 { 01051 cerr<<"Warning : sensitiveNotifyingInputAlias "<<aliasName<<" of object "<<getName() 01052 <<" already defined. No new sensitiveNotifyingInputAlias : reference to old one used"<<endl; 01053 } 01054 } 01055 return *alias ; 01056 } 01057 01058 template <typename Type> 01059 PsOutputAlias<Type> & PsSimulatedObject::addOutputAlias( const PsName & aliasName, 01060 const PsName & aliasedObjectName, 01061 const PsName & aliasedOutputName, 01062 PsPolatorNT * interp ) 01063 { 01064 PsOutputNT * redefinedOutput = _outputTable.getObjectOfIndex ( aliasName ) ; 01065 01066 PsOutputAlias<Type> * alias = NULL ; 01067 list<const PsObjectDescriptor *> * listeFils = getController().template listDescendantsOfType<PsSimulatedObject>(aliasedObjectName); 01068 int aliasedObjectPresent = false ; 01069 01070 if ( redefinedOutput == NULL ) 01071 { 01072 // make sure aliasedObjectName is an ancestor of object 01073 if (listeFils!=NULL) 01074 { 01075 list<const PsObjectDescriptor *>::const_iterator listeFilsIterator = listeFils->begin() ; 01076 while((listeFilsIterator != listeFils->end() ) && 01077 (!aliasedObjectPresent) ) 01078 { 01079 aliasedObjectPresent = ( (*listeFilsIterator)->getName() == getName() ) ; 01080 ++ listeFilsIterator ; 01081 } 01082 01083 delete listeFils; 01084 } 01085 if( aliasedObjectPresent ) 01086 { 01087 01088 PsSimulatedObject * obj = _controller.getPointerToSimulatedObjectNamed (aliasedObjectName) ; 01089 01090 PsOutputNT * Outputnt = obj->getPointerToOutputNamed(aliasedOutputName); 01091 PsOutput<Type> * refOutput = dynamic_cast <PsOutput<Type> *> (Outputnt) ; 01092 if (refOutput != NULL) 01093 { 01094 if (obj != NULL) 01095 { 01096 alias = _controller.template createOutputAlias<Type>(aliasName,*this,refOutput,interp); 01097 } 01098 else 01099 { 01100 cerr << "PsSimulatedObject::addOutputAlias " << endl ; 01101 cerr << "alias " << aliasName << " cannot be made on inexistant " << aliasedOutputName << endl ; 01102 throw PsUserException(""); 01103 } 01104 } 01105 else 01106 { 01107 throw PsUserException("Impossible output aliasing : type mismatch"); 01108 } 01109 } 01110 else 01111 { 01112 cout << "PsSimulatedObject::addOutputAlias " << aliasedObjectName << " isn't the father of " 01113 << getName() << " : not possible to alias " << aliasedOutputName << endl ; 01114 PsController::error(""); 01115 } 01116 } 01117 else 01118 { 01119 alias = dynamic_cast <PsOutputAlias<Type> * > ( redefinedOutput ); 01120 if ( alias == NULL ) 01121 { 01122 throw PsUnallowedOverloadingException ( aliasName, getName() ) ; 01123 } 01124 else 01125 { 01126 cerr<<"Warning : outputAlias already defined. No new outputAlias created : reference to old one used"<<endl; 01127 } 01128 } 01129 _outputTable.addObjectWithIndex (aliasName, alias) ; 01130 return *alias ; 01131 } 01132 01133 01134 01135 template <typename UserType> 01136 void PsSimulatedObject::sendValuedEvent (const PsName & receiver , const PsEventIdentifier & eventId, const UserType & userInfo) { 01137 PsSimulatedObject * receiverObject = _controller.getPointerToSimulatedObjectNamed( receiver ) ; 01138 if ( receiverObject == NULL ) 01139 { 01140 getController().addToPendingEvents (new PsValuedEvent<UserType> (eventId, 01141 _controller.getSimulatedDate (), 01142 getName (), 01143 receiver , 01144 userInfo) ) ; 01145 } 01146 else 01147 { 01148 if ( receiverObject->getObjectHandle() != NULL ) 01149 { 01150 receiverObject->getObjectHandle()->receiveEvent (new PsValuedEvent<UserType> (eventId, 01151 _controller.getSimulatedDate (), 01152 getName (), 01153 receiver , 01154 userInfo) ) ; 01155 } 01156 else 01157 { 01158 getController().addToPendingEvents(new PsValuedEvent<UserType> (eventId, 01159 _controller.getSimulatedDate (), 01160 getName (), 01161 receiver , 01162 userInfo) ) ; 01163 } 01164 } 01165 } 01166 01167 01168 template <typename UserType> 01169 void PsSimulatedObject::sendValuedEvent ( PsSimulatedObject * receiver , const PsEventIdentifier & eventId , const UserType & userInfo) 01170 { 01171 if ( receiver->getObjectHandle() != NULL ) 01172 { 01173 receiver->getObjectHandle()->receiveEvent (new PsValuedEvent<UserType> (eventId, 01174 _controller.getSimulatedDate (), 01175 getName (), 01176 receiver->getName (), 01177 userInfo) ) ; 01178 } 01179 else 01180 { 01181 getController().addToPendingEvents(new PsValuedEvent<UserType> (eventId, 01182 _controller.getSimulatedDate (), 01183 getName (), 01184 receiver->getName (), 01185 userInfo) ) ; 01186 } 01187 } 01188 01189 template <typename UserType> 01190 void PsSimulatedObject::sendValuedEvent ( PsSimulatedObject & receiver , const PsEventIdentifier & eventId , const UserType & userInfo) 01191 { 01192 if ( receiver.getObjectHandle() != NULL ) 01193 { 01194 receiver.getObjectHandle()->receiveEvent (new PsValuedEvent<UserType> (eventId, 01195 _controller.getSimulatedDate (), 01196 getName (), 01197 receiver.getName (), 01198 userInfo) ) ; 01199 } 01200 else 01201 { 01202 getController().addToPendingEvents (new PsValuedEvent<UserType> (eventId, 01203 _controller.getSimulatedDate (), 01204 getName (), 01205 receiver.getName (), 01206 userInfo) ) ; 01207 } 01208 } 01209 01210 01211 template <typename SimulatedObject> 01212 void PsSimulatedObject::generateAndAddInstanceCreatorFor (const PsName & className) 01213 { 01214 addInstanceCreator ( className , new PsSimpleSimulatedObjectCreator< SimulatedObject > () ) ; 01215 } 01216 01217 #endif
| Documentation generated on Mon Nov 25 15:25:02 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |