factory.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017-2020.
  4. // Modifications copyright (c) 2017-2020, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_PROJECTIONS_FACTORY_HPP
  10. #define BOOST_GEOMETRY_PROJECTIONS_FACTORY_HPP
  11. #include <map>
  12. #include <string>
  13. #include <boost/shared_ptr.hpp>
  14. #include <boost/geometry/core/static_assert.hpp>
  15. #include <boost/geometry/srs/projections/dpar.hpp>
  16. #include <boost/geometry/srs/projections/proj4.hpp>
  17. #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
  18. #include <boost/geometry/srs/projections/proj/aea.hpp>
  19. #include <boost/geometry/srs/projections/proj/aeqd.hpp>
  20. #include <boost/geometry/srs/projections/proj/airy.hpp>
  21. #include <boost/geometry/srs/projections/proj/aitoff.hpp>
  22. #include <boost/geometry/srs/projections/proj/august.hpp>
  23. #include <boost/geometry/srs/projections/proj/bacon.hpp>
  24. #include <boost/geometry/srs/projections/proj/bipc.hpp>
  25. #include <boost/geometry/srs/projections/proj/boggs.hpp>
  26. #include <boost/geometry/srs/projections/proj/bonne.hpp>
  27. #include <boost/geometry/srs/projections/proj/cass.hpp>
  28. #include <boost/geometry/srs/projections/proj/cc.hpp>
  29. #include <boost/geometry/srs/projections/proj/cea.hpp>
  30. #include <boost/geometry/srs/projections/proj/chamb.hpp>
  31. #include <boost/geometry/srs/projections/proj/collg.hpp>
  32. #include <boost/geometry/srs/projections/proj/crast.hpp>
  33. #include <boost/geometry/srs/projections/proj/denoy.hpp>
  34. #include <boost/geometry/srs/projections/proj/eck1.hpp>
  35. #include <boost/geometry/srs/projections/proj/eck2.hpp>
  36. #include <boost/geometry/srs/projections/proj/eck3.hpp>
  37. #include <boost/geometry/srs/projections/proj/eck4.hpp>
  38. #include <boost/geometry/srs/projections/proj/eck5.hpp>
  39. #include <boost/geometry/srs/projections/proj/eqc.hpp>
  40. #include <boost/geometry/srs/projections/proj/eqdc.hpp>
  41. #include <boost/geometry/srs/projections/proj/etmerc.hpp>
  42. #include <boost/geometry/srs/projections/proj/fahey.hpp>
  43. #include <boost/geometry/srs/projections/proj/fouc_s.hpp>
  44. #include <boost/geometry/srs/projections/proj/gall.hpp>
  45. #include <boost/geometry/srs/projections/proj/geocent.hpp>
  46. #include <boost/geometry/srs/projections/proj/geos.hpp>
  47. #include <boost/geometry/srs/projections/proj/gins8.hpp>
  48. #include <boost/geometry/srs/projections/proj/gn_sinu.hpp>
  49. #include <boost/geometry/srs/projections/proj/gnom.hpp>
  50. #include <boost/geometry/srs/projections/proj/goode.hpp>
  51. #include <boost/geometry/srs/projections/proj/gstmerc.hpp>
  52. #include <boost/geometry/srs/projections/proj/hammer.hpp>
  53. #include <boost/geometry/srs/projections/proj/hatano.hpp>
  54. #include <boost/geometry/srs/projections/proj/healpix.hpp>
  55. #include <boost/geometry/srs/projections/proj/krovak.hpp>
  56. #include <boost/geometry/srs/projections/proj/igh.hpp>
  57. #include <boost/geometry/srs/projections/proj/imw_p.hpp>
  58. #include <boost/geometry/srs/projections/proj/isea.hpp>
  59. #include <boost/geometry/srs/projections/proj/laea.hpp>
  60. #include <boost/geometry/srs/projections/proj/labrd.hpp>
  61. #include <boost/geometry/srs/projections/proj/lagrng.hpp>
  62. #include <boost/geometry/srs/projections/proj/larr.hpp>
  63. #include <boost/geometry/srs/projections/proj/lask.hpp>
  64. #include <boost/geometry/srs/projections/proj/latlong.hpp>
  65. #include <boost/geometry/srs/projections/proj/lcc.hpp>
  66. #include <boost/geometry/srs/projections/proj/lcca.hpp>
  67. #include <boost/geometry/srs/projections/proj/loxim.hpp>
  68. #include <boost/geometry/srs/projections/proj/lsat.hpp>
  69. #include <boost/geometry/srs/projections/proj/mbtfpp.hpp>
  70. #include <boost/geometry/srs/projections/proj/mbtfpq.hpp>
  71. #include <boost/geometry/srs/projections/proj/mbt_fps.hpp>
  72. #include <boost/geometry/srs/projections/proj/merc.hpp>
  73. #include <boost/geometry/srs/projections/proj/mill.hpp>
  74. #include <boost/geometry/srs/projections/proj/mod_ster.hpp>
  75. #include <boost/geometry/srs/projections/proj/moll.hpp>
  76. #include <boost/geometry/srs/projections/proj/natearth.hpp>
  77. #include <boost/geometry/srs/projections/proj/nell.hpp>
  78. #include <boost/geometry/srs/projections/proj/nell_h.hpp>
  79. #include <boost/geometry/srs/projections/proj/nocol.hpp>
  80. #include <boost/geometry/srs/projections/proj/nsper.hpp>
  81. #include <boost/geometry/srs/projections/proj/nzmg.hpp>
  82. #include <boost/geometry/srs/projections/proj/ob_tran.hpp>
  83. #include <boost/geometry/srs/projections/proj/ocea.hpp>
  84. #include <boost/geometry/srs/projections/proj/oea.hpp>
  85. #include <boost/geometry/srs/projections/proj/omerc.hpp>
  86. #include <boost/geometry/srs/projections/proj/ortho.hpp>
  87. #include <boost/geometry/srs/projections/proj/qsc.hpp>
  88. #include <boost/geometry/srs/projections/proj/poly.hpp>
  89. #include <boost/geometry/srs/projections/proj/putp2.hpp>
  90. #include <boost/geometry/srs/projections/proj/putp3.hpp>
  91. #include <boost/geometry/srs/projections/proj/putp4p.hpp>
  92. #include <boost/geometry/srs/projections/proj/putp5.hpp>
  93. #include <boost/geometry/srs/projections/proj/putp6.hpp>
  94. #include <boost/geometry/srs/projections/proj/robin.hpp>
  95. #include <boost/geometry/srs/projections/proj/rouss.hpp>
  96. #include <boost/geometry/srs/projections/proj/rpoly.hpp>
  97. #include <boost/geometry/srs/projections/proj/sconics.hpp>
  98. #include <boost/geometry/srs/projections/proj/somerc.hpp>
  99. #include <boost/geometry/srs/projections/proj/stere.hpp>
  100. #include <boost/geometry/srs/projections/proj/sterea.hpp>
  101. #include <boost/geometry/srs/projections/proj/sts.hpp>
  102. #include <boost/geometry/srs/projections/proj/tcc.hpp>
  103. #include <boost/geometry/srs/projections/proj/tcea.hpp>
  104. #include <boost/geometry/srs/projections/proj/tmerc.hpp>
  105. #include <boost/geometry/srs/projections/proj/tpeqd.hpp>
  106. #include <boost/geometry/srs/projections/proj/urm5.hpp>
  107. #include <boost/geometry/srs/projections/proj/urmfps.hpp>
  108. #include <boost/geometry/srs/projections/proj/vandg.hpp>
  109. #include <boost/geometry/srs/projections/proj/vandg2.hpp>
  110. #include <boost/geometry/srs/projections/proj/vandg4.hpp>
  111. #include <boost/geometry/srs/projections/proj/wag2.hpp>
  112. #include <boost/geometry/srs/projections/proj/wag3.hpp>
  113. #include <boost/geometry/srs/projections/proj/wag7.hpp>
  114. #include <boost/geometry/srs/projections/proj/wink1.hpp>
  115. #include <boost/geometry/srs/projections/proj/wink2.hpp>
  116. namespace boost { namespace geometry { namespace projections
  117. {
  118. namespace detail
  119. {
  120. template <typename Params>
  121. struct factory_key
  122. {
  123. BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
  124. "Invalid parameters type.",
  125. Params);
  126. };
  127. template <>
  128. struct factory_key<srs::detail::proj4_parameters>
  129. {
  130. typedef std::string type;
  131. template <typename ProjParams>
  132. static type const& get(ProjParams const& par)
  133. {
  134. return par.id.name;
  135. }
  136. static const char* get(const char* name, srs::dpar::value_proj id)
  137. {
  138. return name;
  139. }
  140. };
  141. template <typename T>
  142. struct factory_key<srs::dpar::parameters<T> >
  143. {
  144. typedef srs::dpar::value_proj type;
  145. template <typename ProjParams>
  146. static type const& get(ProjParams const& par)
  147. {
  148. return par.id.id;
  149. }
  150. static srs::dpar::value_proj get(const char* name, srs::dpar::value_proj id)
  151. {
  152. return id;
  153. }
  154. };
  155. template <typename Params, typename CT, typename ProjParams>
  156. class factory
  157. {
  158. private:
  159. typedef detail::factory_entry
  160. <
  161. Params,
  162. CT,
  163. ProjParams
  164. > entry_base;
  165. typedef factory_key<Params> key;
  166. typedef typename key::type key_type;
  167. typedef boost::shared_ptr<entry_base> entry_ptr;
  168. typedef std::map<key_type, entry_ptr> entries_map;
  169. entries_map m_entries;
  170. public:
  171. factory()
  172. {
  173. detail::aea_init(*this);
  174. detail::aeqd_init(*this);
  175. detail::airy_init(*this);
  176. detail::aitoff_init(*this);
  177. detail::august_init(*this);
  178. detail::bacon_init(*this);
  179. detail::bipc_init(*this);
  180. detail::boggs_init(*this);
  181. detail::bonne_init(*this);
  182. detail::cass_init(*this);
  183. detail::cc_init(*this);
  184. detail::cea_init(*this);
  185. detail::chamb_init(*this);
  186. detail::collg_init(*this);
  187. detail::crast_init(*this);
  188. detail::denoy_init(*this);
  189. detail::eck1_init(*this);
  190. detail::eck2_init(*this);
  191. detail::eck3_init(*this);
  192. detail::eck4_init(*this);
  193. detail::eck5_init(*this);
  194. detail::eqc_init(*this);
  195. detail::eqdc_init(*this);
  196. detail::etmerc_init(*this);
  197. detail::fahey_init(*this);
  198. detail::fouc_s_init(*this);
  199. detail::gall_init(*this);
  200. detail::geocent_init(*this);
  201. detail::geos_init(*this);
  202. detail::gins8_init(*this);
  203. detail::gn_sinu_init(*this);
  204. detail::gnom_init(*this);
  205. detail::goode_init(*this);
  206. detail::gstmerc_init(*this);
  207. detail::hammer_init(*this);
  208. detail::hatano_init(*this);
  209. detail::healpix_init(*this);
  210. detail::krovak_init(*this);
  211. detail::igh_init(*this);
  212. detail::imw_p_init(*this);
  213. detail::isea_init(*this);
  214. detail::labrd_init(*this);
  215. detail::laea_init(*this);
  216. detail::lagrng_init(*this);
  217. detail::larr_init(*this);
  218. detail::lask_init(*this);
  219. detail::latlong_init(*this);
  220. detail::lcc_init(*this);
  221. detail::lcca_init(*this);
  222. detail::loxim_init(*this);
  223. detail::lsat_init(*this);
  224. detail::mbtfpp_init(*this);
  225. detail::mbtfpq_init(*this);
  226. detail::mbt_fps_init(*this);
  227. detail::merc_init(*this);
  228. detail::mill_init(*this);
  229. detail::mod_ster_init(*this);
  230. detail::moll_init(*this);
  231. detail::natearth_init(*this);
  232. detail::nell_init(*this);
  233. detail::nell_h_init(*this);
  234. detail::nocol_init(*this);
  235. detail::nsper_init(*this);
  236. detail::nzmg_init(*this);
  237. detail::ob_tran_init(*this);
  238. detail::ocea_init(*this);
  239. detail::oea_init(*this);
  240. detail::omerc_init(*this);
  241. detail::ortho_init(*this);
  242. detail::qsc_init(*this);
  243. detail::poly_init(*this);
  244. detail::putp2_init(*this);
  245. detail::putp3_init(*this);
  246. detail::putp4p_init(*this);
  247. detail::putp5_init(*this);
  248. detail::putp6_init(*this);
  249. detail::robin_init(*this);
  250. detail::rouss_init(*this);
  251. detail::rpoly_init(*this);
  252. detail::sconics_init(*this);
  253. detail::somerc_init(*this);
  254. detail::stere_init(*this);
  255. detail::sterea_init(*this);
  256. detail::sts_init(*this);
  257. detail::tcc_init(*this);
  258. detail::tcea_init(*this);
  259. detail::tmerc_init(*this);
  260. detail::tpeqd_init(*this);
  261. detail::urm5_init(*this);
  262. detail::urmfps_init(*this);
  263. detail::vandg_init(*this);
  264. detail::vandg2_init(*this);
  265. detail::vandg4_init(*this);
  266. detail::wag2_init(*this);
  267. detail::wag3_init(*this);
  268. detail::wag7_init(*this);
  269. detail::wink1_init(*this);
  270. detail::wink2_init(*this);
  271. }
  272. void add_to_factory(const char* name, srs::dpar::value_proj id, entry_base* entry)
  273. {
  274. // The pointer has to be owned before std::map::operator[] in case it thrown an exception.
  275. entry_ptr ptr(entry);
  276. m_entries[key::get(name, id)] = ptr;
  277. }
  278. detail::dynamic_wrapper_b<CT, ProjParams>* create_new(Params const& params, ProjParams const& proj_par) const
  279. {
  280. typedef typename entries_map::const_iterator const_iterator;
  281. const_iterator it = m_entries.find(key::get(proj_par));
  282. if (it != m_entries.end())
  283. {
  284. return it->second->create_new(params, proj_par);
  285. }
  286. return 0;
  287. }
  288. };
  289. template <typename T>
  290. inline detail::dynamic_wrapper_b<T, projections::parameters<T> >*
  291. create_new(srs::detail::proj4_parameters const& params,
  292. projections::parameters<T> const& parameters)
  293. {
  294. static factory<srs::detail::proj4_parameters, T, projections::parameters<T> > const fac;
  295. return fac.create_new(params, parameters);
  296. }
  297. template <typename T>
  298. inline detail::dynamic_wrapper_b<T, projections::parameters<T> >*
  299. create_new(srs::dpar::parameters<T> const& params,
  300. projections::parameters<T> const& parameters)
  301. {
  302. static factory<srs::dpar::parameters<T>, T, projections::parameters<T> > const fac;
  303. return fac.create_new(params, parameters);
  304. }
  305. } // namespace detail
  306. }}} // namespace boost::geometry::projections
  307. #endif // BOOST_GEOMETRY_PROJECTIONS_FACTORY_HPP