par_data.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
  29. nadgrids(std::initializer_list<std::string> l)
  30. : base_t(l)
  31. {}
  32. #endif
  33. nadgrids(std::string const& g0)
  34. : base_t(1)
  35. {
  36. base_t& d = *this;
  37. d[0] = g0;
  38. }
  39. nadgrids(std::string const& g0, std::string const& g1)
  40. : base_t(2)
  41. {
  42. base_t& d = *this;
  43. d[0] = g0; d[1] = g1;
  44. }
  45. nadgrids(std::string const& g0, std::string const& g1, std::string const& g2)
  46. : base_t(3)
  47. {
  48. base_t& d = *this;
  49. d[0] = g0; d[1] = g1; d[2] = g2;
  50. }
  51. nadgrids(std::string const& g0, std::string const& g1, std::string const& g2, std::string const& g3)
  52. : base_t(4)
  53. {
  54. base_t& d = *this;
  55. d[0] = g0; d[1] = g1; d[2] = g2; d[3] = g3;
  56. }
  57. nadgrids(std::string const& g0, std::string const& g1, std::string const& g2, std::string const& g3, std::string const& g4)
  58. : base_t(5)
  59. {
  60. base_t& d = *this;
  61. d[0] = g0; d[1] = g1; d[2] = g2; d[3] = g3; d[4] = g4;
  62. }
  63. };
  64. template <typename T = double>
  65. struct towgs84
  66. {
  67. static const std::size_t static_capacity = 7;
  68. typedef std::size_t size_type;
  69. typedef T value_type;
  70. typedef T* iterator;
  71. typedef const T* const_iterator;
  72. typedef T& reference;
  73. typedef const T& const_reference;
  74. towgs84()
  75. : m_size(0)
  76. #ifdef BOOST_GEOMETRY_CXX11_ARRAY_UNIFIED_INITIALIZATION
  77. , m_data{0, 0, 0, 0, 0, 0, 0}
  78. {}
  79. #else
  80. {
  81. std::fill(m_data, m_data + 7, T(0));
  82. }
  83. #endif
  84. template <typename It>
  85. towgs84(It first, It last)
  86. {
  87. assign(first, last);
  88. }
  89. #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
  90. towgs84(std::initializer_list<T> l)
  91. {
  92. assign(l.begin(), l.end());
  93. }
  94. #endif
  95. towgs84(T const& v0, T const& v1, T const& v2)
  96. : m_size(3)
  97. {
  98. m_data[0] = v0;
  99. m_data[1] = v1;
  100. m_data[2] = v2;
  101. }
  102. towgs84(T const& v0, T const& v1, T const& v2, T const& v3, T const& v4, T const& v5, T const& v6)
  103. : m_size(7)
  104. {
  105. m_data[0] = v0;
  106. m_data[1] = v1;
  107. m_data[2] = v2;
  108. m_data[3] = v3;
  109. m_data[4] = v4;
  110. m_data[5] = v5;
  111. m_data[6] = v6;
  112. }
  113. void push_back(T const& v)
  114. {
  115. BOOST_GEOMETRY_ASSERT(m_size < static_capacity);
  116. m_data[m_size] = v;
  117. ++m_size;
  118. }
  119. template <typename It>
  120. void assign(It first, It last)
  121. {
  122. for (m_size = 0 ; first != last && m_size < 7 ; ++first, ++m_size)
  123. m_data[m_size] = *first;
  124. }
  125. #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
  126. void assign(std::initializer_list<T> l)
  127. {
  128. assign(l.begin(), l.end());
  129. }
  130. #endif
  131. const_reference operator[](size_type i) const
  132. {
  133. BOOST_GEOMETRY_ASSERT(i < m_size);
  134. return m_data[i];
  135. }
  136. reference operator[](size_type i)
  137. {
  138. BOOST_GEOMETRY_ASSERT(i < m_size);
  139. return m_data[i];
  140. }
  141. size_type size() const
  142. {
  143. return m_size;
  144. }
  145. bool empty() const
  146. {
  147. return m_size == 0;
  148. }
  149. void clear()
  150. {
  151. m_size = 0;
  152. }
  153. iterator begin() { return m_data; }
  154. iterator end() { return m_data + m_size; }
  155. const_iterator begin() const { return m_data; }
  156. const_iterator end() const { return m_data + m_size; }
  157. private:
  158. size_type m_size;
  159. T m_data[7];
  160. };
  161. } // namespace detail
  162. #endif // DOXYGEN_NO_DETAIL
  163. }}} // namespace boost::geometry::srs
  164. #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_SPAR_HPP