RawArray.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #pragma once
  2. #include <algorithm>
  3. #include "ClassMacros.h"
  4. #include "CodeContract.h"
  5. #include "MiscMacros.h"
  6. namespace tecplot
  7. {
  8. template <typename T>
  9. class ___3269
  10. {
  11. public:
  12. void ___2319(char const *container, size_t numElements)
  13. {
  14. #ifdef LARGE_ARRAY_MEMORY_LOGGING
  15. size_t const MEMTRACK_CUTOFF = size_t(1000) * size_t(1000);
  16. if (numElements * sizeof(T) >= MEMTRACK_CUTOFF)
  17. {
  18. FILE *file = fopen("memtrack.txt", "at");
  19. if (file)
  20. {
  21. fprintf(file, "%s\t%"
  22. "I64u"
  23. "\t%"
  24. "I64u"
  25. "\t%s\n",
  26. container, numElements, sizeof(T), typeid(T).___2685());
  27. fclose(file);
  28. }
  29. else
  30. throw std::bad_alloc();
  31. }
  32. #else
  33. ___4278(container);
  34. ___4278(numElements);
  35. #endif
  36. }
  37. typedef T value_type;
  38. #if (defined _MSC_VER && __cplusplus >= 199711L) || __cplusplus >= 201103L
  39. ___3269(___3269 const &) = delete;
  40. ___3269 &operator=(___3269 const &) = delete;
  41. #if defined _MSC_VER && _MSC_VER <= 1800
  42. ___3269(___3269 &&___2888) : m_valuesRef(std::move(___2888.m_valuesRef)), ___2671(std::move(___2888.___2671)), m_capacity(std::move(___2888.m_capacity)), m_size(std::move(___2888.m_size))
  43. {
  44. }
  45. ___3269 &operator=(___3269 &&___3392)
  46. {
  47. if (this != &___3392)
  48. {
  49. m_valuesRef = std::move(___3392.m_valuesRef);
  50. ___2671 = std::move(___3392.___2671);
  51. m_capacity = std::move(___3392.m_capacity);
  52. m_size = std::move(___3392.m_size);
  53. }
  54. return *this;
  55. }
  56. #else
  57. ___3269(___3269 &&) = default;
  58. ___3269 &operator=(___3269 &&) = default;
  59. #endif
  60. #else
  61. private:
  62. ___3269(___3269 const &);
  63. ___3269 &operator=(___3269 const &);
  64. public:
  65. #endif
  66. inline ___3269() : m_valuesRef(NULL), ___2671(NULL), m_capacity(0), m_size(0)
  67. {
  68. }
  69. inline ___3269(T *const &values, size_t capacity, size_t size = 0) : m_valuesRef(NULL), ___2671(const_cast<T *>(values)), m_capacity(capacity), m_size(size)
  70. {
  71. REQUIRE(VALID_REF(this->___2671));
  72. REQUIRE(m_capacity != 0);
  73. REQUIRE(this->m_capacity >= this->m_size);
  74. }
  75. inline ___3269(T *&values, size_t capacity = 0, size_t size = 0) : m_valuesRef(&values), ___2671(values), m_capacity(capacity), m_size(size)
  76. {
  77. REQUIRE(VALID_REF(this->___2671) || this->___2671 == NULL);
  78. REQUIRE(EQUIVALENCE(this->___2671 == NULL, m_capacity == 0));
  79. REQUIRE(this->m_capacity >= this->m_size);
  80. }
  81. inline void nullify()
  82. {
  83. if (m_valuesRef != NULL)
  84. *m_valuesRef = NULL;
  85. m_valuesRef = NULL;
  86. ___2671 = NULL;
  87. m_capacity = 0;
  88. m_size = 0;
  89. }
  90. inline bool empty() const { return m_size == 0; }
  91. inline size_t size() const { return m_size; }
  92. inline void reserve(size_t size)
  93. {
  94. if (size > m_capacity)
  95. enlargeCapacity(size);
  96. }
  97. inline void ___3503(size_t size)
  98. {
  99. REQUIRE(size <= m_capacity);
  100. m_size = size;
  101. ENSURE(m_size <= m_capacity);
  102. }
  103. inline void clear() { m_size = 0; }
  104. inline size_t capacity() const { return m_capacity; }
  105. inline ___3269 &copy(___3269 const &___2888)
  106. {
  107. reserve(___2888.m_size);
  108. ___3503(___2888.m_size);
  109. for (size_t ___2865 = 0; ___2865 < m_size; ++___2865)
  110. ___2671[___2865] = ___2888.___2671[___2865];
  111. return *this;
  112. }
  113. inline ___3269 &append(___3269 const &___2888)
  114. {
  115. size_t const origSize = m_size;
  116. reserve(m_size + ___2888.m_size);
  117. ___3503(m_size + ___2888.m_size);
  118. for (size_t ___2865 = origSize; ___2865 < m_size; ++___2865)
  119. ___2671[___2865] = ___2888.___2671[___2865 - origSize];
  120. return *this;
  121. }
  122. inline void push_back(T const &___4314)
  123. {
  124. size_t const requestedCapacity = m_size + 1ul;
  125. if (requestedCapacity > m_capacity)
  126. {
  127. size_t const defaultCapacity = 32ul;
  128. size_t const blockSize = std::max(defaultCapacity, m_capacity / 2ul);
  129. size_t const adjustedRequest = ((requestedCapacity - 1ul) / blockSize + 1ul) * blockSize;
  130. ___478(adjustedRequest >= requestedCapacity);
  131. reserve(adjustedRequest);
  132. }
  133. size_t const valuePos = m_size;
  134. ___3503(m_size + 1ul);
  135. ___2671[valuePos] = ___4314;
  136. }
  137. inline ___3269 &append(T const &___4314)
  138. {
  139. push_back(___4314);
  140. return *this;
  141. }
  142. inline void copyTo(T *target)
  143. {
  144. for (size_t ___2865 = 0; ___2865 < m_size; ++___2865)
  145. target[___2865] = ___2671[___2865];
  146. }
  147. inline T &front()
  148. {
  149. REQUIRE(this->m_size != 0 || this->m_capacity != 0);
  150. return ___2671[0];
  151. }
  152. inline T const &front() const
  153. {
  154. REQUIRE(this->m_size != 0 || this->m_capacity != 0);
  155. return ___2671[0];
  156. }
  157. inline T &back()
  158. {
  159. REQUIRE(this->m_size != 0);
  160. return ___2671[m_size - 1];
  161. }
  162. inline T const &back() const
  163. {
  164. REQUIRE(this->m_size != 0);
  165. return ___2671[m_size - 1];
  166. }
  167. inline T &operator[](size_t ___2865)
  168. {
  169. REQUIRE(___2865 < this->m_size || (___2865 == 0 && this->m_capacity != 0));
  170. return ___2671[___2865];
  171. }
  172. inline T const &operator[](size_t ___2865) const
  173. {
  174. REQUIRE(___2865 < this->m_size || (___2865 == 0 && this->m_capacity != 0));
  175. return ___2671[___2865];
  176. }
  177. bool operator==(___3269<T> const &___3392) const
  178. {
  179. bool equal = m_size == ___3392.m_size;
  180. for (size_t ___2865 = 0; equal && ___2865 < m_size; ++___2865)
  181. equal = ___2671[___2865] == ___3392.___2671[___2865];
  182. return equal;
  183. }
  184. bool operator!=(___3269<T> const &___3392) const { return !(*this == ___3392); }
  185. inline bool ___2035() const { return (m_valuesRef == NULL || *m_valuesRef == NULL); }
  186. inline T *data() { return ___2671; }
  187. inline T const *data() const { return ___2671; }
  188. typedef T const *const_iterator;
  189. inline const_iterator begin() const { return ___2671; }
  190. inline const_iterator end() const { return ___2671 + m_size; }
  191. typedef T *iterator;
  192. inline iterator begin() { return ___2671; }
  193. inline iterator end() { return ___2671 + m_size; }
  194. private:
  195. inline void enlargeCapacity(size_t capacity)
  196. {
  197. REQUIRE(capacity > m_capacity);
  198. REQUIRE(m_valuesRef != NULL);
  199. ___2319("RawArray", capacity);
  200. T *values = new T[capacity];
  201. if (m_size != 0)
  202. std::copy(___2671, ___2671 + m_size, values);
  203. delete[] ___2671;
  204. *m_valuesRef = values;
  205. ___2671 = values;
  206. m_capacity = capacity;
  207. }
  208. T **m_valuesRef;
  209. T *___2671;
  210. size_t m_capacity;
  211. size_t m_size;
  212. };
  213. }