arrenum.h
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:12k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: arrenum.h,v 1.1.1.1.50.3 2004/07/09 01:45:50 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include "unkimp.h"
  50. /* This class implements the fragment Enumerator
  51.  */
  52. #define DECLARE_INTERFACE_ARRAY_ENUMERATOR(ENUMERATED, IENUMERATE)
  53.     class _C##IENUMERATE##IMP                                           
  54. : public IENUMERATE                                             
  55. , public CUnknownIMP                                            
  56.     {                                                                   
  57. DECLARE_UNKNOWN(_C##IENUMERATE##IMP)
  58.     public:                                                             
  59. _C##IENUMERATE##IMP()                                           
  60.     : m_arrpbufData(NULL)                                       
  61.     , m_ulIndex(0)                                              
  62. {}                                                              
  63. ~_C##IENUMERATE##IMP()                                          
  64. {_KillData();}                                                  
  65. STDMETHOD(Reset)(THIS)                                          
  66. {                                                               
  67.     m_ulIndex = 0;                                              
  68.     return HXR_OK;                                              
  69. }                                                               
  70. STDMETHOD(Next)                                                 
  71. (                                                               
  72.     THIS_                                                       
  73.     UINT32          ulNumToReturn,                              
  74.     ENUMERATED**    ppbufNext,                                  
  75.     UINT32*         pulNumReturned                              
  76. )                                                               
  77. {                                                               
  78.     if(!ppbufNext || (ulNumToReturn != 1 && pulNumReturned == NULL))    
  79.     {                                                           
  80. return HXR_POINTER;                                     
  81.     }                                                           
  82.     if(!m_arrpbufData || !m_ulTotal)                            
  83.     {                                                           
  84. return HXR_FAIL;                                        
  85.     }                                                           
  86.     HX_RESULT pnrRes = HXR_OK;                                  
  87.     UINT32 ulRemaining = m_ulTotal-m_ulIndex;                   
  88.     if(ulNumToReturn > ulRemaining)                             
  89.     {                                                           
  90. pnrRes = HXR_INCOMPLETE;                                
  91. ulNumToReturn = ulRemaining;                            
  92.     }                                                           
  93.     else                                                        
  94.     {                                                           
  95. ulRemaining = ulNumToReturn;                            
  96.     }                                                           
  97.     if (pulNumReturned)
  98.     {
  99. *pulNumReturned = ulNumToReturn;                        
  100.     }
  101.     while(ulRemaining)                                          
  102.     {                                                           
  103. (                                                       
  104.     ppbufNext[ulRemaining-ulNumToReturn]
  105.     = m_arrpbufData[m_ulIndex]                          
  106. )->AddRef();                                            
  107. ++m_ulIndex;                                            
  108. --ulRemaining;                                          
  109.     }                                                           
  110.     return pnrRes;                                              
  111. }                                                               
  112. STDMETHOD(Skip)                                                 
  113. (                                                               
  114.     THIS_                                                       
  115.     UINT32 ulNumToSkip                                          
  116. )                                                               
  117. {                                                               
  118.     m_ulIndex += ulNumToSkip;                                   
  119.     if (m_ulIndex < m_ulTotal)                                  
  120.     {                                                           
  121. return HXR_OK;                                            
  122.     }                                                           
  123.     m_ulIndex = m_ulTotal;                                      
  124.     return HXR_FAIL;                                             
  125. }                                                               
  126. STDMETHOD(Clone)                                                
  127. (                                                               
  128.     THIS_                                                       
  129.     IENUMERATE** ppefbNew                                       
  130. )                                                               
  131. {                                                               
  132.     ENUMERATED** arrpbufData = NULL;                            
  133.     if(m_arrpbufData && m_ulTotal)                              
  134.     {                                                           
  135. UINT32 ulIndex = 0;                                     
  136. arrpbufData = (ENUMERATED**)new ENUMERATED*[m_ulTotal];   
  137. for                                                     
  138. (                                                       
  139.     ulIndex = 0;                                        
  140.     ulIndex < m_ulTotal;                                
  141.     ++ulIndex                                           
  142. )                                                       
  143. {                                                       
  144.     arrpbufData[ulIndex] = m_arrpbufData[ulIndex];      
  145.     (arrpbufData[ulIndex])->AddRef();                   
  146. }                                                       
  147.     }                                                           
  148.     _C##IENUMERATE##IMP* pNewEnum = CreateObject();             
  149.     pNewEnum->_SetData(arrpbufData, m_ulTotal, m_ulIndex);      
  150.     return pNewEnum->QueryInterface(IID_##IENUMERATE, (void**)ppefbNew);   
  151. }                                                               
  152. void _SetData                                                   
  153. (                                                               
  154.     ENUMERATED** arrpbufData,                                   
  155.     UINT32 ulTotal,                                             
  156.     UINT32 ulIndex = 0                                          
  157. )                                                               
  158. {                                                               
  159.     _KillData();                                                
  160.     m_arrpbufData = arrpbufData;                                
  161.     m_ulTotal = ulTotal;                                        
  162.     m_ulIndex = ulIndex;                                        
  163. }                                                               
  164.     private:                                                            
  165. void _KillData()                                                
  166. {                                                               
  167.     if(m_arrpbufData)                                           
  168.     {                                                           
  169. for                                                     
  170. (                                                       
  171.     m_ulIndex = 0;                                      
  172.     m_ulIndex < m_ulTotal;                              
  173.     ++m_ulIndex                                         
  174. )                                                       
  175. {                                                       
  176.     (m_arrpbufData[m_ulIndex])->Release();              
  177. }                                                       
  178. delete[] m_arrpbufData;                                 
  179. m_ulIndex = 0;                                          
  180.     }                                                           
  181. }                                                               
  182. ENUMERATED**    m_arrpbufData;                                  
  183. UINT32          m_ulIndex;                                      
  184. UINT32          m_ulTotal;                                      
  185.     }                                                                  
  186. #define IMPLEMENT_INTERFACE_ARRAY_ENUMERATOR(IENUMERATE)
  187.     BEGIN_INTERFACE_LIST(_C##IENUMERATE##IMP)
  188. INTERFACE_LIST_ENTRY(IID_##IENUMERATE,  IENUMERATE)
  189.     END_INTERFACE_LIST
  190. #define CREATE_INTERFACE_ARRAY_ENUMERATOR(IENUMERATE, ARRAY, TOTAL, NEWENUM)        
  191.     {                                                                               
  192. _C##IENUMERATE##IMP* _pNewEnum = _C##IENUMERATE##IMP::CreateObject();       
  193. _pNewEnum->_SetData(ARRAY, TOTAL);                                          
  194. _pNewEnum->QueryInterface(IID_##IENUMERATE, (void**)NEWENUM);   
  195.     }