~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to COLLADAStreamWriter/include/COLLADASWParamBase.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
    This file is part of COLLADAStreamWriter.
 
5
 
 
6
    Licensed under the MIT Open Source License,
 
7
    for details please see LICENSE file or the website
 
8
    http://www.opensource.org/licenses/mit-license.php
 
9
*/
 
10
 
 
11
#ifndef __COLLADASTREAMWRITER_PARAM_H__
 
12
#define __COLLADASTREAMWRITER_PARAM_H__
 
13
 
 
14
#include "COLLADASWPrerequisites.h"
 
15
#include "COLLADASWElementWriter.h"
 
16
#include "COLLADASWAnnotation.h"
 
17
#include "COLLADASWValueType.h"
 
18
#include "COLLADASWSampler.h"
 
19
#include "COLLADASWConstants.h"
 
20
 
 
21
namespace COLLADASW
 
22
{
 
23
 
 
24
    /** A class to add a param to the stream.*/
 
25
    class ParamBase : public ElementWriter
 
26
    {
 
27
 
 
28
    protected:
 
29
 
 
30
        /** Used to close the current param. */
 
31
        TagCloser mParamCloser;
 
32
 
 
33
        /** The parameter's name. */
 
34
        String mParamName;
 
35
 
 
36
        /** Flag, if the value element is opened. */
 
37
        bool mValueElementIsOpen;
 
38
 
 
39
        /** The type of the current parameter. */
 
40
        ValueType::ColladaType mParamType;
 
41
 
 
42
    public:
 
43
 
 
44
        /** Constructor
 
45
        @param streamWriter The stream the asset should be written to.*/
 
46
        ParamBase (
 
47
            StreamWriter* streamWriter,
 
48
            const String* paramName=&CSWC::CSW_ELEMENT_PARAM,
 
49
            const ValueType::ColladaType& paramType=ValueType::VALUE_TYPE_UNSPECIFIED );
 
50
 
 
51
        /** Destructor*/
 
52
        virtual ~ParamBase() {}
 
53
 
 
54
        /** Set the current param type. */
 
55
        void setParamType ( const ValueType::ColladaType& paramType );
 
56
 
 
57
        /** Set the current param name. */
 
58
        void setParamName ( const String& paramName );
 
59
 
 
60
        /** Returns the name of the current parameter. */
 
61
        const String& getParamName () const { return mParamName; }
 
62
 
 
63
        /** Opens the current param element. */
 
64
        virtual void openParam ( const String& refe="" );
 
65
 
 
66
        /** Set a param attribute */
 
67
        void appendAttribute ( const String& name, const String& val );
 
68
 
 
69
        /** Writes the semantic of the parameter. */
 
70
        void addSemantic ( const String &semantic );
 
71
 
 
72
        /** Adds a annotation to the param. */
 
73
        template <class T>
 
74
        void addAnnotation (
 
75
            const String &name,
 
76
            const ValueType::ColladaType &valueType,
 
77
            const T val )
 
78
        {
 
79
            COLLADASW::Annotation annotation ( mSW );
 
80
            annotation.openAnnotation ( name );
 
81
            annotation.openValuesElement ( valueType );
 
82
            annotation.appendValues ( val );
 
83
            annotation.closeValuesElement ();
 
84
            annotation.closeAnnotation ();
 
85
        }
 
86
 
 
87
        /** Adds a annotation to the param. */
 
88
        template <class T>
 
89
        void addAnnotation (
 
90
            const String &name,
 
91
            const ValueType::ColladaType &valueType,
 
92
            const T val,
 
93
            const int nval )
 
94
        {
 
95
            COLLADASW::Annotation annotation ( mSW );
 
96
            annotation.openAnnotation ( name );
 
97
            annotation.openValuesElement ( valueType );
 
98
            annotation.appendValues ( val, nval );
 
99
            annotation.closeValuesElement ();
 
100
            annotation.closeAnnotation ();
 
101
        }
 
102
 
 
103
        /** Adds a annotation to the param. */
 
104
        void addAnnotations ( std::vector<Annotation>& annotations )
 
105
        {
 
106
            for ( size_t i=0; i<annotations.size (); ++i )
 
107
            {
 
108
                COLLADASW::Annotation& annotation = annotations [i];
 
109
                annotation.add ();
 
110
            }
 
111
        }
 
112
 
 
113
        /** Opens the param's value element of the given type. */
 
114
        void openValuesElement ();
 
115
 
 
116
        /** Close the param's value element of the given type. */
 
117
        void closeValuesElement ();
 
118
 
 
119
        /** Adds @a value to the array*/
 
120
        template <class Type>
 
121
        void appendValues ( const std::vector<Type>& value )
 
122
        {
 
123
            openValuesElement ();
 
124
            mSW->appendValues ( value );
 
125
        }
 
126
 
 
127
        /** Adds @a value to the array*/
 
128
        template <class Type>
 
129
        void appendValues ( const Type value )
 
130
        {
 
131
            openValuesElement ();
 
132
            mSW->appendValues ( value );
 
133
        }
 
134
 
 
135
        /** Adds @a value1  and @a value2 to the array*/
 
136
        template <class Type>
 
137
        void appendValues ( const Type value1, const Type value2 )
 
138
        {
 
139
            openValuesElement ();
 
140
            mSW->appendValues ( value1, value2 );
 
141
        }
 
142
 
 
143
 
 
144
        /** Adds @a value1, @a value2 and @a value3 to the array*/
 
145
        template <class Type>
 
146
        void appendValues ( const Type value1, const Type value2, const Type value3 )
 
147
        {
 
148
            openValuesElement ();
 
149
            mSW->appendValues ( value1, value2, value3 );
 
150
        }
 
151
 
 
152
        /** Adds @a value1, @a value2, @a value3 and @a value4 to the array*/
 
153
        template <class Type>
 
154
        void appendValues ( const Type value1, const Type value2, const Type value3, const Type value4 )
 
155
        {
 
156
            openValuesElement ();
 
157
            mSW->appendValues ( value1, value2, value3, value4 );
 
158
        }
 
159
 
 
160
        /**
 
161
        * This function must be called after the last value has been added to the array
 
162
        * and before another element has been opened.
 
163
        * @param closeSourceElement false, if we want to add some extra tags and close the element later.
 
164
        */
 
165
        void closeParam ();
 
166
 
 
167
    protected:
 
168
 
 
169
        /** Returns the closer tag for the current parameter. */
 
170
        TagCloser& getParamCloser () { return mParamCloser; }
 
171
 
 
172
        /** Set the current tag closer. */
 
173
        void setParamCloser ( const TagCloser& tagCloser ) { mParamCloser = tagCloser; }
 
174
 
 
175
    };
 
176
 
 
177
} //namespace COLLADASW
 
178
 
 
179
 
 
180
#endif //__COLLADASTREAMWRITER_PARAM_H__