Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenenumx.c
Go to the documentation of this file.
00001 /* 00002 * IEnum* implementation 00003 * 00004 * Copyright 2006 Mike McCormack 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #define COBJMACROS 00022 00023 #include <stdarg.h> 00024 00025 #include "windef.h" 00026 #include "winbase.h" 00027 #include "objbase.h" 00028 00029 #include "enumx.h" 00030 00031 #include "wine/list.h" 00032 #include "wine/debug.h" 00033 00034 WINE_DEFAULT_DEBUG_CHANNEL(ole); 00035 00036 struct tagEnumSTATPROPSETSTG_impl 00037 { 00038 const void *vtbl; 00039 LONG ref; 00040 struct list elements; 00041 struct list *current; 00042 ULONG elem_size; 00043 GUID riid; 00044 }; 00045 00046 /************************************************************************ 00047 * enumx_QueryInterface 00048 */ 00049 HRESULT WINAPI enumx_QueryInterface( 00050 enumx_impl *This, 00051 REFIID riid, 00052 void** ppvObject) 00053 { 00054 if ( ppvObject==0 ) 00055 return E_INVALIDARG; 00056 00057 *ppvObject = 0; 00058 00059 if (IsEqualGUID(&IID_IUnknown, riid) || 00060 IsEqualGUID(&This->riid, riid)) 00061 { 00062 IUnknown_AddRef(((IUnknown*)This)); 00063 *ppvObject = This; 00064 return S_OK; 00065 } 00066 00067 return E_NOINTERFACE; 00068 } 00069 00070 /************************************************************************ 00071 * enumx_AddRef 00072 */ 00073 ULONG WINAPI enumx_AddRef(enumx_impl *This) 00074 { 00075 return InterlockedIncrement(&This->ref); 00076 } 00077 00078 /************************************************************************ 00079 * enumx_Release 00080 */ 00081 ULONG WINAPI enumx_Release(enumx_impl *This) 00082 { 00083 ULONG ref; 00084 00085 ref = InterlockedDecrement(&This->ref); 00086 if (ref == 0) 00087 { 00088 while (!list_empty(&This->elements)) 00089 { 00090 struct list *x = list_head(&This->elements); 00091 list_remove(x); 00092 HeapFree(GetProcessHeap(), 0, x); 00093 } 00094 HeapFree(GetProcessHeap(), 0, This); 00095 } 00096 return ref; 00097 } 00098 00099 /************************************************************************ 00100 * enumx_Next 00101 */ 00102 HRESULT WINAPI enumx_Next(enumx_impl *This, ULONG celt, 00103 void *rgelt, ULONG *pceltFetched) 00104 { 00105 unsigned char *p; 00106 ULONG count = 0; 00107 00108 TRACE("%p %u %p\n", This, celt, pceltFetched); 00109 00110 if (This->current == NULL) 00111 This->current = list_head(&This->elements); 00112 p = rgelt; 00113 while (count < celt && This->current && This->current != &This->elements) 00114 { 00115 memcpy(p, &This->current[1], This->elem_size); 00116 p += This->elem_size; 00117 This->current = This->current->next; 00118 count++; 00119 } 00120 if (pceltFetched) 00121 *pceltFetched = count; 00122 if (count < celt) 00123 return S_FALSE; 00124 return S_OK; 00125 } 00126 00127 /************************************************************************ 00128 * enumx_Skip 00129 */ 00130 HRESULT WINAPI enumx_Skip(enumx_impl *This, ULONG celt) 00131 { 00132 ULONG count = 0; 00133 00134 TRACE("%p %u\n", This, celt); 00135 00136 if (This->current == NULL) 00137 This->current = list_head(&This->elements); 00138 00139 while (count < celt && This->current && This->current != &This->elements) 00140 count++; 00141 00142 return S_OK; 00143 } 00144 00145 /************************************************************************ 00146 * enumx_Reset 00147 */ 00148 HRESULT WINAPI enumx_Reset(enumx_impl *This) 00149 { 00150 TRACE("\n"); 00151 00152 This->current = NULL; 00153 return S_OK; 00154 } 00155 00156 /************************************************************************ 00157 * enumx_fnClone 00158 */ 00159 HRESULT WINAPI enumx_Clone( 00160 enumx_impl *iface, 00161 enumx_impl **ppenum) 00162 { 00163 FIXME("\n"); 00164 return E_NOTIMPL; 00165 } 00166 00167 /************************************************************************ 00168 * enumx_allocate 00169 * 00170 * Allocate a generic enumerator 00171 */ 00172 enumx_impl *enumx_allocate(REFIID riid, const void *vtbl, ULONG elem_size) 00173 { 00174 enumx_impl *enumx; 00175 00176 enumx = HeapAlloc(GetProcessHeap(), 0, sizeof *enumx); 00177 if (enumx) 00178 { 00179 enumx->vtbl = vtbl; 00180 enumx->ref = 1; 00181 enumx->current = NULL; 00182 enumx->elem_size = elem_size; 00183 enumx->riid = *riid; 00184 list_init(&enumx->elements); 00185 } 00186 00187 return enumx; 00188 } 00189 00190 /************************************************************************ 00191 * enumx_add_element 00192 * 00193 * Add an element to the enumeration. 00194 */ 00195 void *enumx_add_element(enumx_impl *enumx, const void *data) 00196 { 00197 struct list *element; 00198 00199 element = HeapAlloc(GetProcessHeap(), 0, sizeof *element + enumx->elem_size); 00200 if (!element) 00201 return NULL; 00202 memcpy(&element[1], data, enumx->elem_size); 00203 list_add_tail(&enumx->elements, element); 00204 return &element[1]; 00205 } Generated on Mon May 28 2012 04:25:18 for ReactOS by
1.7.6.1
|