Cortex  10.0.0-a4
MArrayIter.h
1 //
3 // Copyright (c) 2007, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IE_MAYACORE_MARRAYITER_H
36 #define IE_MAYACORE_MARRAYITER_H
37 
38 #include "IECoreMaya/MArrayTraits.h"
39 
40 #include "maya/MStringArray.h"
41 #include "maya/MString.h"
42 
43 #include <iterator>
44 #include <vector>
45 
46 namespace IECoreMaya
47 {
48 
51 template<typename T>
52 struct MArrayIter
53 {
54 
55  typedef typename MArrayTraits<T>::ValueType *Iterator;
56  typedef const typename MArrayTraits<T>::ValueType *ConstIterator;
57  typedef std::reverse_iterator<Iterator> ReverseIterator;
58  typedef std::reverse_iterator<ConstIterator> ConstReverseIterator;
59 
60  static inline Iterator begin( T &array );
61  static inline ConstIterator begin( const T &array );
62  static inline Iterator end( T &array );
63  static inline ConstIterator end( const T &array );
64 
65  static inline ReverseIterator reverseBegin( T &array );
66  static inline ConstReverseIterator reverseBegin( const T &array );
67  static inline ReverseIterator reverseEnd( T &array );
68  static inline ConstReverseIterator reverseEnd( const T &array );
69 
70 };
71 
74 template<typename T>
75 class MayaAppendIterator : public std::iterator< std::output_iterator_tag, void, void, void, void>
76 {
77 
78  public:
79 
80  typedef T ContainerType;
81 
82  explicit MayaAppendIterator(T& x) : m_container(&x) {}
83 
85  {
86  m_container->append(v);
87  return *this;
88  }
89 
90  MayaAppendIterator& operator*()
91  {
92  return *this;
93  }
94 
95  MayaAppendIterator& operator++()
96  {
97  return *this;
98  }
99 
100  MayaAppendIterator operator++(int)
101  {
102  return *this;
103  }
104 
105  protected:
106  T* m_container;
107 };
108 
110 template<>
111 class MayaAppendIterator<MStringArray> : public std::iterator< std::output_iterator_tag, void, void, void, void>
112 {
113 
114  public:
115 
116  typedef MStringArray ContainerType;
117 
118  explicit MayaAppendIterator(MStringArray& x) : m_container(&x) {}
119 
120  MayaAppendIterator& operator=(const MString &v)
121  {
122  m_container->append(v);
123  return *this;
124  }
125 
126  MayaAppendIterator& operator=(const std::string &v)
127  {
128  m_container->append(v.c_str());
129  return *this;
130  }
131 
132  MayaAppendIterator& operator*()
133  {
134  return *this;
135  }
136 
137  MayaAppendIterator& operator++()
138  {
139  return *this;
140  }
141 
142  MayaAppendIterator operator++(int)
143  {
144  return *this;
145  }
146 
147  protected:
148  MStringArray* m_container;
149 
150 };
151 
152 template<typename T>
153 inline MayaAppendIterator<T> MArrayInserter(T& x)
154 {
155  return MayaAppendIterator<T>(x);
156 }
157 
158 } // namespace IECoreMaya
159 
160 #include "IECoreMaya/MArrayIter.inl"
161 
162 #endif // IE_MAYACORE_MARRAYITER_H
Definition: MArrayIter.h:75
The IECoreMaya namespace holds all the functionality of libIECoreMaya.
Definition: BoolParameterHandler.h:44
Definition: MArrayIter.h:52
void ValueType
The type held in the array.
Definition: MArrayTraits.h:70