Leaked source code of windows server 2003
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.

178 lines
4.5 KiB

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