CszConnectivity.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #pragma once
  2. #include "basicTypes.h"
  3. #include "ClassMacros.h"
  4. #include "ItemAddress.h"
  5. #include "RawArray.h"
  6. #include "showMessage.h"
  7. #include "StandardIntegralTypes.h"
  8. namespace tecplot
  9. {
  10. namespace ___3933
  11. {
  12. class CszConnectivity
  13. {
  14. UNCOPYABLE_CLASS(CszConnectivity);
  15. public:
  16. typedef uint16_t EntryIndex_t;
  17. CszConnectivity() : m_ptr(NULL) {}
  18. ~CszConnectivity() { ___937(); }
  19. static size_t bytesRequired(uint32_t ___2795, uint32_t numRefNszs);
  20. bool empty() const { return m_ptr == NULL; }
  21. bool alloc(uint32_t ___2795, uint32_t numRefNszs);
  22. size_t numBytesAllocated(void) const;
  23. void ___937();
  24. uint32_t getNumEntries() const;
  25. uint32_t getNumRefNszs() const;
  26. uint8_t *getItemOffsetArray();
  27. uint8_t const *getItemOffsetArray() const;
  28. uint16_t *getRszOffsetArray();
  29. uint16_t const *getRszOffsetArray() const;
  30. ___2090::SubzoneAddress *getRefNszArray();
  31. ___2090::SubzoneAddress const *getRefNszArray() const;
  32. bool getRszAddresses(___3269<___2090::SubzoneAddress> &rszAddresses) const;
  33. ___2090::SubzoneAddress getRszAddress(RefSubzoneOffset_t rszOffset) const;
  34. RefSubzoneOffset_t getRszOffset(EntryIndex_t entry) const;
  35. uint8_t getNodeOffset(EntryIndex_t entry) const;
  36. ___2090 getNodeAddress(EntryIndex_t entry) const;
  37. private:
  38. uint8_t *m_ptr;
  39. static uint16_t const MAX_NUM_ENTRIES = 2048;
  40. static size_t const POS_NUMENTRIES = 0;
  41. static size_t const POS_NUMREFNSZS = POS_NUMENTRIES + sizeof(uint32_t);
  42. static size_t const POS_OFFSETARRAY = POS_NUMREFNSZS + sizeof(uint32_t);
  43. static size_t const POS_RSZINDEXARRAY = POS_OFFSETARRAY + MAX_NUM_ENTRIES * sizeof(uint8_t);
  44. static size_t const POS_REFNSZARRAY = POS_RSZINDEXARRAY + MAX_NUM_ENTRIES * sizeof(uint16_t);
  45. };
  46. inline size_t CszConnectivity::bytesRequired(uint32_t ___2795, uint32_t numRefNszs)
  47. {
  48. ___4278(___2795);
  49. size_t const bytes = POS_REFNSZARRAY + numRefNszs * sizeof(uint64_t);
  50. return bytes;
  51. }
  52. inline bool CszConnectivity::alloc(uint32_t ___2795, uint32_t numRefNszs)
  53. {
  54. REQUIRE(empty());
  55. REQUIRE(___2795 > 0 && ___2795 <= MAX_NUM_ENTRIES);
  56. REQUIRE(numRefNszs > 0 && numRefNszs <= ___2795);
  57. size_t const bytes = bytesRequired(___2795, numRefNszs);
  58. m_ptr = (uint8_t *)malloc(bytes);
  59. if (m_ptr)
  60. {
  61. *((uint32_t *)(m_ptr + POS_NUMENTRIES)) = ___2795;
  62. *((uint32_t *)(m_ptr + POS_NUMREFNSZS)) = numRefNszs;
  63. }
  64. return m_ptr != NULL;
  65. }
  66. inline size_t CszConnectivity::numBytesAllocated(void) const
  67. {
  68. if (empty())
  69. return 0;
  70. else
  71. {
  72. uint32_t const ___2795 = getNumEntries();
  73. uint32_t const numRefNszs = getNumRefNszs();
  74. size_t const bytes = bytesRequired(___2795, numRefNszs);
  75. return bytes;
  76. }
  77. }
  78. inline void CszConnectivity::___937()
  79. {
  80. if (!empty())
  81. {
  82. free(m_ptr);
  83. m_ptr = 0;
  84. }
  85. ENSURE(empty());
  86. }
  87. inline uint32_t CszConnectivity::getNumEntries() const
  88. {
  89. REQUIRE(!empty());
  90. uint32_t const ___2795 = *((uint32_t *)(m_ptr + POS_NUMENTRIES));
  91. ENSURE(___2795 > 0 && ___2795 <= MAX_NUM_ENTRIES);
  92. return ___2795;
  93. }
  94. inline uint32_t CszConnectivity::getNumRefNszs() const
  95. {
  96. REQUIRE(!empty());
  97. uint32_t const numRefNszs = *((uint32_t *)(m_ptr + POS_NUMREFNSZS));
  98. ENSURE(numRefNszs > 0 && numRefNszs <= getNumEntries());
  99. return numRefNszs;
  100. }
  101. inline uint8_t *CszConnectivity::getItemOffsetArray()
  102. {
  103. REQUIRE(!empty());
  104. return ((uint8_t *)(m_ptr + POS_OFFSETARRAY));
  105. }
  106. inline uint8_t const *CszConnectivity::getItemOffsetArray() const
  107. {
  108. REQUIRE(!empty());
  109. return ((uint8_t *)(m_ptr + POS_OFFSETARRAY));
  110. }
  111. inline uint16_t *CszConnectivity::getRszOffsetArray()
  112. {
  113. REQUIRE(!empty());
  114. return ((uint16_t *)(m_ptr + POS_RSZINDEXARRAY));
  115. }
  116. inline uint16_t const *CszConnectivity::getRszOffsetArray() const
  117. {
  118. REQUIRE(!empty());
  119. return ((uint16_t *)(m_ptr + POS_RSZINDEXARRAY));
  120. }
  121. inline ___2090::SubzoneAddress *CszConnectivity::getRefNszArray()
  122. {
  123. REQUIRE(!empty());
  124. INVARIANT(sizeof(___2090::SubzoneAddress) == sizeof(uint64_t));
  125. return ((___2090::SubzoneAddress *)(m_ptr + POS_REFNSZARRAY));
  126. }
  127. inline ___2090::SubzoneAddress const *CszConnectivity::getRefNszArray() const
  128. {
  129. REQUIRE(!empty());
  130. INVARIANT(sizeof(___2090::SubzoneAddress) == sizeof(uint64_t));
  131. return ((___2090::SubzoneAddress *)(m_ptr + POS_REFNSZARRAY));
  132. }
  133. inline bool CszConnectivity::getRszAddresses(___3269<___2090::SubzoneAddress> &rszAddresses) const
  134. {
  135. REQUIRE(!empty());
  136. REQUIRE(rszAddresses.empty());
  137. bool ___2039 = ___4226;
  138. try
  139. {
  140. uint32_t const numRefNszs = getNumRefNszs();
  141. ___478(numRefNszs > 0);
  142. rszAddresses.reserve(numRefNszs);
  143. rszAddresses.___3503(numRefNszs);
  144. ___2090::SubzoneAddress const *refNszArray = getRefNszArray();
  145. memcpy(&rszAddresses[0], refNszArray, numRefNszs * sizeof(___2090::SubzoneAddress));
  146. }
  147. catch (std::bad_alloc const &)
  148. {
  149. ___2039 = ___1186("Out of memory getRszAddresses");
  150. }
  151. return ___2039;
  152. }
  153. inline ___2090::SubzoneAddress CszConnectivity::getRszAddress(RefSubzoneOffset_t rszOffset) const
  154. {
  155. REQUIRE(!empty());
  156. REQUIRE(rszOffset < getNumRefNszs());
  157. ___2090::SubzoneAddress const *refNszArray = getRefNszArray();
  158. ___2090::SubzoneAddress const ___2757 = refNszArray[rszOffset];
  159. return ___2757;
  160. }
  161. inline RefSubzoneOffset_t CszConnectivity::getRszOffset(EntryIndex_t entry) const
  162. {
  163. REQUIRE(!empty());
  164. REQUIRE(entry < getNumEntries());
  165. uint16_t const *rszOffsetArray = getRszOffsetArray();
  166. uint16_t const rszOffset = rszOffsetArray[entry];
  167. ENSURE(rszOffset < getNumRefNszs());
  168. return rszOffset;
  169. }
  170. inline uint8_t CszConnectivity::getNodeOffset(EntryIndex_t entry) const
  171. {
  172. REQUIRE(!empty());
  173. REQUIRE(entry < getNumEntries());
  174. uint8_t const *itemOffsetArray = getItemOffsetArray();
  175. uint8_t const itemOffset = itemOffsetArray[entry];
  176. return itemOffset;
  177. }
  178. inline ___2090 CszConnectivity::getNodeAddress(EntryIndex_t entry) const
  179. {
  180. REQUIRE(!empty());
  181. REQUIRE(entry < getNumEntries());
  182. uint8_t const itemOffset = getNodeOffset(entry);
  183. uint16_t const rszOffset = getRszOffset(entry);
  184. ___2090::SubzoneAddress const nszAddress = getRszAddress(rszOffset);
  185. return ___2090(nszAddress, itemOffset);
  186. }
  187. }
  188. }