[srs] Remove unneeded factory_key type.

This commit is contained in:
Adam Wulkiewicz 2019-09-01 18:41:20 +02:00
parent 8e9e163210
commit 4aecfdf3a9
3 changed files with 49 additions and 96 deletions

View File

@ -2,8 +2,8 @@
// Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2017.
// Modifications copyright (c) 2017, Oracle and/or its affiliates.
// This file was modified by Oracle on 2017, 2019.
// Modifications copyright (c) 2017, 2019, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
@ -19,7 +19,6 @@
#include <boost/shared_ptr.hpp>
#include <boost/geometry/srs/projections/dpar.hpp>
#include <boost/geometry/srs/projections/factory_key.hpp>
#include <boost/geometry/srs/projections/proj4.hpp>
#include <boost/geometry/srs/projections/impl/factory_entry.hpp>
#include <boost/geometry/srs/projections/proj/aea.hpp>
@ -127,6 +126,43 @@ namespace boost { namespace geometry { namespace projections
namespace detail
{
template <typename Params>
struct factory_key
{
BOOST_MPL_ASSERT_MSG((false), INVALID_PARAMETERS_TYPE, (Params));
};
template <>
struct factory_key<srs::detail::proj4_parameters>
{
typedef std::string type;
template <typename ProjParams>
static type const& get(ProjParams const& par)
{
return par.id.name;
}
static const char* get(const char* name, srs::dpar::value_proj id)
{
return name;
}
};
template <typename T>
struct factory_key<srs::dpar::parameters<T> >
{
typedef srs::dpar::value_proj type;
template <typename ProjParams>
static type const& get(ProjParams const& par)
{
return par.id.id;
}
static srs::dpar::value_proj get(const char* name, srs::dpar::value_proj id)
{
return id;
}
};
template <typename Params, typename CT, typename ProjParams>
class factory
{
@ -138,7 +174,8 @@ private:
ProjParams
> entry_base;
typedef typename factory_key_util<Params>::type key_type;
typedef factory_key<Params> key;
typedef typename key::type key_type;
typedef boost::shared_ptr<entry_base> entry_ptr;
typedef std::map<key_type, entry_ptr> entries_map;
@ -249,17 +286,17 @@ public:
detail::wink2_init(*this);
}
void add_to_factory(key_type const& key, entry_base* entry)
void add_to_factory(const char* name, srs::dpar::value_proj id, entry_base* entry)
{
// The pointer has to be owned before std::map::operator[] in case it thrown an exception.
entry_ptr ptr(entry);
m_entries[key] = ptr;
m_entries[key::get(name, id)] = ptr;
}
detail::base_v<CT, ProjParams>* create_new(Params const& params, ProjParams const& proj_par) const
{
typename factory_key_util<Params>::type key = factory_key_util<Params>::get(proj_par);
typename entries_map::const_iterator it = m_entries.find(key);
typedef typename entries_map::const_iterator const_iterator;
const_iterator it = m_entries.find(key::get(proj_par));
if (it != m_entries.end())
{
return it->second->create_new(params, proj_par);

View File

@ -1,83 +0,0 @@
// Boost.Geometry
// Copyright (c) 2018, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_PROJECTIONS_FACTORY_KEY_HPP
#define BOOST_GEOMETRY_PROJECTIONS_FACTORY_KEY_HPP
#include <string>
#include <boost/geometry/srs/projections/dpar.hpp>
#include <boost/geometry/srs/projections/proj4.hpp>
namespace boost { namespace geometry { namespace projections
{
namespace detail
{
template <typename Params>
struct factory_key_util
{
BOOST_MPL_ASSERT_MSG((false), INVALID_PARAMETERS_TYPE, (Params));
};
template <>
struct factory_key_util<srs::detail::proj4_parameters>
{
typedef std::string type;
template <typename ProjParams>
static type const& get(ProjParams const& par)
{
return par.id.name;
}
};
template <typename T>
struct factory_key_util<srs::dpar::parameters<T> >
{
typedef srs::dpar::value_proj type;
template <typename ProjParams>
static type const& get(ProjParams const& par)
{
return par.id.id;
}
};
struct factory_key
{
factory_key(const char* name, srs::dpar::value_proj id)
: m_name(name), m_id(id)
{}
operator const char*() const
{
return m_name;
}
operator std::string() const
{
return std::string(m_name);
}
operator srs::dpar::value_proj() const
{
return m_id;
}
private:
const char* m_name;
srs::dpar::value_proj m_id;
};
} // namespace detail
}}} // namespace boost::geometry::projections
#endif // BOOST_GEOMETRY_PROJECTIONS_FACTORY_KEY_HPP

View File

@ -2,8 +2,8 @@
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2017, 2018.
// Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
// This file was modified by Oracle on 2017, 2018, 2019.
// Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
@ -15,7 +15,6 @@
#include <string>
#include <boost/geometry/srs/projections/factory_key.hpp>
#include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
namespace boost { namespace geometry { namespace projections
@ -76,8 +75,8 @@ template <typename Params, typename T, typename Parameters> \
inline void FUN_NAME(projections::detail::factory<Params, T, Parameters>& factory)
#define BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(PROJ_NAME, ENTRY) \
factory.add_to_factory(projections::detail::factory_key(#PROJ_NAME, \
srs::dpar::proj_##PROJ_NAME), \
factory.add_to_factory(#PROJ_NAME, \
srs::dpar::proj_##PROJ_NAME, \
new ENTRY<Params, T, Parameters>);
} // namespace detail