variant_sequential_view.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /************************************************************************************
  2. * *
  3. * Copyright (c) 2014 - 2018 Axel Menzel <info@rttr.org> *
  4. * *
  5. * This file is part of RTTR (Run Time Type Reflection) *
  6. * License: MIT License *
  7. * *
  8. * Permission is hereby granted, free of charge, to any person obtaining *
  9. * a copy of this software and associated documentation files (the "Software"), *
  10. * to deal in the Software without restriction, including without limitation *
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  12. * and/or sell copies of the Software, and to permit persons to whom the *
  13. * Software is furnished to do so, subject to the following conditions: *
  14. * *
  15. * The above copyright notice and this permission notice shall be included in *
  16. * all copies or substantial portions of the Software. *
  17. * *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
  24. * SOFTWARE. *
  25. * *
  26. *************************************************************************************/
  27. #include "rttr/variant_sequential_view.h"
  28. #include "rttr/argument.h"
  29. #include "rttr/instance.h"
  30. using namespace std;
  31. namespace rttr
  32. {
  33. /////////////////////////////////////////////////////////////////////////////////
  34. variant_sequential_view::variant_sequential_view()
  35. {
  36. }
  37. /////////////////////////////////////////////////////////////////////////////////
  38. variant_sequential_view::variant_sequential_view(const variant_sequential_view& other)
  39. : m_view(other.m_view)
  40. {
  41. }
  42. /////////////////////////////////////////////////////////////////////////////////
  43. variant_sequential_view::~variant_sequential_view() RTTR_NOEXCEPT
  44. {
  45. }
  46. /////////////////////////////////////////////////////////////////////////////////
  47. void variant_sequential_view::swap(variant_sequential_view& other) RTTR_NOEXCEPT
  48. {
  49. std::swap(m_view, other.m_view);
  50. }
  51. /////////////////////////////////////////////////////////////////////////////////
  52. variant_sequential_view& variant_sequential_view::operator=(const variant_sequential_view& other) RTTR_NOEXCEPT
  53. {
  54. variant_sequential_view(other).swap(*this);
  55. return *this;
  56. }
  57. /////////////////////////////////////////////////////////////////////////////////////////
  58. bool variant_sequential_view::is_valid() const RTTR_NOEXCEPT
  59. {
  60. return m_view.get_type().is_valid();
  61. }
  62. /////////////////////////////////////////////////////////////////////////////////////////
  63. variant_sequential_view::operator bool() const RTTR_NOEXCEPT
  64. {
  65. return m_view.get_type().is_valid();
  66. }
  67. /////////////////////////////////////////////////////////////////////////////////////////
  68. type variant_sequential_view::get_type() const RTTR_NOEXCEPT
  69. {
  70. return m_view.get_type();
  71. }
  72. /////////////////////////////////////////////////////////////////////////////////////////
  73. type variant_sequential_view::get_value_type() const RTTR_NOEXCEPT
  74. {
  75. return m_view.get_value_type();
  76. }
  77. /////////////////////////////////////////////////////////////////////////////////////////
  78. bool variant_sequential_view::is_empty() const RTTR_NOEXCEPT
  79. {
  80. return m_view.is_empty();
  81. }
  82. /////////////////////////////////////////////////////////////////////////////////////////
  83. bool variant_sequential_view::is_dynamic() const RTTR_NOEXCEPT
  84. {
  85. return m_view.is_dynamic();
  86. }
  87. /////////////////////////////////////////////////////////////////////////////////////////
  88. std::size_t variant_sequential_view::get_rank() const RTTR_NOEXCEPT
  89. {
  90. return m_view.get_rank();
  91. }
  92. /////////////////////////////////////////////////////////////////////////////////////////
  93. type variant_sequential_view::get_rank_type(std::size_t index) const RTTR_NOEXCEPT
  94. {
  95. return m_view.get_rank_type(index);
  96. }
  97. /////////////////////////////////////////////////////////////////////////////////////////
  98. std::size_t variant_sequential_view::get_size() const RTTR_NOEXCEPT
  99. {
  100. return m_view.get_size();
  101. }
  102. /////////////////////////////////////////////////////////////////////////////////////////
  103. bool variant_sequential_view::set_size(std::size_t size) const RTTR_NOEXCEPT
  104. {
  105. return m_view.set_size(size);
  106. }
  107. /////////////////////////////////////////////////////////////////////////////////////////
  108. variant_sequential_view::const_iterator variant_sequential_view::insert(const const_iterator& pos, argument value)
  109. {
  110. const_iterator itr(&m_view);
  111. m_view.insert(pos.m_itr, value, itr.m_itr);
  112. return itr;
  113. }
  114. /////////////////////////////////////////////////////////////////////////////////////////
  115. variant_sequential_view::const_iterator variant_sequential_view::erase(const const_iterator& pos)
  116. {
  117. const_iterator itr(&m_view);
  118. m_view.erase(pos.m_itr, itr.m_itr);
  119. return itr;
  120. }
  121. /////////////////////////////////////////////////////////////////////////////////////////
  122. void variant_sequential_view::clear()
  123. {
  124. m_view.clear();
  125. }
  126. /////////////////////////////////////////////////////////////////////////////////////////
  127. bool variant_sequential_view::set_value(std::size_t index, argument arg)
  128. {
  129. return m_view.set_value(index, arg);
  130. }
  131. /////////////////////////////////////////////////////////////////////////////////////////
  132. variant variant_sequential_view::get_value(std::size_t index) const
  133. {
  134. return m_view.get_value(index);
  135. }
  136. /////////////////////////////////////////////////////////////////////////////////////////
  137. variant_sequential_view::const_iterator variant_sequential_view::begin() const
  138. {
  139. const_iterator itr(&m_view);
  140. m_view.begin(itr.m_itr);
  141. return itr;
  142. }
  143. /////////////////////////////////////////////////////////////////////////////////////////
  144. variant_sequential_view::const_iterator variant_sequential_view::end() const
  145. {
  146. const_iterator itr(&m_view);
  147. m_view.end(itr.m_itr);
  148. return itr;
  149. }
  150. /////////////////////////////////////////////////////////////////////////////////////////
  151. /////////////////////////////////////////////////////////////////////////////////////////
  152. /////////////////////////////////////////////////////////////////////////////////////////
  153. variant_sequential_view::const_iterator::const_iterator(const detail::variant_sequential_view_private* view) RTTR_NOEXCEPT
  154. : m_view(view)
  155. {
  156. }
  157. /////////////////////////////////////////////////////////////////////////////////////////
  158. variant_sequential_view::const_iterator::~const_iterator()
  159. {
  160. m_view->destroy(m_itr);
  161. }
  162. /////////////////////////////////////////////////////////////////////////////////////////
  163. variant_sequential_view::const_iterator::const_iterator(const const_iterator &other)
  164. : m_view(other.m_view),
  165. m_itr(other.m_itr)
  166. {
  167. m_view->copy(m_itr, other.m_itr);
  168. }
  169. /////////////////////////////////////////////////////////////////////////////////////////
  170. variant_sequential_view::const_iterator& variant_sequential_view::const_iterator::operator=(const_iterator other)
  171. {
  172. swap(other);
  173. return *this;
  174. }
  175. /////////////////////////////////////////////////////////////////////////////////////////
  176. void variant_sequential_view::const_iterator::swap(const_iterator& other)
  177. {
  178. std::swap(m_itr, other.m_itr);
  179. std::swap(m_view, other.m_view);
  180. }
  181. /////////////////////////////////////////////////////////////////////////////////////////
  182. const variant variant_sequential_view::const_iterator::operator*() const
  183. {
  184. return m_view->get_data(m_itr);
  185. }
  186. /////////////////////////////////////////////////////////////////////////////////////////
  187. const variant variant_sequential_view::const_iterator::get_data() const
  188. {
  189. return m_view->get_data(m_itr);
  190. }
  191. /////////////////////////////////////////////////////////////////////////////////////////
  192. variant_sequential_view::const_iterator& variant_sequential_view::const_iterator::operator++()
  193. {
  194. m_view->advance(m_itr, 1);
  195. return *this;
  196. }
  197. /////////////////////////////////////////////////////////////////////////////////////////
  198. variant_sequential_view::const_iterator variant_sequential_view::const_iterator::operator++(int)
  199. {
  200. const_iterator result(m_view);
  201. m_view->copy(result.m_itr, m_itr);
  202. m_view->advance(m_itr, 1);
  203. return result;
  204. }
  205. /////////////////////////////////////////////////////////////////////////////////////////
  206. variant_sequential_view::const_iterator& variant_sequential_view::const_iterator::operator--()
  207. {
  208. m_view->advance(m_itr, -1);
  209. return *this;
  210. }
  211. /////////////////////////////////////////////////////////////////////////////////////////
  212. variant_sequential_view::const_iterator variant_sequential_view::const_iterator::operator--(int)
  213. {
  214. const_iterator result(m_view);
  215. m_view->copy(result.m_itr, m_itr);
  216. m_view->advance(m_itr, -1);
  217. return result;
  218. }
  219. /////////////////////////////////////////////////////////////////////////////////////////
  220. variant_sequential_view::const_iterator& variant_sequential_view::const_iterator::operator+=(int i)
  221. {
  222. m_view->advance(m_itr, i);
  223. return *this;
  224. }
  225. /////////////////////////////////////////////////////////////////////////////////////////
  226. variant_sequential_view::const_iterator& variant_sequential_view::const_iterator::operator-=(int i)
  227. {
  228. m_view->advance(m_itr, -i);
  229. return *this;
  230. }
  231. /////////////////////////////////////////////////////////////////////////////////////////
  232. variant_sequential_view::const_iterator variant_sequential_view::const_iterator::operator+(int i) const
  233. {
  234. const_iterator result(m_view);
  235. m_view->copy(result.m_itr, m_itr);
  236. result.m_view->advance(result.m_itr, i);
  237. return result;
  238. }
  239. /////////////////////////////////////////////////////////////////////////////////////////
  240. variant_sequential_view::const_iterator variant_sequential_view::const_iterator::operator-(int i) const
  241. {
  242. const_iterator result(m_view);
  243. m_view->copy(result.m_itr, m_itr);
  244. result.m_view->advance(result.m_itr, -i);
  245. return result;
  246. }
  247. /////////////////////////////////////////////////////////////////////////////////////////
  248. bool variant_sequential_view::const_iterator::operator==(const const_iterator& other) const
  249. {
  250. return m_view->equal(m_itr, other.m_itr);
  251. }
  252. /////////////////////////////////////////////////////////////////////////////////////////
  253. bool variant_sequential_view::const_iterator::operator!=(const const_iterator& other) const
  254. {
  255. return !m_view->equal(m_itr, other.m_itr);
  256. }
  257. /////////////////////////////////////////////////////////////////////////////////////////
  258. } // end namespace rttr