oo_COPY.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* oo_COPY.h
  2. *
  3. * Copyright (C) 1994-2007,2009,2011-2018 Paul Boersma
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "oo_undef.h"
  19. #define oo_SIMPLE(type, storage, x) \
  20. thy x = our x;
  21. #define oo_SET(type, storage, x, setType) \
  22. for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  23. thy x [_i] = our x [_i]; \
  24. }
  25. #define oo_VECTOR(type, storage, x, min, max) \
  26. { \
  27. integer _min = (min), _max = (max); \
  28. if (our x) thy x = NUMvector_copy (our x, _min, _max); \
  29. }
  30. #define oo_ANYVEC(type, storage, x, sizeExpression) \
  31. thy x = vectorcopy (our x.get());
  32. #define oo_MATRIX(type, storage, x, row1, row2, col1, col2) \
  33. { \
  34. integer _row1 = (row1), _row2 = (row2), _col1 = (col1), _col2 = (col2); \
  35. if (our x) thy x = NUMmatrix_copy (our x, _row1, _row2, _col1, _col2); \
  36. }
  37. #define oo_ANYMAT(type, storage, x, nrowExpression, ncolExpression) \
  38. thy x = matrixcopy (our x.get());
  39. #define oo_ENUMx(kType, storage, x) \
  40. thy x = our x;
  41. //#define oo_ENUMx_SET(kType, storage, x, setType) \
  42. // for (int _i = 0; _i <= (int) setType::MAX; _i ++) thy x [_i] = our x [_i];
  43. //#define oo_ENUMx_VECTOR(kType, storage, x, min, max) \
  44. // { \
  45. // integer _min = (min), _max = (max); \
  46. // if (our x) thy x = NUMvector_copy (our x, _min, _max); \
  47. // }
  48. #define oo_STRINGx(storage, x) \
  49. if (our x) thy x = Melder_dup (our x.get());
  50. #define oo_STRINGx_SET(storage, x, setType) \
  51. for (int _i = 0; _i <= setType::MAX; _i ++) { \
  52. if (our x [_i]) thy x [_i] = Melder_dup (our x [_i].get()); \
  53. }
  54. #define oo_STRINGx_VECTOR(storage, x, n) \
  55. { \
  56. integer _size = (n); \
  57. Melder_assert (_size == our x.size); \
  58. if (our x) { \
  59. thy x = autostring32vector (_size); \
  60. for (integer _i = 1; _i <= _size; _i ++) { \
  61. if (our x [_i]) thy x [_i] = Melder_dup (our x [_i].get()); \
  62. } \
  63. } \
  64. }
  65. #define oo_STRUCT(Type, x) \
  66. our x. copy (& thy x);
  67. #define oo_STRUCT_SET(Type, x, setType) \
  68. for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  69. our x [_i]. copy (& thy x [_i]); \
  70. }
  71. #define oo_STRUCT_VECTOR_FROM(Type, x, min, max) \
  72. { \
  73. integer _min = (min), _max = (max); \
  74. if (our x) { \
  75. thy x = NUMvector <struct##Type> (_min, _max); \
  76. for (integer _i = _min; _i <= _max; _i ++) { \
  77. our x [_i]. copy (& thy x [_i]); \
  78. } \
  79. } \
  80. }
  81. #define oo_STRUCT_MATRIX_FROM(Type, x, row1, row2, col1, col2) \
  82. { \
  83. integer _row1 = (row1), _row2 = (row2), _col1 = (col1), _col2 = (col2); \
  84. if (our x) { \
  85. thy x = NUMmatrix <struct##Type> (_row1, _row2, _col1, _col2); \
  86. for (integer _irow = _row1; _irow <= _row2; _irow ++) { \
  87. for (integer _icol = _col1; _icol <= _col2; _icol ++) { \
  88. our x [_irow] [_icol]. copy (& thy x [_irow] [_icol]); \
  89. } \
  90. } \
  91. } \
  92. }
  93. #define oo_OBJECT(Class, version, x) \
  94. if (our x) thy x = Data_copy (our x.get());
  95. #define oo_COLLECTION_OF(Class, x, ItemClass, version) \
  96. if (our x._capacity > 0) { \
  97. thy x.at._elements = Melder_calloc (ItemClass, our x._capacity); \
  98. thy x.at._elements --; \
  99. } \
  100. thy x.size = our x.size; \
  101. thy x._capacity = our x._capacity; \
  102. thy x._ownItems = our x._ownItems; \
  103. thy x._ownershipInitialized = our x._ownershipInitialized; \
  104. for (integer _i = 1; _i <= our x.size; _i ++) { \
  105. if (our x.at [_i]) thy x.at [_i] = Data_copy (our x.at [_i]).releaseToAmbiguousOwner(); \
  106. }
  107. #define oo_COLLECTION(Class, x, ItemClass, version) \
  108. if (our x) thy x = Data_copy (our x.get());
  109. #define oo_FILE(x) \
  110. MelderFile_copy (& our x, & thy x);
  111. #define oo_DIR(x) \
  112. MelderDir_copy (& our x, & thy x);
  113. #define oo_DEFINE_STRUCT(Type) \
  114. void struct##Type :: copy (Type thee) {
  115. #define oo_END_STRUCT(Type) \
  116. }
  117. #define oo_DEFINE_CLASS(Class, Parent) \
  118. void struct##Class :: v_copy (Daata _thee_Daata) { \
  119. Class thee = static_cast <Class> (_thee_Daata); \
  120. Class##_Parent :: v_copy (thee);
  121. #define oo_END_CLASS(Class) \
  122. }
  123. #define oo_FROM(from)
  124. #define oo_ENDFROM
  125. #define oo_DECLARING 0
  126. #define oo_DESTROYING 0
  127. #define oo_COPYING 1
  128. #define oo_COMPARING 0
  129. #define oo_VALIDATING_ENCODING 0
  130. #define oo_READING 0
  131. #define oo_READING_TEXT 0
  132. #define oo_READING_BINARY 0
  133. #define oo_WRITING 0
  134. #define oo_WRITING_TEXT 0
  135. #define oo_WRITING_BINARY 0
  136. #define oo_DESCRIBING 0
  137. /* End of file oo_COPY.h */