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.

133 lines
2.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: N C S T L . H
  7. //
  8. // Contents: STL utilities.
  9. //
  10. // Notes: Pollute this under penalty of death.
  11. //
  12. // Author: shaunco 09 Oct 1997
  13. // Polluter: deonb 2 Jan 2002.
  14. //
  15. //----------------------------------------------------------------------------
  16. #ifndef _NCSTL_H_
  17. #define _NCSTL_H_
  18. #include "ncmem.h"
  19. #include "list"
  20. #include "vector"
  21. #include "xstring"
  22. #include "string"
  23. using namespace std;
  24. #if defined(USE_CUSTOM_STL_ALLOCATOR) && defined (_DLL)
  25. #error You must statically link to the CRT to use the NetConfig custom STL Allocator
  26. #endif
  27. #ifdef COMPILE_WITH_TYPESAFE_PRINTF
  28. class CWideString : public wstring
  29. {
  30. public:
  31. CWideString();
  32. CWideString(WCHAR);
  33. CWideString(LPCWSTR);
  34. CWideString(LPCWSTR, size_type);
  35. CWideString(const CWideString&);
  36. CWideString(const wstring&);
  37. CWideString& operator=(const LPWSTR _S)
  38. {return *this; }
  39. CWideString& operator=(PCWSTR _S)
  40. {return *this; }
  41. private:
  42. operator void*()
  43. {
  44. return this;
  45. }
  46. };
  47. #else
  48. typedef wstring CWideString;
  49. #endif
  50. typedef CWideString tstring;
  51. typedef list<tstring*> ListStrings;
  52. //+--------------------------------------------------------------------------
  53. //
  54. // Funct: DumpListStrings
  55. //
  56. // Desc: debug utility function to dump out the given list
  57. //
  58. // Args:
  59. //
  60. // Return: (void)
  61. //
  62. // Notes:
  63. //
  64. // History: 1-Dec-97 SumitC Created
  65. //
  66. //---------------------------------------------------------------------------
  67. inline
  68. PCWSTR
  69. DumpListStrings(
  70. IN const list<tstring *>& lstr,
  71. OUT tstring* pstrOut)
  72. {
  73. WCHAR szBuf [1024];
  74. INT i;
  75. list<tstring *>::const_iterator iter;
  76. pstrOut->erase();
  77. for (iter = lstr.begin(), i = 1;
  78. iter != lstr.end();
  79. iter++, i++)
  80. {
  81. wsprintfW(szBuf, L" %2i: %s\n", i, (*iter)->c_str());
  82. pstrOut->append(szBuf);
  83. }
  84. return pstrOut->c_str();
  85. }
  86. template<class T>
  87. void
  88. FreeCollectionAndItem (
  89. T& col)
  90. {
  91. for(T::iterator iter = col.begin(); iter != col.end(); ++iter)
  92. {
  93. T::value_type pElem = *iter;
  94. delete pElem;
  95. }
  96. col.erase (col.begin(), col.end());
  97. }
  98. template<class T>
  99. void
  100. FreeVectorItem (
  101. vector<T>& v,
  102. UINT i)
  103. {
  104. if ((v.size()>0) && (i<v.size()))
  105. {
  106. delete v[i];
  107. vector<T>::iterator iterItem = v.begin() + i;
  108. v.erase (iterItem);
  109. }
  110. }
  111. #endif // _NCSTL_H_