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 #ifndef WPROPERTYTYPES_H
00026 #define WPROPERTYTYPES_H
00027
00028 #include <stdint.h>
00029
00030 #include <list>
00031 #include <string>
00032 #include <vector>
00033 #include <utility>
00034
00035
00036 #ifndef BOOST_FILESYSTEM_VERSION
00037 #define BOOST_FILESYSTEM_VERSION 2
00038 #endif
00039 #include <boost/filesystem.hpp>
00040 #include <boost/lexical_cast.hpp>
00041
00042 #include "math/linearAlgebra/WLinearAlgebra.h"
00043 #include "math/linearAlgebra/WMatrixFixed.h"
00044 #include "math/linearAlgebra/WVectorFixed.h"
00045 #include "WAssert.h"
00046 #include "WColor.h"
00047 #include "WItemSelector.h"
00048
00049 template < typename T >
00050 class WPropertyVariable;
00051 class WProperties;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 typedef enum
00065 {
00066 PV_UNKNOWN,
00067 PV_GROUP,
00068 PV_INT,
00069 PV_DOUBLE,
00070 PV_BOOL,
00071 PV_STRING,
00072 PV_PATH,
00073 PV_SELECTION,
00074 PV_POSITION,
00075 PV_COLOR,
00076 PV_TRIGGER,
00077 PV_MATRIX4X4
00078 }
00079 PROPERTY_TYPE;
00080
00081
00082
00083
00084
00085
00086 typedef enum
00087 {
00088 PV_PURPOSE_INFORMATION,
00089 PV_PURPOSE_PARAMETER
00090
00091 }
00092 PROPERTY_PURPOSE;
00093
00094
00095
00096
00097
00098
00099
00100 namespace WPVBaseTypes
00101 {
00102 typedef int32_t PV_INT;
00103 typedef double PV_DOUBLE;
00104 typedef bool PV_BOOL;
00105 typedef std::string PV_STRING;
00106 typedef boost::filesystem::path PV_PATH;
00107 typedef WItemSelector PV_SELECTION;
00108 typedef WPosition PV_POSITION;
00109 typedef WColor PV_COLOR;
00110 typedef WMatrix4d PV_MATRIX4X4;
00111
00112
00113
00114
00115 typedef enum
00116 {
00117 PV_TRIGGER_READY = 0,
00118 PV_TRIGGER_TRIGGERED
00119 }
00120 PV_TRIGGER;
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 std::ostream& operator<<( std::ostream& out, const PV_TRIGGER& c );
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 std::istream& operator>>( std::istream& in, PV_TRIGGER& c );
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 typedef WProperties WPVGroup;
00153
00154
00155
00156
00157 typedef WPropertyVariable< WPVBaseTypes::PV_INT > WPVInt;
00158
00159
00160
00161
00162 typedef WPropertyVariable< WPVBaseTypes::PV_DOUBLE > WPVDouble;
00163
00164
00165
00166
00167 typedef WPropertyVariable< WPVBaseTypes::PV_BOOL > WPVBool;
00168
00169
00170
00171
00172 typedef WPropertyVariable< WPVBaseTypes::PV_STRING > WPVString;
00173
00174
00175
00176
00177 typedef WPropertyVariable< WPVBaseTypes::PV_PATH > WPVFilename;
00178
00179
00180
00181
00182 typedef WPropertyVariable< WPVBaseTypes::PV_SELECTION > WPVSelection;
00183
00184
00185
00186
00187 typedef WPropertyVariable< WPVBaseTypes::PV_POSITION > WPVPosition;
00188
00189
00190
00191
00192 typedef WPropertyVariable< WPVBaseTypes::PV_COLOR > WPVColor;
00193
00194
00195
00196
00197 typedef WPropertyVariable< WPVBaseTypes::PV_TRIGGER > WPVTrigger;
00198
00199
00200
00201
00202 typedef WPropertyVariable< WPVBaseTypes::PV_MATRIX4X4 > WPVMatrix4X4;
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 typedef boost::shared_ptr< WPVInt > WPropInt;
00213
00214
00215
00216
00217 typedef boost::shared_ptr< WPVDouble > WPropDouble;
00218
00219
00220
00221
00222 typedef boost::shared_ptr< WPVBool > WPropBool;
00223
00224
00225
00226
00227 typedef boost::shared_ptr< WPVString > WPropString;
00228
00229
00230
00231
00232 typedef boost::shared_ptr< WPVFilename > WPropFilename;
00233
00234
00235
00236
00237 typedef boost::shared_ptr< WPVSelection > WPropSelection;
00238
00239
00240
00241
00242 typedef boost::shared_ptr< WPVPosition > WPropPosition;
00243
00244
00245
00246
00247 typedef boost::shared_ptr< WPVColor > WPropColor;
00248
00249
00250
00251
00252 typedef boost::shared_ptr< WPVGroup > WPropGroup;
00253
00254
00255
00256
00257 typedef boost::shared_ptr< WPVTrigger > WPropTrigger;
00258
00259
00260
00261
00262 typedef boost::shared_ptr< WPVMatrix4X4 > WPropMatrix4X4;
00263
00264
00265
00266
00267
00268 namespace PROPERTY_TYPE_HELPER
00269 {
00270
00271
00272
00273 template< typename T >
00274 class WTypeIdentifier
00275 {
00276 public:
00277
00278
00279
00280
00281
00282 PROPERTY_TYPE getType()
00283 {
00284 return PV_UNKNOWN;
00285 }
00286 };
00287
00288
00289
00290
00291
00292
00293 template< typename T >
00294 class WStringConversion
00295 {
00296 public:
00297
00298
00299
00300
00301
00302
00303
00304 T create( const T& , const std::string str )
00305 {
00306 return boost::lexical_cast< T >( str );
00307 }
00308
00309
00310
00311
00312
00313
00314
00315
00316 std::string asString( const T& v )
00317 {
00318 return boost::lexical_cast< std::string >( v );
00319 }
00320 };
00321
00322
00323
00324
00325 template<>
00326 class WTypeIdentifier< WPVBaseTypes::PV_BOOL >
00327 {
00328 public:
00329
00330
00331
00332
00333
00334 PROPERTY_TYPE getType()
00335 {
00336 return PV_BOOL;
00337 }
00338 };
00339
00340
00341
00342
00343 template<>
00344 class WTypeIdentifier< WPVBaseTypes::PV_INT >
00345 {
00346 public:
00347
00348
00349
00350
00351
00352 PROPERTY_TYPE getType()
00353 {
00354 return PV_INT;
00355 }
00356 };
00357
00358
00359
00360
00361 template<>
00362 class WTypeIdentifier< WPVBaseTypes::PV_DOUBLE >
00363 {
00364 public:
00365
00366
00367
00368
00369
00370 PROPERTY_TYPE getType()
00371 {
00372 return PV_DOUBLE;
00373 }
00374 };
00375
00376
00377
00378
00379 template<>
00380 class WTypeIdentifier< WPVBaseTypes::PV_STRING >
00381 {
00382 public:
00383
00384
00385
00386
00387
00388 PROPERTY_TYPE getType()
00389 {
00390 return PV_STRING;
00391 }
00392 };
00393
00394
00395
00396
00397 template<>
00398 class WTypeIdentifier< WPVBaseTypes::PV_PATH >
00399 {
00400 public:
00401
00402
00403
00404
00405
00406 PROPERTY_TYPE getType()
00407 {
00408 return PV_PATH;
00409 }
00410 };
00411
00412
00413
00414
00415 template<>
00416 class WTypeIdentifier< WPVBaseTypes::PV_SELECTION >
00417 {
00418 public:
00419
00420
00421
00422
00423
00424 PROPERTY_TYPE getType()
00425 {
00426 return PV_SELECTION;
00427 }
00428 };
00429
00430
00431
00432
00433
00434 template<>
00435 class WStringConversion< WPVBaseTypes::PV_SELECTION >
00436 {
00437 public:
00438
00439
00440
00441
00442
00443
00444
00445
00446 WPVBaseTypes::PV_SELECTION create( const WPVBaseTypes::PV_SELECTION& old, const std::string str )
00447 {
00448 return old.newSelector( str );
00449 }
00450
00451
00452
00453
00454
00455
00456
00457
00458 std::string asString( const WPVBaseTypes::PV_SELECTION& v )
00459 {
00460 return boost::lexical_cast< std::string >( v );
00461 }
00462 };
00463
00464
00465
00466
00467 template<>
00468 class WTypeIdentifier< WPVBaseTypes::PV_POSITION >
00469 {
00470 public:
00471
00472
00473
00474
00475
00476 PROPERTY_TYPE getType()
00477 {
00478 return PV_POSITION;
00479 }
00480 };
00481
00482
00483
00484
00485 template<>
00486 class WTypeIdentifier< WPVBaseTypes::PV_COLOR >
00487 {
00488 public:
00489
00490
00491
00492
00493
00494 PROPERTY_TYPE getType()
00495 {
00496 return PV_COLOR;
00497 }
00498 };
00499
00500
00501
00502
00503 template<>
00504 class WTypeIdentifier< WPVBaseTypes::PV_TRIGGER >
00505 {
00506 public:
00507
00508
00509
00510
00511
00512 PROPERTY_TYPE getType()
00513 {
00514 return PV_TRIGGER;
00515 }
00516 };
00517
00518
00519
00520
00521 template<>
00522 class WTypeIdentifier< WPVBaseTypes::PV_MATRIX4X4 >
00523 {
00524 public:
00525
00526
00527
00528
00529
00530 PROPERTY_TYPE getType()
00531 {
00532 return PV_MATRIX4X4;
00533 }
00534 };
00535
00536
00537
00538
00539
00540 template<>
00541 class WStringConversion< WPVBaseTypes::PV_MATRIX4X4 >
00542 {
00543 public:
00544
00545
00546
00547
00548
00549
00550
00551 WPVBaseTypes::PV_MATRIX4X4 create( const WPVBaseTypes::PV_MATRIX4X4& , const std::string str )
00552 {
00553 WMatrix4d c;
00554 std::vector< std::string > tokens;
00555 tokens = string_utils::tokenize( str, ";" );
00556 WAssert( tokens.size() >= 16, "There weren't 16 values for a 4x4 Matrix" );
00557
00558 size_t idx = 0;
00559 for( size_t row = 0; row < 4; ++row )
00560 {
00561 for( size_t col = 0; col < 4; ++col )
00562 {
00563 c( row, col ) = boost::lexical_cast< double >( tokens[ idx ] );
00564 idx++;
00565 }
00566 }
00567
00568 return c;
00569 }
00570
00571
00572
00573
00574
00575
00576
00577
00578 std::string asString( const WPVBaseTypes::PV_MATRIX4X4& v )
00579 {
00580 std::ostringstream out;
00581 for( size_t row = 0; row < 4; ++row )
00582 {
00583 for( size_t col = 0; col < 4; ++col )
00584 {
00585 out << v( row, col ) << ";";
00586 }
00587 }
00588 return out.str();
00589 }
00590 };
00591
00592
00593
00594
00595
00596 template<>
00597 class WStringConversion< WPVBaseTypes::PV_POSITION >
00598 {
00599 public:
00600
00601
00602
00603
00604
00605
00606
00607 WPVBaseTypes::PV_POSITION create( const WPVBaseTypes::PV_POSITION& , const std::string str )
00608 {
00609 WPVBaseTypes::PV_POSITION c;
00610 std::vector< std::string > tokens;
00611 tokens = string_utils::tokenize( str, ";" );
00612 WAssert( tokens.size() >= 3, "There weren't 3 values for a 3D vector" );
00613
00614 size_t idx = 0;
00615 for( size_t col = 0; col < 3; ++col )
00616 {
00617 c[ col ] = boost::lexical_cast< double >( tokens[ idx ] );
00618 idx++;
00619 }
00620 return c;
00621 }
00622
00623
00624
00625
00626
00627
00628
00629
00630 std::string asString( const WPVBaseTypes::PV_POSITION& v )
00631 {
00632 std::ostringstream out;
00633 for( size_t col = 0; col < 3; ++col )
00634 {
00635 out << v[ col ] << ";";
00636 }
00637 return out.str();
00638 }
00639 };
00640 }
00641
00642 #endif // WPROPERTYTYPES_H