OMKAddVisualObjectPrm.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 "OMKAddVisualObjectPrm.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::Type ;
00033 //========================================================================
00034 // Default constructor
00035 AddVisualObjectPrm::AddVisualObjectPrm()
00036 : Base(),
00037   _classId(),
00038   _configParam( 0 )
00039 {
00040 }
00041 
00042 //========================================================================
00043 // Copy constructor
00044 AddVisualObjectPrm::AddVisualObjectPrm( const AddVisualObjectPrm& ref )
00045 : Base(),
00046   _configParam( 0 )
00047 {
00048   _copy( ref ) ;
00049 }
00050 
00051 //========================================================================
00052 // Constructor with the parameters
00053 AddVisualObjectPrm::AddVisualObjectPrm( const Name& objectName,
00054                                         const Name& classId,
00055                                         const Name& VisuName,
00056                                         const ConfigurationParameterDescriptor* configParam )
00057 : Base(),
00058   _objectName( objectName ) ,
00059   _classId( classId ) ,
00060   _visuName( VisuName ) ,
00061   _configParam( configParam ? configParam->clone() : 0 ) 
00062 {
00063 }
00064 
00065 //========================================================================
00066 // Destructor
00067 AddVisualObjectPrm::~AddVisualObjectPrm()
00068 {
00069   delete _configParam ;
00070 }
00071 
00072 //========================================================================
00073 // Default values for parameters
00074 void AddVisualObjectPrm::resetDefaultValues()
00075 {
00076   //=== Reset default parameters
00077   _classId = Name() ;
00078   delete _configParam ;
00079   _configParam = 0 ;
00080 }
00081                 
00082 //========================================================================
00083 // Configuration parameters loader
00084 bool AddVisualObjectPrm::loadParameters( const ConfigurationParameterDescriptor * node, 
00085                                const std::string& prefix,
00086                                SimulatedObject* p )
00087 {
00088   resetDefaultValues() ;
00089   return innerParametersLoader( node, prefix, p );
00090 }
00091 
00092 //========================================================================
00093 // Configuration parameters loader
00094 bool AddVisualObjectPrm::innerParametersLoader( const ConfigurationParameterDescriptor * node, const std::string& prefix, SimulatedObject* p )
00095 {
00096   // Tests the configuration parameter node
00097   if( !node )
00098   { // No valid node => display error message and return false
00099     std::ostringstream txt ;
00100     txt << "Error in AddVisualObjectPrm::innerParametersLoader";
00101     if( p ) txt << " for " << OMK::debugMsg( p ) ;
00102     txt << std::endl << ">>> :-( Invalid node" << std::endl ; 
00103     OMERROR( txt.str() ) ;
00104     return false ;
00105   }
00106   // return value
00107   bool ok = true ;
00108 
00109   //=== The optional parameters => no test
00110   // Load the value of VisuName
00111   ParametersAccessor::get( node, prefix + "VisuName", _visuName ) ;
00112   // Load the value of ObjectName
00113   ParametersAccessor::get( node, prefix + "ObjectName", _objectName ) ;
00114 
00115   //=== The needed parameters => tested
00116   // Load the value of ClassId
00117   ok = ParametersAccessor::get( node, prefix + "Class", _classId, p ) && ok ;
00118   // save the value of ConfigParam
00119   _configParam = node->clone() ;
00120 
00121   return ok ;
00122 }
00123                 
00124 
00125 //========================================================================
00126 // != operator
00127 bool AddVisualObjectPrm::operator != ( const AddVisualObjectPrm& ref ) const
00128 {
00129   return _objectName != ref.getObjectName()
00130       || _classId != ref.getClassId()
00131       || _visuName != ref.getVisuName()
00132       || _configParam != ref.getConfigParam() ;
00133 }
00134 
00135 //========================================================================
00136 // copy operator
00137 AddVisualObjectPrm& AddVisualObjectPrm::operator = ( const AddVisualObjectPrm& ref )
00138 {
00139   if ( this != &ref ) 
00140   {
00141     _copy( ref ) ;
00142   }
00143   return *this ;
00144 }  
00145 
00146 //========================================================================
00147 // insert in stream
00148 void AddVisualObjectPrm::insertInStream( std::ostream& out ) const 
00149 {
00150   out << getObjectName() << " "
00151       << getClassId() << " "
00152       << getVisuName() << " "
00153       << *getConfigParam() << " " 
00154           << " " ;
00155 }
00156 
00157 //========================================================================
00158 // extract from a stream
00159 void AddVisualObjectPrm::extract( std::istream& in ) 
00160 {
00161   in >> _objectName
00162      >> _classId
00163      >> _visuName ;
00164   // At this step we must retrieve the configuration parameters
00165   // we assume that is a MultipleConfigurationParameter
00166   MultipleConfigurationParameter* configParamTmp = new MultipleConfigurationParameter ;
00167   in >> ( *configParamTmp ) ;
00168   delete _configParam ;
00169   _configParam = configParamTmp ;
00170 }
00171 
00172 //========================================================================
00173 // pack
00174 void AddVisualObjectPrm::pack( OutgoingSynchronisationMessage& out ) const
00175 {
00176   out << getObjectName()
00177       << getClassId()
00178       << getVisuName() 
00179           << *getConfigParam() ;
00180 }
00181 
00182 //========================================================================
00183 // unpack
00184 void AddVisualObjectPrm::unpack( IncomingSynchronisationMessage& in ) 
00185 {
00186   in >> _objectName
00187      >> _classId
00188      >> _visuName ;
00189   // At this step we must retrieve the configuration parameters
00190   // we assume that is a MultipleConfigurationParameter
00191   MultipleConfigurationParameter* configParamTmp = new MultipleConfigurationParameter ;
00192   in >> ( *configParamTmp ) ;
00193   delete _configParam ;
00194   _configParam = configParamTmp ;
00195 }
00196 
00197 //========================================================================
00198 // create a default polator
00199 PolatorNT* AddVisualObjectPrm::createPolator() 
00200 {
00201   return new Polator<AddVisualObjectPrm>() ;
00202 }
00203 
00204 //========================================================================
00205 // Protected copy methods
00206 void AddVisualObjectPrm::_copy( const AddVisualObjectPrm& ref )
00207 {
00208   _objectName = ref.getObjectName() ; 
00209   _classId = ref.getClassId() ; 
00210   _visuName = ref.getVisuName() ; 
00211   delete _configParam ;
00212   _configParam = ref.getConfigParam() ? ref.getConfigParam()->clone() : 0 ; 
00213 }
00214 
00215 //========================================================================
00216 

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007