OMKAddInputListenerPrm.cpp

Go to the documentation of this file.
00001 /************************************************************************/
00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */
00003 /* 1993-2002, thereinafter the Software                                 */
00004 /*                                                                      */
00005 /* The Software has been developped within the Siames Project.          */
00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */
00007 /* property rights                                                      */
00008 /*                                                                      */
00009 /* The Software has been registered with the Agence pour la Protection  */
00010 /* des Programmes (APP) under registration number                       */
00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200                             */
00012 /*                                                                      */
00013 /* This file may be distributed under the terms of the Q Public License */
00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in    */
00015 /* the file LICENSE.QPL included in the packaging of this file.         */
00016 /*                                                                      */
00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or   */
00018 /* Universite Rennes 1 for the software may use this file in            */
00019 /* acordance with that specific license                                 */
00020 /************************************************************************/
00021                 
00022 
00023 #include "OMKAddInputListenerPrm.h"
00024 #include "OMKSimulatedObject.h"
00025 #include "OMKParametersAccessor.inl"
00026 #include "OMKMultipleConfigurationParameter.h"
00027 #include <vector>
00028 #include <string>
00029 #include <iostream>
00030 
00031 using namespace OMK ;
00032 using namespace OMK::Inp ;
00033 using namespace OMK::Type ;
00034 //========================================================================
00035 // Default constructor
00036 AddInputListenerPrm::AddInputListenerPrm()
00037 : Base(),
00038   _classId(),
00039   _visBase( "" ),
00040   _configParam( 0 )
00041 {
00042   OMTRACE( ":-) In AddInputListenerPrm::AddInputListenerPrm default constructor" << std::endl ) ;
00043 }
00044 
00045 //========================================================================
00046 // Copy constructor
00047 AddInputListenerPrm::AddInputListenerPrm( const AddInputListenerPrm& ref )
00048 : Base(),
00049 _configParam( 0 )
00050 {
00051   OMTRACE( ":-) In AddInputListenerPrm::AddInputListenerPrm copy constructor" << std::endl ) ;
00052   _copy( ref ) ;
00053 }
00054 
00055 //========================================================================
00056 // Constructor with the parameters
00057 AddInputListenerPrm::AddInputListenerPrm( const std::string& listenerId,
00058                                           const Name& classId,
00059                                           const std::string& visBase,
00060                                           const ConfigurationParameterDescriptor* configParam )
00061 : Base(),
00062   _listenerId( listenerId ) ,
00063   _classId( classId ) ,
00064   _visBase( visBase ) ,
00065   _configParam( configParam ? configParam->clone() : 0 ) 
00066 {
00067   OMTRACE( ":-) In AddInputListenerPrm::AddInputListenerPrm constructor with parameters" << std::endl ) ;
00068 }
00069 
00070 //========================================================================
00071 // Destructor
00072 AddInputListenerPrm::~AddInputListenerPrm()
00073 {
00074   OMTRACE( ":-) In AddInputListenerPrm::~AddInputListenerPrm" << std::endl );
00075   delete _configParam ;
00076   OMTRACE( ">>> Configuration parameters deleted" << std::endl ) ;
00077 }
00078 
00079 //========================================================================
00080 // Default values for parameters
00081 void AddInputListenerPrm::resetDefaultValues()
00082 {
00083   OMTRACE( ":-) In AddInputListenerPrm::resetDefaultValues" << std::endl ) ;
00084   //=== Reset default parameters
00085   _classId = "" ;
00086   _visBase = std::string( "" ) ;
00087   delete _configParam ;
00088   _configParam = 0 ;
00089   OMTRACE( ">>> All parameters reseted"  << std::endl );
00090 }
00091                 
00092 //========================================================================
00093 // Configuration parameters loader
00094 bool AddInputListenerPrm::loadParameters( const ConfigurationParameterDescriptor * node, 
00095                                const std::string& prefix,
00096                                SimulatedObject* p )
00097 {
00098   OMTRACE( ":-) In AddInputListenerPrm::loadParameters" << std::endl ) ;
00099   resetDefaultValues() ;
00100   return innerParametersLoader( node, prefix, p );
00101 }
00102 
00103 //========================================================================
00104 // Configuration parameters loader
00105 bool AddInputListenerPrm::innerParametersLoader( const ConfigurationParameterDescriptor * node, const std::string& prefix, SimulatedObject* p )
00106 {
00107   OMTRACE( ":-) In AddInputListenerPrm::innerParametersLoader" << std::endl ) ;
00108   // Tests the configuration parameter node
00109   if( !node )
00110   { // No valid node => display error message and return false
00111     std::ostringstream txt ;
00112     txt << "Error in AddInputListenerPrm::innerParametersLoader";
00113     if( p ) txt << " for " << OMK::debugMsg( p ) ;
00114     txt << std::endl << ">>> :-( Invalid node" << std::endl ; 
00115     OMERROR( txt.str() ) ;
00116     return false ;
00117   }
00118   // return value
00119   bool ok = true ;
00120 
00121   //=== The optional parameters => no test
00122   // Load the value of VisBase
00123   ParametersAccessor::get( node, prefix + "VisBase", _visBase ) ;
00124   // Load the value of ObjectName
00125   ParametersAccessor::get( node, prefix + "ObjectName", _listenerId ) ;
00126 
00127   //=== The needed parameters => tested
00128   // Load the value of ClassId
00129   ok = ParametersAccessor::get( node, prefix + "ClassId", _classId, p ) && ok ;
00130   // store the value of ConfigParam
00131   _configParam = node->clone() ;
00132 
00133   OMTRACE( ":-) In AddInputListenerPrm::innerParametersLoader" << std::endl << *this << std::endl ) ;
00134 
00135   return ok ;
00136 }
00137                 
00138 
00139 //========================================================================
00140 // != operator
00141 bool AddInputListenerPrm::operator != ( const AddInputListenerPrm& ref ) const
00142 {
00143   return _listenerId != ref.getListenerId()
00144       || _classId != ref.getClassId()
00145       || _visBase != ref.getVisBase()
00146       || _configParam != ref.getConfigParam() ;
00147 }
00148 
00149 //========================================================================
00150 // copy operator
00151 AddInputListenerPrm& AddInputListenerPrm::operator = ( const AddInputListenerPrm& ref )
00152 {
00153   if ( this != &ref ) 
00154   {
00155     _copy( ref ) ;
00156   }
00157   return *this ;
00158 }  
00159 
00160 //========================================================================
00161 // insert in stream
00162 void AddInputListenerPrm::insertInStream( std::ostream& out ) const 
00163 {
00164   out << getListenerId() << " "
00165       << getClassId() << " "
00166       << getVisBase() << " "
00167           << *getConfigParam() << " "
00168       << " " ;
00169 }
00170 
00171 //========================================================================
00172 // extract from a stream
00173 void AddInputListenerPrm::extract( std::istream& in ) 
00174 {
00175   in >> _listenerId
00176      >> _classId
00177      >> _visBase ;
00178   // At this step we must retrieve the configuration parameters
00179   // we assume that is a MultipleConfigurationParameter
00180   MultipleConfigurationParameter* configParamTmp = new MultipleConfigurationParameter ;
00181   in >> ( *configParamTmp ) ;
00182   delete _configParam ;
00183   _configParam = configParamTmp ;
00184 }
00185 
00186 //========================================================================
00187 // pack
00188 void AddInputListenerPrm::pack( OutgoingSynchronisationMessage& out ) const
00189 {
00190   out << getListenerId()
00191       << getClassId()
00192       << getVisBase()
00193           << *getConfigParam() ;
00194 }
00195 
00196 //========================================================================
00197 // unpack
00198 void AddInputListenerPrm::unpack( IncomingSynchronisationMessage& in ) 
00199 {
00200   in >> _listenerId
00201      >> _classId
00202      >> _visBase ;
00203   // At this step we must retrieve the configuration parameters
00204   // we assume that is a MultipleConfigurationParameter
00205   MultipleConfigurationParameter* configParamTmp = new MultipleConfigurationParameter ;
00206   in >> ( *configParamTmp ) ;
00207   delete _configParam ;
00208   _configParam = configParamTmp ;
00209 }
00210 
00211 //========================================================================
00212 // create a default polator
00213 OMK::Type::PolatorNT* AddInputListenerPrm::createPolator() 
00214 {
00215   return new OMK::Type::Polator<AddInputListenerPrm>() ;
00216 }
00217 
00218 //========================================================================
00219 // Protected copy methods
00220 void AddInputListenerPrm::_copy( const AddInputListenerPrm& ref )
00221 {
00222   _listenerId = ref.getListenerId() ; 
00223   _classId = ref.getClassId() ; 
00224   _visBase = ref.getVisBase() ; 
00225   delete _configParam ;
00226   _configParam = ref.getConfigParam() ? ref.getConfigParam()->clone() : 0 ; 
00227 }
00228 
00229 //========================================================================
00230 

logo OpenMask

Documentation generated on Mon Jun 9 11:45:55 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007