kodi
EnumerableNptArray.h
1 /*****************************************************************
2 |
3 | Platinum - Managed EnumerableNptArray
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
13 |
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 |
21 | This program is distributed in the hope that it will be useful,
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | GNU General Public License for more details.
25 |
26 | You should have received a copy of the GNU General Public License
27 | along with this program; see the file LICENSE.txt. If not, write to
28 | the Free Software Foundation, Inc.,
29 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 | http://www.gnu.org/licenses/gpl-2.0.html
31 |
32 ****************************************************************/
33 #pragma once
34 
35 namespace Platinum
36 {
37 
38 namespace Enumerables
39 {
40 
41 /*----------------------------------------------------------------------
42 | EnumerableNptArray
43 +---------------------------------------------------------------------*/
44 template<typename T_DotNetType, typename T_NativeType>
45 private ref class EnumerableNptArray : public IEnumerable<T_DotNetType>
46 {
47 private:
48 
49  ref class EnumerableNptArrayIterator : public IEnumerator<T_DotNetType>
50  {
51  private:
52 
53  const NPT_Array<T_NativeType>* m_pArray;
54  NPT_Ordinal m_Index;
55 
56  public:
57 
58  virtual property T_DotNetType Current
59  {
60  T_DotNetType get()
61  {
62  return marshal_as<T_DotNetType>(*(*m_pArray)[m_Index]);
63  }
64  }
65 
66  private:
67 
68  virtual property Object^ Current2
69  {
70  Object^ get() sealed = System::Collections::IEnumerator::Current::get
71  {
72  return marshal_as<T_DotNetType>(*(*m_pArray)[m_Index]); // FIXME: This is a problem when T_NativeType is not a pointer (like PLT_DeviceDataReference for example)
73  }
74  }
75 
76  public:
77 
78  virtual bool MoveNext()
79  {
80  if (m_Index < m_pArray->GetItemCount() - 1)
81  {
82  m_Index++;
83  }
84 
85  return false;
86  }
87 
88  virtual void Reset()
89  {
90  m_Index = -1;
91  }
92 
93  public:
94 
95  EnumerableNptArrayIterator(const NPT_Array<T_NativeType>& array)
96  {
97  m_Index = -1;
98  m_pArray = &array;
99  }
100 
101  ~EnumerableNptArrayIterator()
102  {
103  }
104 
105  };
106 
107 private:
108 
109  const NPT_Array<T_NativeType>* m_pArray;
110 
111 public:
112 
113  virtual IEnumerator<T_DotNetType>^ GetEnumerator()
114  {
115  return gcnew EnumerableNptArrayIterator(*m_pArray);
116  }
117 
118 private:
119 
120  virtual System::Collections::IEnumerator^ GetEnumerator2() sealed = System::Collections::IEnumerable::GetEnumerator
121  {
122  return gcnew EnumerableNptArrayIterator(*m_pArray);
123  }
124 
125 public:
126 
128  {
129  m_pArray = &array;
130  }
131 };
132 
133 /*----------------------------------------------------------------------
134 | EnumerableNptArrayRef
135 +---------------------------------------------------------------------*/
136 template<typename T_DotNetType, typename T_NativeType>
137 private ref class EnumerableNptArrayRef : public IEnumerable<T_DotNetType>
138 {
139 private:
140 
141  ref class EnumerableNptArrayRefIterator : public IEnumerator<T_DotNetType>
142  {
143  private:
144 
145  const NPT_Array<T_NativeType>* m_pArray;
146  NPT_Ordinal m_Index;
147 
148  public:
149 
150  virtual property T_DotNetType Current
151  {
152  T_DotNetType get()
153  {
154  return marshal_as<T_DotNetType>((*m_pArray)[m_Index]);
155  }
156  }
157 
158  private:
159 
160  virtual property Object^ Current2
161  {
162  Object^ get() sealed = System::Collections::IEnumerator::Current::get
163  {
164  return marshal_as<T_DotNetType>((*m_pArray)[m_Index]); // FIXME: This is a problem when T_NativeType is not a pointer (like PLT_DeviceDataReference for example)
165  }
166  }
167 
168  public:
169 
170  virtual bool MoveNext()
171  {
172  if (m_Index < m_pArray->GetItemCount() - 1)
173  {
174  m_Index++;
175  }
176 
177  return false;
178  }
179 
180  virtual void Reset()
181  {
182  m_Index = -1;
183  }
184 
185  public:
186 
187  EnumerableNptArrayRefIterator(const NPT_Array<T_NativeType>& array)
188  {
189  m_Index = -1;
190  m_pArray = &array;
191  }
192 
193  ~EnumerableNptArrayRefIterator()
194  {
195  }
196 
197  };
198 
199 private:
200 
201  const NPT_Array<T_NativeType>* m_pArray;
202 
203 public:
204 
205  virtual IEnumerator<T_DotNetType>^ GetEnumerator()
206  {
207  return gcnew EnumerableNptArrayRefIterator(*m_pArray);
208  }
209 
210 private:
211 
212  virtual System::Collections::IEnumerator^ GetEnumerator2() sealed = System::Collections::IEnumerable::GetEnumerator
213  {
214  return gcnew EnumerableNptArrayRefIterator(*m_pArray);
215  }
216 
217 public:
218 
220  {
221  m_pArray = &array;
222  }
223 };
224 
225 }
226 }
Definition: NptArray.h:54
Definition: EnumerableNptArray.h:45
Definition: EnumerableNptArray.h:137