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.

208 lines
3.1 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. */
  4. #ifndef __SDP_GENERAL__
  5. #define __SDP_GENERAL__
  6. #include "sdpcommo.h"
  7. #include <stdlib.h> // for strtoul()
  8. #include <ctype.h> // for isdigit()
  9. #include "sdpdef.h"
  10. template <class T>
  11. class _DllDecl SDP_ARRAY : public CArray<T, T>
  12. {
  13. public:
  14. virtual void Reset()
  15. {
  16. RemoveAll();
  17. return;
  18. }
  19. };
  20. class _DllDecl BSTR_ARRAY : public SDP_ARRAY<BSTR>
  21. {
  22. };
  23. class _DllDecl CHAR_ARRAY : public SDP_ARRAY<CHAR>
  24. {
  25. };
  26. class _DllDecl BYTE_ARRAY : public SDP_ARRAY<BYTE>
  27. {
  28. };
  29. class _DllDecl LONG_ARRAY : public SDP_ARRAY<LONG>
  30. {
  31. };
  32. class _DllDecl ULONG_ARRAY : public SDP_ARRAY<ULONG>
  33. {
  34. };
  35. template <class T_PTR>
  36. class _DllDecl SDP_POINTER_ARRAY : public SDP_ARRAY<T_PTR>
  37. {
  38. public:
  39. inline SDP_POINTER_ARRAY();
  40. inline void ClearDestroyMembersFlag(
  41. );
  42. virtual void Reset();
  43. virtual ~SDP_POINTER_ARRAY()
  44. {
  45. Reset();
  46. }
  47. protected:
  48. BOOL m_DestroyMembers;
  49. };
  50. template <class T_PTR>
  51. inline
  52. SDP_POINTER_ARRAY<T_PTR>::SDP_POINTER_ARRAY(
  53. )
  54. : m_DestroyMembers(TRUE)
  55. {
  56. }
  57. template <class T_PTR>
  58. inline void
  59. SDP_POINTER_ARRAY<T_PTR>::ClearDestroyMembersFlag(
  60. )
  61. {
  62. m_DestroyMembers = FALSE;
  63. }
  64. template <class T_PTR>
  65. /* virtual */ void
  66. SDP_POINTER_ARRAY<T_PTR>::Reset(
  67. )
  68. {
  69. // if members must be destroyed on destruction, delete each of them
  70. if ( m_DestroyMembers )
  71. {
  72. int Size = (int) GetSize();
  73. if ( 0 < Size )
  74. {
  75. for ( int i=0; i < Size; i++ )
  76. {
  77. T_PTR Member = GetAt(i);
  78. ASSERT(NULL != Member);
  79. if ( NULL == Member )
  80. {
  81. SetLastError(SDP_INTERNAL_ERROR);
  82. return;
  83. }
  84. delete Member;
  85. }
  86. }
  87. }
  88. SDP_ARRAY<T_PTR>::Reset();
  89. return;
  90. }
  91. class _DllDecl LINE_TERMINATOR
  92. {
  93. public:
  94. inline LINE_TERMINATOR(
  95. IN CHAR *Start,
  96. IN const CHAR Replacement
  97. );
  98. inline IsLegal() const;
  99. inline DWORD GetLength() const;
  100. inline ~LINE_TERMINATOR();
  101. private:
  102. CHAR *m_Start;
  103. DWORD m_Length;
  104. CHAR m_Replacement;
  105. };
  106. inline
  107. LINE_TERMINATOR::LINE_TERMINATOR(
  108. IN CHAR *Start,
  109. IN const CHAR Replacement
  110. )
  111. : m_Start(Start),
  112. m_Replacement(Replacement)
  113. {
  114. if ( NULL != Start )
  115. {
  116. m_Length = strlen(m_Start);
  117. }
  118. }
  119. inline
  120. LINE_TERMINATOR::IsLegal(
  121. ) const
  122. {
  123. return (NULL == m_Start)? FALSE : TRUE;
  124. }
  125. inline DWORD
  126. LINE_TERMINATOR::GetLength(
  127. ) const
  128. {
  129. return m_Length;
  130. }
  131. inline
  132. LINE_TERMINATOR::~LINE_TERMINATOR(
  133. )
  134. {
  135. if ( IsLegal() )
  136. {
  137. m_Start[m_Length] = m_Replacement;
  138. }
  139. }
  140. // Isolates tokens by searching for one of the separators
  141. // and returns the first separator thats found
  142. CHAR *
  143. GetToken(
  144. IN CHAR *String,
  145. IN BYTE NumSeparators,
  146. IN const CHAR *SeparatorChars,
  147. OUT CHAR &Separator
  148. );
  149. #endif // __SDP_GENERAL__