00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <iostream>
00026 #include <map>
00027 #include <string>
00028 #include <vector>
00029 #include <algorithm>
00030
00031 #include <boost/lexical_cast.hpp>
00032 #include <boost/tokenizer.hpp>
00033
00034 #include "WLogger.h"
00035 #include "exceptions/WPropertyUnknown.h"
00036
00037 #include "WPropertyHelper.h"
00038
00039 #include "WProperties.h"
00040
00041 WProperties::WProperties( std::string name, std::string description ):
00042 WPropertyBase( name, description ),
00043 m_properties(),
00044 m_childUpdateCondition( new WConditionSet() )
00045 {
00046 m_updateCondition->add( m_properties.getChangeCondition() );
00047 }
00048
00049 WProperties::~WProperties()
00050 {
00051 }
00052
00053 WProperties::WProperties( const WProperties& from ):
00054 WPropertyBase( from ),
00055 m_properties(),
00056 m_childUpdateCondition( new WConditionSet() )
00057 {
00058
00059
00060
00061 PropertySharedContainerType::ReadTicket l = from.m_properties.getReadTicket();
00062
00063
00064 for( PropertyConstIterator iter = l->get().begin(); iter != l->get().end(); ++iter )
00065 {
00066
00067 addProperty( ( *iter )->clone() );
00068 }
00069
00070
00071 l.reset();
00072
00073
00074 m_updateCondition->add( m_properties.getChangeCondition() );
00075 }
00076
00077 boost::shared_ptr< WPropertyBase > WProperties::clone()
00078 {
00079
00080 return boost::shared_ptr< WProperties >( new WProperties( *this ) );
00081 }
00082
00083 PROPERTY_TYPE WProperties::getType() const
00084 {
00085 return PV_GROUP;
00086 }
00087
00088 bool WProperties::setAsString( std::string )
00089 {
00090
00091 return true;
00092 }
00093
00094 std::string WProperties::getAsString()
00095 {
00096
00097 return "";
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 template< typename T >
00110 T _addDefaultConstraints( T prop )
00111 {
00112 return prop;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 WPropInt _addDefaultConstraints( WPropInt prop )
00125 {
00126 prop->setMin( 0 );
00127 prop->setMax( 100 );
00128 return prop;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 WPropDouble _addDefaultConstraints( WPropDouble prop )
00141 {
00142 prop->setMin( 0.0 );
00143 prop->setMax( 100.0 );
00144 return prop;
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 WPropSelection _addDefaultConstraints( WPropSelection prop )
00157 {
00158 WPropertyHelper::PC_ISVALID::addTo( prop );
00159 return prop;
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 WPropFilename _addDefaultConstraints( WPropFilename prop )
00172 {
00173 WPropertyHelper::PC_NOTEMPTY::addTo( prop );
00174 return prop;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 template< typename T >
00187 T addDefaultConstraints( T prop )
00188 {
00189 if( prop->getPurpose() == PV_PURPOSE_INFORMATION )
00190 {
00191 return prop;
00192 }
00193
00194 return _addDefaultConstraints( prop );
00195 }
00196
00197 bool WProperties::set( boost::shared_ptr< WPropertyBase > )
00198 {
00199 return true;
00200 }
00201
00202 bool WProperties::propNamePredicate( boost::shared_ptr< WPropertyBase > prop1, boost::shared_ptr< WPropertyBase > prop2 ) const
00203 {
00204 return ( prop1->getName() == prop2->getName() );
00205 }
00206 void WProperties::removeProperty( boost::shared_ptr< WPropertyBase > prop )
00207 {
00208 if( !prop )
00209 {
00210 return;
00211 }
00212
00213
00214 PropertySharedContainerType::WriteTicket l = m_properties.getWriteTicket();
00215 l->get().erase( std::remove( l->get().begin(), l->get().end(), prop ), l->get().end() );
00216 m_childUpdateCondition->remove( prop->getUpdateCondition() );
00217 }
00218
00219 boost::shared_ptr< WPropertyBase > WProperties::findProperty( const WProperties* const props, std::string name ) const
00220 {
00221 boost::shared_ptr< WPropertyBase > result = boost::shared_ptr< WPropertyBase >();
00222
00223
00224 PropertySharedContainerType::ReadTicket l = props->m_properties.getReadTicket();
00225
00226
00227 for( PropertyContainerType::const_iterator it = l->get().begin(); it != l->get().end(); ++it )
00228 {
00229 if( ( *it )->getName() == name )
00230 {
00231 result = ( *it );
00232 break;
00233 }
00234 }
00235
00236
00237 return result;
00238 }
00239
00240 boost::shared_ptr< WPropertyBase > WProperties::findProperty( std::string name ) const
00241 {
00242 boost::shared_ptr< WPropertyBase > result = boost::shared_ptr< WPropertyBase >();
00243
00244
00245 typedef boost::tokenizer<boost::char_separator< char > > tokenizer;
00246 boost::char_separator< char > sep( "/" );
00247 tokenizer tok( name, sep );
00248
00249
00250 const WProperties* curProps = this;
00251 for( tokenizer::iterator it = tok.begin(); it != tok.end(); ++it )
00252 {
00253
00254 if( result && ( result->getType() != PV_GROUP ) )
00255 {
00256
00257 return boost::shared_ptr< WPropertyBase >();
00258 }
00259
00260
00261 result = findProperty( curProps, boost::lexical_cast< std::string >( *it ) );
00262 if( !result )
00263 {
00264
00265 return boost::shared_ptr< WPropertyBase >();
00266 }
00267 else if( result && ( result->getType() == PV_GROUP ) )
00268 {
00269
00270 curProps = result->toPropGroup().get();
00271 }
00272 }
00273
00274 return result;
00275 }
00276
00277 bool WProperties::existsProperty( std::string name )
00278 {
00279 return ( findProperty( name ) != boost::shared_ptr< WPropertyBase >() );
00280 }
00281
00282 boost::shared_ptr< WPropertyBase > WProperties::getProperty( std::string name )
00283 {
00284 boost::shared_ptr< WPropertyBase > p = findProperty( name );
00285 if( p == boost::shared_ptr< WPropertyBase >() )
00286 {
00287 throw WPropertyUnknown( std::string( "Property \"" + name + "\" can't be found." ) );
00288 }
00289
00290 return p;
00291 }
00292
00293 WProperties::PropertySharedContainerType::ReadTicket WProperties::getProperties() const
00294 {
00295 return m_properties.getReadTicket();
00296 }
00297
00298 WProperties::PropertySharedContainerType::ReadTicket WProperties::getReadTicket() const
00299 {
00300 return m_properties.getReadTicket();
00301 }
00302
00303 WPropGroup WProperties::addPropertyGroup( std::string name, std::string description, bool hide )
00304 {
00305 WPropGroup p = WPropGroup( new WProperties( name, description ) );
00306 p->setHidden( hide );
00307 addProperty( p );
00308 return p;
00309 }
00310
00311 void WProperties::clear()
00312 {
00313
00314 PropertySharedContainerType::WriteTicket l = m_properties.getWriteTicket();
00315 l->get().clear();
00316 }
00317
00318 boost::shared_ptr< WCondition > WProperties::getChildUpdateCondition() const
00319 {
00320 return m_childUpdateCondition;
00321 }
00322
00323
00324
00325
00326
00327
00328
00329 WPropBool WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL& initial, bool hide )
00330 {
00331 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_BOOL >( name, description, initial, hide ) );
00332 }
00333
00334 WPropInt WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT& initial, bool hide )
00335 {
00336 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_INT >( name, description, initial, hide ) );
00337 }
00338
00339 WPropDouble WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial, bool hide )
00340 {
00341 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_DOUBLE >( name, description, initial, hide ) );
00342 }
00343
00344 WPropString WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial, bool hide )
00345 {
00346 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_STRING >( name, description, initial, hide ) );
00347 }
00348
00349 WPropFilename WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial, bool hide )
00350 {
00351 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, hide ) );
00352 }
00353
00354 WPropSelection WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION& initial, bool hide )
00355 {
00356 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_SELECTION >( name, description, initial, hide ) );
00357 }
00358
00359 WPropPosition WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION& initial, bool hide )
00360 {
00361 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_POSITION >( name, description, initial, hide ) );
00362 }
00363
00364 WPropColor WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial, bool hide )
00365 {
00366 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_COLOR >( name, description, initial, hide ) );
00367 }
00368
00369 WPropTrigger WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial, bool hide )
00370 {
00371 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_TRIGGER >( name, description, initial, hide ) );
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381 WPropBool WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL& initial,
00382 boost::shared_ptr< WCondition > condition, bool hide )
00383 {
00384 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_BOOL >( name, description, initial, condition, hide ) );
00385 }
00386
00387 WPropInt WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT& initial,
00388 boost::shared_ptr< WCondition > condition, bool hide )
00389 {
00390 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_INT >( name, description, initial, condition, hide ) );
00391 }
00392
00393 WPropDouble WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial,
00394 boost::shared_ptr< WCondition > condition, bool hide )
00395 {
00396 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_DOUBLE >( name, description, initial, condition, hide ) );
00397 }
00398
00399 WPropString WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial,
00400 boost::shared_ptr< WCondition > condition, bool hide )
00401 {
00402 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_STRING >( name, description, initial, condition, hide ) );
00403 }
00404
00405 WPropFilename WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial,
00406 boost::shared_ptr< WCondition > condition, bool hide )
00407 {
00408 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, condition, hide ) );
00409 }
00410
00411 WPropSelection WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION& initial,
00412 boost::shared_ptr< WCondition > condition, bool hide )
00413 {
00414 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_SELECTION >( name, description, initial, condition, hide ) );
00415 }
00416
00417 WPropPosition WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION& initial,
00418 boost::shared_ptr< WCondition > condition, bool hide )
00419 {
00420 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_POSITION >( name, description, initial, condition, hide ) );
00421 }
00422
00423 WPropColor WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial,
00424 boost::shared_ptr< WCondition > condition, bool hide )
00425 {
00426 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_COLOR >( name, description, initial, condition, hide ) );
00427 }
00428
00429 WPropTrigger WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
00430 boost::shared_ptr< WCondition > condition, bool hide )
00431 {
00432 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_TRIGGER >( name, description, initial, condition, hide ) );
00433 }
00434
00435
00436
00437
00438
00439
00440
00441
00442 WPropBool WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL& initial,
00443 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00444 {
00445 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_BOOL >( name, description, initial, notifier, hide ) );
00446 }
00447
00448 WPropInt WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT& initial,
00449 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00450 {
00451 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_INT >( name, description, initial, notifier, hide ) );
00452 }
00453
00454 WPropDouble WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial,
00455 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00456 {
00457 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_DOUBLE >( name, description, initial, notifier, hide ) );
00458 }
00459
00460 WPropString WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial,
00461 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00462 {
00463 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_STRING >( name, description, initial, notifier, hide ) );
00464 }
00465
00466 WPropFilename WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial,
00467 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00468 {
00469 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, notifier, hide ) );
00470 }
00471
00472 WPropSelection WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION& initial,
00473 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00474 {
00475 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_SELECTION >( name, description, initial, notifier, hide ) );
00476 }
00477
00478 WPropPosition WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION& initial,
00479 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00480 {
00481 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_POSITION >( name, description, initial, notifier, hide ) );
00482 }
00483
00484 WPropColor WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial,
00485 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00486 {
00487 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_COLOR >( name, description, initial, notifier, hide ) );
00488 }
00489
00490 WPropTrigger WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
00491 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00492 {
00493 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_TRIGGER >( name, description, initial, notifier, hide ) );
00494 }
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 WPropBool WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL& initial,
00505 boost::shared_ptr< WCondition > condition,
00506 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00507 {
00508 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_BOOL >( name, description, initial, condition, notifier, hide ) );
00509 }
00510
00511 WPropInt WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT& initial,
00512 boost::shared_ptr< WCondition > condition,
00513 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00514 {
00515 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_INT >( name, description, initial, condition, notifier, hide ) );
00516 }
00517
00518 WPropDouble WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial,
00519 boost::shared_ptr< WCondition > condition,
00520 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00521 {
00522 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_DOUBLE >( name, description, initial, condition, notifier, hide ) );
00523 }
00524
00525 WPropString WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial,
00526 boost::shared_ptr< WCondition > condition,
00527 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00528 {
00529 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_STRING >( name, description, initial, condition, notifier, hide ) );
00530 }
00531
00532 WPropFilename WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial,
00533 boost::shared_ptr< WCondition > condition,
00534 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00535 {
00536 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, condition, notifier, hide ) );
00537 }
00538
00539 WPropSelection WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION& initial,
00540 boost::shared_ptr< WCondition > condition,
00541 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00542 {
00543 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_SELECTION >( name, description, initial, condition, notifier, hide ) );
00544 }
00545
00546 WPropPosition WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION& initial,
00547 boost::shared_ptr< WCondition > condition,
00548 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00549 {
00550 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_POSITION >( name, description, initial, condition, notifier, hide ) );
00551 }
00552
00553 WPropColor WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial,
00554 boost::shared_ptr< WCondition > condition,
00555 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00556 {
00557 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_COLOR >( name, description, initial, condition, notifier, hide ) );
00558 }
00559
00560 WPropTrigger WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
00561 boost::shared_ptr< WCondition > condition,
00562 WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
00563 {
00564 return addDefaultConstraints( addProperty< WPVBaseTypes::PV_TRIGGER >( name, description, initial, condition, notifier, hide ) );
00565 }
00566