Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
5.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: stemcf.cxx
  7. //
  8. // Contents: Stemmer class factory
  9. //
  10. // History: 01-July-1996 PatHal Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. #include "stemcf.hxx"
  16. #include "stemmer.hxx"
  17. extern long gulcInstances;
  18. //+-------------------------------------------------------------------------
  19. //
  20. // Method: CStemmerCF::CStemmerCF
  21. //
  22. // Synopsis: Stemmer class factory constructor
  23. //
  24. //--------------------------------------------------------------------------
  25. CStemmerCF::CStemmerCF( LCID lcid )
  26. : _cRefs( 1 ), _lcid( lcid )
  27. {
  28. InterlockedIncrement( &gulcInstances );
  29. }
  30. //+-------------------------------------------------------------------------
  31. //
  32. // Method: CStemmerCF::~CStemmerCF
  33. //
  34. // Synopsis: Stemmer class factory destructor
  35. //
  36. //--------------------------------------------------------------------------
  37. CStemmerCF::~CStemmerCF()
  38. {
  39. InterlockedDecrement( &gulcInstances );
  40. }
  41. //+-------------------------------------------------------------------------
  42. //
  43. // Method: CStemmerCF::QueryInterface
  44. //
  45. // Synopsis: Rebind to other interface
  46. //
  47. // Arguments: [riid] -- IID of new interface
  48. // [ppvObject] -- New interface * returned here
  49. //
  50. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  51. //
  52. //--------------------------------------------------------------------------
  53. SCODE STDMETHODCALLTYPE CStemmerCF::QueryInterface( REFIID riid,
  54. void ** ppvObject )
  55. {
  56. //
  57. // Optimize QueryInterface by only checking minimal number of bytes.
  58. //
  59. // IID_IUnknown = 00000000-0000-0000-C000-000000000046
  60. // IID_IClassFactory = 00000001-0000-0000-C000-000000000046
  61. // --
  62. // |
  63. // +--- Unique!
  64. //
  65. Assert( (IID_IUnknown.Data1 & 0x000000FF) == 0x00 );
  66. Assert( (IID_IClassFactory.Data1 & 0x000000FF) == 0x01 );
  67. IUnknown *pUnkTemp;
  68. SCODE sc = S_OK;
  69. switch( riid.Data1 & 0x000000FF )
  70. {
  71. case 0x00:
  72. if ( riid == IID_IUnknown )
  73. pUnkTemp = (IUnknown *)this;
  74. else
  75. sc = E_NOINTERFACE;
  76. break;
  77. case 0x01:
  78. if ( riid == IID_IClassFactory )
  79. pUnkTemp = (IUnknown *)(IClassFactory *)this;
  80. else
  81. sc = E_NOINTERFACE;
  82. break;
  83. default:
  84. pUnkTemp = 0;
  85. sc = E_NOINTERFACE;
  86. break;
  87. }
  88. if( 0 != pUnkTemp )
  89. {
  90. *ppvObject = (void * )pUnkTemp;
  91. pUnkTemp->AddRef();
  92. }
  93. else
  94. *ppvObject = 0;
  95. return(sc);
  96. }
  97. //+-------------------------------------------------------------------------
  98. //
  99. // Method: CStemmerCF::AddRef
  100. //
  101. // Synopsis: Increments refcount
  102. //
  103. //--------------------------------------------------------------------------
  104. ULONG STDMETHODCALLTYPE CStemmerCF::AddRef()
  105. {
  106. return InterlockedIncrement( &_cRefs );
  107. }
  108. //+-------------------------------------------------------------------------
  109. //
  110. // Method: CStemmerCF::Release
  111. //
  112. // Synopsis: Decrement refcount. Delete if necessary.
  113. //
  114. //--------------------------------------------------------------------------
  115. ULONG STDMETHODCALLTYPE CStemmerCF::Release()
  116. {
  117. unsigned long uTmp = InterlockedDecrement( &_cRefs );
  118. if ( 0 == uTmp )
  119. delete this;
  120. return(uTmp);
  121. }
  122. //+-------------------------------------------------------------------------
  123. //
  124. // Method: CStemmerCF::CreateInstance
  125. //
  126. // Synopsis: Creates new CStemmer object
  127. //
  128. // Arguments: [pUnkOuter] -- 'Outer' IUnknown
  129. // [riid] -- Interface to bind
  130. // [ppvObject] -- Interface returned here
  131. //
  132. //--------------------------------------------------------------------------
  133. SCODE STDMETHODCALLTYPE CStemmerCF::CreateInstance( IUnknown * pUnkOuter,
  134. REFIID riid,
  135. void * * ppvObject )
  136. {
  137. CStemmer *pIUnk = 0;
  138. SCODE sc = S_OK;
  139. __try
  140. {
  141. pIUnk = new CStemmer( _lcid );
  142. sc = pIUnk->QueryInterface( riid , ppvObject );
  143. pIUnk->Release(); // Release extra refcount from QueryInterface
  144. }
  145. __except(1)
  146. {
  147. Assert( 0 == pIUnk );
  148. sc = E_UNEXPECTED;
  149. }
  150. return (sc);
  151. }
  152. //+-------------------------------------------------------------------------
  153. //
  154. // Method: CStemmerCF::LockServer
  155. //
  156. // Synopsis: Force class factory to remain loaded
  157. //
  158. // Arguments: [fLock] -- TRUE if locking, FALSE if unlocking
  159. //
  160. // Returns: S_OK
  161. //
  162. //--------------------------------------------------------------------------
  163. SCODE STDMETHODCALLTYPE CStemmerCF::LockServer(BOOL fLock)
  164. {
  165. if(fLock)
  166. InterlockedIncrement( &gulcInstances );
  167. else
  168. InterlockedDecrement( &gulcInstances );
  169. return(S_OK);
  170. }