~ubuntu-branches/ubuntu/raring/openwalnut/raring

« back to all changes in this revision

Viewing changes to src/core/common/WPropertyTypes.h

  • Committer: Package Import Robot
  • Author(s): Sebastian Eichelbaum
  • Date: 2012-12-12 11:26:32 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20121212112632-xhiuwkxuz5h0idkh
Tags: 1.3.1+hg5849-1
* Minor changes compared to 1.3.0 but included several bug fixes.
* See http://www.openwalnut.org/versions/4

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <vector>
33
33
#include <utility>
34
34
 
35
 
// Use filesystem version 2 for compatibility with newer boost versions.
36
 
#ifndef BOOST_FILESYSTEM_VERSION
37
 
    #define BOOST_FILESYSTEM_VERSION 2
38
 
#endif
39
35
#include <boost/filesystem.hpp>
40
 
#include <boost/lexical_cast.hpp>
41
36
 
 
37
#include "WStringUtils.h"
42
38
#include "math/linearAlgebra/WLinearAlgebra.h"
43
39
#include "math/linearAlgebra/WMatrixFixed.h"
44
40
#include "math/linearAlgebra/WVectorFixed.h"
48
44
 
49
45
template < typename T >
50
46
class WPropertyVariable;
51
 
class WProperties;
 
47
class WPropertyGroup;
 
48
 
 
49
class WTransferFunction;
52
50
 
53
51
////////////////////////////////////////////////////////////////////////////////////////////////////////
54
 
// NOTE: If you add new types here, please also add corresponding addProperty methods to WProperties
 
52
// NOTE: If you add new types here, please also add corresponding addProperty methods to WPropertyGroup
55
53
////////////////////////////////////////////////////////////////////////////////////////////////////////
56
54
 
57
55
////////////////////////////////////////////////////////////////////////////////////////////////////////
63
61
 */
64
62
typedef enum
65
63
{
66
 
    PV_UNKNOWN,        //!< type not known
67
 
    PV_GROUP,          //!< the group property
68
 
    PV_INT,            //!< integer value
69
 
    PV_DOUBLE,         //!< floating point value
70
 
    PV_BOOL,           //!< boolean
71
 
    PV_STRING,         //!< a string
72
 
    PV_PATH,           //!< a Boost Path object denoting a filename/path
73
 
    PV_SELECTION,      //!< a list of strings, selectable
74
 
    PV_POSITION,       //!< a position property
75
 
    PV_COLOR,          //!< a color property
76
 
    PV_TRIGGER,        //!< for triggering an event
77
 
    PV_MATRIX4X4       //!< for 4x4 matrices
 
64
    PV_UNKNOWN,          //!< type not known
 
65
    PV_GROUP,            //!< the group property
 
66
    PV_INT,              //!< integer value
 
67
    PV_DOUBLE,           //!< floating point value
 
68
    PV_BOOL,             //!< boolean
 
69
    PV_STRING,           //!< a string
 
70
    PV_PATH,             //!< a Boost Path object denoting a filename/path
 
71
    PV_SELECTION,        //!< a list of strings, selectable
 
72
    PV_POSITION,         //!< a position property
 
73
    PV_COLOR,            //!< a color property
 
74
    PV_TRIGGER,          //!< for triggering an event
 
75
    PV_MATRIX4X4,        //!< for 4x4 matrices
 
76
    PV_TRANSFERFUNCTION, //!< for transfer function textures
 
77
    PV_STRUCT,           //!< for complex, structured properties (used by \ref WPropertyStruct)
 
78
    PV_LIST              //!< for a dynamic list of properties of the same type (see \ref WPropertyList)
78
79
}
79
80
PROPERTY_TYPE;
80
81
 
87
88
{
88
89
    PV_PURPOSE_INFORMATION,     //!< information property not meant to be modified from someone (except the creating object)
89
90
    PV_PURPOSE_PARAMETER        //!< a parameter meant to be modified by others to manipulate the behaviour of the module (or whomever created
90
 
                                //!< the property)
 
91
        //!< the property)
91
92
}
92
93
PROPERTY_PURPOSE;
93
94
 
99
100
 */
100
101
namespace WPVBaseTypes
101
102
{
102
 
    typedef int32_t                                         PV_INT;         //!< base type used for every WPVInt
103
 
    typedef double                                          PV_DOUBLE;      //!< base type used for every WPVDouble
104
 
    typedef bool                                            PV_BOOL;        //!< base type used for every WPVBool
105
 
    typedef std::string                                     PV_STRING;      //!< base type used for every WPVString
106
 
    typedef boost::filesystem::path                         PV_PATH;        //!< base type used for every WPVFilename
107
 
    typedef WItemSelector                                   PV_SELECTION;   //!< base type used for every WPVSelection
108
 
    typedef WPosition                                     PV_POSITION;    //!< base type used for every WPVPosition
109
 
    typedef WColor                                          PV_COLOR;       //!< base type used for every WPVColor
110
 
    typedef WMatrix4d                                     PV_MATRIX4X4;   //!< base type used for every WPVMatrix4X4
 
103
    typedef int32_t                                         PV_INT;              //!< base type used for every WPVInt
 
104
    typedef double                                          PV_DOUBLE;           //!< base type used for every WPVDouble
 
105
    typedef bool                                            PV_BOOL;             //!< base type used for every WPVBool
 
106
    typedef std::string                                     PV_STRING;           //!< base type used for every WPVString
 
107
    typedef boost::filesystem::path                         PV_PATH;             //!< base type used for every WPVFilename
 
108
    typedef WItemSelector                                   PV_SELECTION;        //!< base type used for every WPVSelection
 
109
    typedef WPosition                                       PV_POSITION;         //!< base type used for every WPVPosition
 
110
    typedef WColor                                          PV_COLOR;            //!< base type used for every WPVColor
 
111
    typedef WMatrix4d                                       PV_MATRIX4X4;        //!< base type used for every WPVMatrix4X4
 
112
    typedef WTransferFunction                               PV_TRANSFERFUNCTION; //!< base type for every transfer function
111
113
 
112
114
    /**
113
115
     * Enum denoting the possible trigger states. It is used for trigger properties.
117
119
        PV_TRIGGER_READY = 0,                                               //!< Trigger property: is ready to be triggered (again)
118
120
        PV_TRIGGER_TRIGGERED                                                //!< Trigger property: got triggered
119
121
    }
120
 
                                                            PV_TRIGGER;     //!< base type used for every WPVTrigger
 
122
    PV_TRIGGER;     //!< base type used for every WPVTrigger
 
123
 
 
124
    /**
 
125
     * Checks which property types are derived from \ref WPropertyGroupBase. This, for example, is true for PV_GROUP and PV_STRUCT.
 
126
     *
 
127
     * \param type the type to check.
 
128
     *
 
129
     * \return true if cast-able \ref WPropertyGroupBase.
 
130
     */
 
131
    bool isPropertyGroup( PROPERTY_TYPE  type );
121
132
 
122
133
    /**
123
134
     * Write a PV_TRIGGER in string representation to the given output stream.
149
160
/**
150
161
 * Group properties.
151
162
 */
152
 
typedef WProperties WPVGroup;
 
163
typedef WPropertyGroup WPVGroup;
153
164
 
154
165
/**
155
166
 * Int properties.
202
213
typedef WPropertyVariable< WPVBaseTypes::PV_MATRIX4X4 > WPVMatrix4X4;
203
214
 
204
215
/**
 
216
 * Transfer Function properties
 
217
 */
 
218
typedef WPropertyVariable< WPVBaseTypes::PV_TRANSFERFUNCTION > WPVTransferFunction;
 
219
 
 
220
/**
205
221
 * Some convenience type alias for a even more easy usage of WPropertyVariable.
206
222
 * These typdefs define some pointer alias.
207
223
 */
261
277
 */
262
278
typedef boost::shared_ptr< WPVMatrix4X4 > WPropMatrix4X4;
263
279
 
 
280
/**
 
281
 * Alias for the transfer function properties
 
282
 */
 
283
typedef boost::shared_ptr< WPVTransferFunction > WPropTransferFunction;
264
284
 
265
285
/**
266
286
 * This namespace contains several helper classes which translate their template type to an enum.
288
308
    /**
289
309
     * Class helping to create a new instance of the property content from an old one. This might be needed by some types (some need to have a
290
310
     * predecessor for creation).
291
 
     * You only need to specialize this class for types not allowing the direct use of boost::lexical_cast.
 
311
     * You only need to specialize this class for types not allowing the direct use of string_utils::fromString
292
312
     */
293
313
    template< typename T >
294
314
    class WStringConversion
303
323
         */
304
324
        T create( const T& /*old*/, const std::string str )
305
325
        {
306
 
            return boost::lexical_cast< T >( str );
 
326
            return string_utils::fromString< T >( str );
307
327
        }
308
328
 
309
329
        /**
315
335
         */
316
336
        std::string asString( const T& v )
317
337
        {
318
 
            return boost::lexical_cast< std::string >( v );
 
338
            return string_utils::toString( v );
319
339
        }
320
340
    };
321
341
 
457
477
         */
458
478
        std::string asString( const WPVBaseTypes::PV_SELECTION& v )
459
479
        {
460
 
            return boost::lexical_cast< std::string >( v );
 
480
            return string_utils::toString( v );
461
481
        }
462
482
    };
463
483
 
560
580
            {
561
581
                for( size_t col = 0; col < 4; ++col )
562
582
                {
563
 
                    c( row, col ) = boost::lexical_cast< double >( tokens[ idx ] );
 
583
                    c( row, col ) = string_utils::fromString< double >( tokens[ idx ] );
564
584
                    idx++;
565
585
                }
566
586
            }
590
610
    };
591
611
 
592
612
    /**
 
613
     * Class helping to adapt types specified as template parameter into an enum.
 
614
     */
 
615
    template<>
 
616
    class WTypeIdentifier< WPVBaseTypes::PV_TRANSFERFUNCTION >
 
617
    {
 
618
    public:
 
619
        /**
 
620
         * Get type identifier of the template type T.
 
621
         *
 
622
         * \return type identifier-
 
623
         */
 
624
        PROPERTY_TYPE getType()
 
625
        {
 
626
            return PV_TRANSFERFUNCTION;
 
627
        }
 
628
    };
 
629
 
 
630
    /**
 
631
     * Class helping to create a new instance of the property content from an old one. Selections need this special care since they contain not
 
632
     * serializable content which needs to be acquired from its predecessor instance.
 
633
     */
 
634
    template<>
 
635
    class WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >
 
636
    {
 
637
    public:
 
638
        /**
 
639
         * Creates a new instance of the type from a given string. Some classes need a predecessor which is also specified here.
 
640
         *
 
641
         * \param str the new value as string
 
642
         *
 
643
         * \return the new instance
 
644
         */
 
645
        WPVBaseTypes::PV_TRANSFERFUNCTION create( const WPVBaseTypes::PV_TRANSFERFUNCTION& /*old*/, const std::string str );
 
646
 
 
647
        /**
 
648
         * Creates a string from the specified value.
 
649
         *
 
650
         * \param tf the value to convert
 
651
         *
 
652
         * \return the string representation
 
653
         */
 
654
        std::string asString( const WPVBaseTypes::PV_TRANSFERFUNCTION& tf );
 
655
    };
 
656
 
 
657
    /**
593
658
     * Class helping to create a new instance of the property content from an old one. Selections need this special care since they contain not
594
659
     * serializable content which needs to be acquired from its predecessor instance.
595
660
     */
614
679
            size_t idx = 0;
615
680
            for( size_t col = 0; col < 3; ++col )
616
681
            {
617
 
                c[ col ] = boost::lexical_cast< double >( tokens[ idx ] );
 
682
                c[ col ] = string_utils::fromString< double >( tokens[ idx ] );
618
683
                idx++;
619
684
            }
620
685
            return c;