arrenum.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:11k
源码类别:

Symbian

开发平台:

C/C++

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