summaryrefslogtreecommitdiffstats
path: root/tools/globalcode/utility/MExt_template.h
blob: 5714e9548f6304c217d8ba5d036fed47850564e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "precompiled/PCH.h"

#ifndef _MEXT_TEMPLATE_H
#define _MEXT_TEMPLATE_H
//-----------------------------------------------------------------------------
// Copyright (C) 2001 Radical Entertainment Ltd.  All rights reserved.
//
// MExt_template.h
//
// Description: 
//
// Modification History:
//  + Created Dec 19, 2001 -- bkusy 
//-----------------------------------------------------------------------------

//This is a warning provided by the STL...  It seems that toollib gets whacky when there 
//is other templates made...  Sigh...
#pragma warning(disable:4786)

//----------------------------------------
// System Includes
//----------------------------------------
//#include <assert.h>

/* Using precompiled headers
#include <maya/MDoubleArray.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MFnDoubleArrayData.h>
#include <maya/MFnIntArrayData.h>
#include <maya/MFnStringArrayData.h>
#include <maya/MIntArray.h>
#include <maya/MObject.h>
#include <maya/MPlug.h>
#include <maya/MPoint.h>
#include <maya/MString.h>
#include <maya/MStringArray.h>
*/

//----------------------------------------
// Project Includes
//----------------------------------------

//----------------------------------------
// Forward References
//----------------------------------------

//----------------------------------------
// Constants, Typedefs and Statics
//----------------------------------------

namespace MExt
{
    namespace Attr
    {

        template < class T >
        void Get( T* value, const MPlug& plug )
        {
            assert( value );

            MStatus status;

            status = plug.getValue( *value );
            assert( status );
        }

        template < >
        void Get< MDoubleArray >( MDoubleArray*, const MPlug& );

        template < >
        void Get< MIntArray >( MIntArray*, const MPlug& );

        template < >
        void Get< MPoint >( MPoint*, const MPlug& );

        template < >
        void Get< MStringArray >( MStringArray*, const MPlug& );

        template < class T >
        void Get( T* value, const MObject& node, const MObject& attr )
        {
            MPlug plug( node, attr );
            Get( value, plug );
        }

        template < class T >
        void Get( T* value, const MObject& node, const MString& attr )
        {
            MStatus status;

            MFnDependencyNode fnNode( node, &status );
            assert( status );

            MPlug plug = fnNode.findPlug( attr, &status );
            assert( status );

            Get( value, plug );
        }

        template < class T >
        void Set( const T& value, MPlug& plug )
        {
            MStatus status;

            status = plug.setValue( const_cast<T&>(value) );
            assert( status );
        }

        template < >
        void Set< MDoubleArray >( const MDoubleArray& array, MPlug& plug );

        template < >
        void Set< MIntArray >( const MIntArray& array, MPlug& plug );

        template < >
        void Set< MPoint >( const MPoint& vertex, MPlug& plug );

        template < >
        void Set< MStringArray >( const MStringArray& array, MPlug& plug );

        template < class T >
        void Set( const T& value, MObject& node, MObject& attr )
        {
            MPlug plug( node, attr );
            Set( value, plug );
        }

        template < class T >
        void Set( const T& value, MObject& node, const MString& attr )
        {
            MStatus status;

            MFnDependencyNode fnNode( node, &status );
            assert( status );

            MPlug plug = fnNode.findPlug( attr, &status );
            assert( status );

            Set( value, plug );
        }

    } // namespace Attr

} // namespace MExt

#endif