par_data.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // Boost.Geometry
  2. // Copyright (c) 2018, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_PAR_DATA_HPP
  8. #define BOOST_GEOMETRY_SRS_PROJECTIONS_PAR_DATA_HPP
  9. #include <string>
  10. #include <vector>
  11. #include <boost/geometry/core/assert.hpp>
  12. #include <boost/geometry/core/config.hpp>
  13. namespace boost { namespace geometry { namespace srs
  14. {
  15. #ifndef DOXYGEN_NO_DETAIL
  16. namespace detail
  17. {
  18. struct nadgrids
  19. : std::vector<std::string>
  20. {
  21. typedef std::vector<std::string> base_t;
  22. nadgrids()
  23. {}
  24. template <typename It>
  25. nadgrids(It first, It last)
  26. : base_t(first, last)
  27. {}
  28. nadgrids(std::initializer_list<std::string> l)
  29. : base_t(l)
  30. {}
  31. nadgrids(std::string const& g0)
  32. : base_t(1)
  33. {
  34. base_t& d = *this;
  35. d[0] = g0;
  36. }
  37. nadgrids(std::string const& g0, std::string const& g1)
  38. : base_t(2)
  39. {
  40. base_t& d = *this;
  41. d[0] = g0; d[1] = g1;
  42. }
  43. nadgrids(std::string const& g0, std::string const& g1, std::string const& g2)
  44. : base_t(3)
  45. {
  46. base_t& d = *this;
  47. d[0] = g0; d[1] = g1; d[2] = g2;
  48. }
  49. nadgrids(std::string const& g0, std::string const& g1, std::string const& g2, std::string const& g3)
  50. : base_t(4)
  51. {
  52. base_t& d = *this;
  53. d[0] = g0; d[1] = g1; d[2] = g2; d[3] = g3;
  54. }
  55. nadgrids(std::string const& g0, std::string const& g1, std::string const& g2, std::string const& g3, std::string const& g4)
  56. : base_t(5)
  57. {
  58. base_t& d = *this;
  59. d[0] = g0; d[1] = g1; d[2] = g2; d[3] = g3; d[4] = g4;
  60. }
  61. };
  62. template <typename T = double>
  63. struct towgs84
  64. {
  65. static const std::size_t static_capacity = 7;
  66. typedef std::size_t size_type;
  67. typedef T value_type;
  68. typedef T* iterator;
  69. typedef const T* const_iterator;
  70. typedef T& reference;
  71. typedef const T& const_reference;
  72. towgs84()
  73. : m_size(0)
  74. {
  75. std::fill(m_data, m_data + 7, T(0));
  76. }
  77. template <typename It>
  78. towgs84(It first, It last)
  79. {
  80. assign(first, last);
  81. }
  82. towgs84(std::initializer_list<T> l)
  83. {
  84. assign(l.begin(), l.end());
  85. }
  86. towgs84(T const& v0, T const& v1, T const& v2)
  87. : m_size(3)
  88. {
  89. m_data[0] = v0;
  90. m_data[1] = v1;
  91. m_data[2] = v2;
  92. }
  93. towgs84(T const& v0, T const& v1, T const& v2, T const& v3, T const& v4, T const& v5, T const& v6)
  94. : m_size(7)
  95. {
  96. m_data[0] = v0;
  97. m_data[1] = v1;
  98. m_data[2] = v2;
  99. m_data[3] = v3;
  100. m_data[4] = v4;
  101. m_data[5] = v5;
  102. m_data[6] = v6;
  103. }
  104. void push_back(T const& v)
  105. {
  106. BOOST_GEOMETRY_ASSERT(m_size < static_capacity);
  107. m_data[m_size] = v;
  108. ++m_size;
  109. }
  110. template <typename It>
  111. void assign(It first, It last)
  112. {
  113. for (m_size = 0 ; first != last && m_size < 7 ; ++first, ++m_size)
  114. m_data[m_size] = *first;
  115. }
  116. void assign(std::initializer_list<T> l)
  117. {
  118. assign(l.begin(), l.end());
  119. }
  120. const_reference operator[](size_type i) const
  121. {
  122. BOOST_GEOMETRY_ASSERT(i < m_size);
  123. return m_data[i];
  124. }
  125. reference operator[](size_type i)
  126. {
  127. BOOST_GEOMETRY_ASSERT(i < m_size);
  128. return m_data[i];
  129. }
  130. size_type size() const
  131. {
  132. return m_size;
  133. }
  134. bool empty() const
  135. {
  136. return m_size == 0;
  137. }
  138. void clear()
  139. {
  140. m_size = 0;
  141. }
  142. iterator begin() { return m_data; }
  143. iterator end() { return m_data + m_size; }
  144. const_iterator begin() const { return m_data; }
  145. const_iterator end() const { return m_data + m_size; }
  146. private:
  147. size_type m_size;
  148. T m_data[7];
  149. };
  150. struct axis
  151. {
  152. static const std::size_t static_capacity = 3;
  153. typedef std::size_t size_type;
  154. typedef int value_type;
  155. typedef int* iterator;
  156. typedef const int* const_iterator;
  157. typedef int& reference;
  158. typedef const int& const_reference;
  159. axis()
  160. : m_size(3)
  161. , m_data{0, 0, 0}
  162. {}
  163. template <typename It>
  164. axis(It first, It last)
  165. {
  166. assign(first, last);
  167. }
  168. axis(std::initializer_list<int> l)
  169. {
  170. assign(l.begin(), l.end());
  171. }
  172. axis(int const& v0, int const& v1, int const& v2)
  173. : m_size(3)
  174. {
  175. m_data[0] = v0;
  176. m_data[1] = v1;
  177. m_data[2] = v2;
  178. }
  179. void push_back(int const& v)
  180. {
  181. BOOST_GEOMETRY_ASSERT(m_size < static_capacity);
  182. m_data[m_size] = v;
  183. ++m_size;
  184. }
  185. template <typename It>
  186. void assign(It first, It last)
  187. {
  188. for (m_size = 0 ; first != last && m_size < 3 ; ++first, ++m_size)
  189. m_data[m_size] = *first;
  190. }
  191. void assign(std::initializer_list<int> l)
  192. {
  193. assign(l.begin(), l.end());
  194. }
  195. const_reference operator[](size_type i) const
  196. {
  197. BOOST_GEOMETRY_ASSERT(i < m_size);
  198. return m_data[i];
  199. }
  200. reference operator[](size_type i)
  201. {
  202. BOOST_GEOMETRY_ASSERT(i < m_size);
  203. return m_data[i];
  204. }
  205. size_type size() const
  206. {
  207. return m_size;
  208. }
  209. bool empty() const
  210. {
  211. return m_size == 0;
  212. }
  213. void clear()
  214. {
  215. m_size = 0;
  216. }
  217. iterator begin() { return m_data; }
  218. iterator end() { return m_data + m_size; }
  219. const_iterator begin() const { return m_data; }
  220. const_iterator end() const { return m_data + m_size; }
  221. private:
  222. size_type m_size;
  223. int m_data[3];
  224. };
  225. } // namespace detail
  226. #endif // DOXYGEN_NO_DETAIL
  227. }}} // namespace boost::geometry::srs
  228. #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_SPAR_HPP