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.

156 lines
4.9 KiB

  1. // MultiStrZ.cpp -- Multiple String, zero-terminated class definition.
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #include "NoWarning.h"
  8. #include "ForceLib.h"
  9. #include <numeric>
  10. #include "MultiStrZ.h"
  11. using namespace std;
  12. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  13. namespace
  14. {
  15. MultiStringZ::SizeType
  16. LengthAccumulator(MultiStringZ::SizeType cInitLength,
  17. MultiStringZ::ValueType const &rs)
  18. {
  19. return cInitLength += rs.length() + 1; // include terminating 0
  20. }
  21. MultiStringZ::ValueType &
  22. StringAccumulator(MultiStringZ::ValueType &lhs,
  23. MultiStringZ::ValueType const &rhs)
  24. {
  25. // include terminating 0
  26. lhs.append(rhs.c_str(), rhs.length() + 1);
  27. return lhs;
  28. }
  29. MultiStringZ::csSizeType
  30. csLengthAccumulator(MultiStringZ::csSizeType cInitLength,
  31. MultiStringZ::csValueType const &rs)
  32. {
  33. return cInitLength += rs.GetLength()+1; //Include terminating 0
  34. }
  35. MultiStringZ::csValueType &
  36. csStringAccumulator(MultiStringZ::csValueType &lhs,
  37. MultiStringZ::csValueType const &rhs)
  38. {
  39. int lLen = lhs.GetLength();
  40. int rLen = rhs.GetLength();
  41. LPTSTR pBuffer = lhs.GetBufferSetLength(lLen+rLen+1);
  42. wcsncpy(pBuffer+lLen,(LPCTSTR)rhs,rLen);
  43. *(pBuffer+lLen+rLen) = TCHAR('\0');//The separator between strings
  44. lhs.ReleaseBuffer(lLen+rLen+1);
  45. return lhs;
  46. }
  47. } // namespace
  48. /////////////////////////// PUBLIC /////////////////////////////////
  49. // Types
  50. // C'tors/D'tors
  51. MultiStringZ::MultiStringZ()
  52. : m_Buffer(),
  53. m_csBuffer()
  54. {}
  55. MultiStringZ::MultiStringZ(vector<ValueType> const &rvs)
  56. : m_Buffer(),
  57. m_csBuffer()
  58. {
  59. SizeType cLength = accumulate(rvs.begin(), rvs.end(), 0,
  60. LengthAccumulator);
  61. if (0 != cLength)
  62. {
  63. // +1 to account for the zero character ending the list
  64. m_Buffer.reserve(cLength + 1);
  65. m_Buffer = accumulate(rvs.begin(), rvs.end(), m_Buffer,
  66. StringAccumulator);
  67. m_Buffer.append(1, 0); // mark end of list
  68. }
  69. }
  70. MultiStringZ::MultiStringZ(vector<csValueType> const &rvs)
  71. : m_Buffer(),
  72. m_csBuffer()
  73. {
  74. csSizeType cLength = accumulate(rvs.begin(), rvs.end(), 0,
  75. csLengthAccumulator);
  76. if (0 != cLength)
  77. {
  78. m_csBuffer = accumulate(rvs.begin(), rvs.end(), m_csBuffer,
  79. csStringAccumulator);
  80. }
  81. }
  82. MultiStringZ::~MultiStringZ()
  83. {}
  84. // Operators
  85. // Operations
  86. // Access
  87. MultiStringZ::CharType const *
  88. MultiStringZ::Data() const
  89. {
  90. return m_Buffer.c_str(); // use 0 terminated version
  91. }
  92. MultiStringZ::SizeType
  93. MultiStringZ::Length() const
  94. {
  95. return m_Buffer.length();
  96. }
  97. LPCTSTR
  98. MultiStringZ::csData() const
  99. {
  100. return (LPCTSTR)m_csBuffer;
  101. }
  102. MultiStringZ::csSizeType
  103. MultiStringZ::csLength() const
  104. {
  105. return m_csBuffer.GetLength();
  106. }
  107. // Predicates
  108. // Static Variables
  109. /////////////////////////// PROTECTED /////////////////////////////////
  110. // C'tors/D'tors
  111. // Operators
  112. // Operations
  113. // Access
  114. // Predicates
  115. // Static Variables
  116. /////////////////////////// PRIVATE /////////////////////////////////
  117. // C'tors/D'tors
  118. // Operators
  119. // Operations
  120. // Access
  121. // Predicates
  122. // Static Variables