Skip to content

Commit 1bc9a24

Browse files
authored
refactor(autoware_geography_utils): rewrite using modern C++ without API breakage (#345)
* refactor using modern c++ Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp> * precommit Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp> * revert Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp> * remove nodiscard Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp> * precommit Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp> --------- Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
1 parent 21a408c commit 1bc9a24

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

Diff for: common/autoware_geography_utils/include/autoware/geography_utils/height.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
#ifndef AUTOWARE__GEOGRAPHY_UTILS__HEIGHT_HPP_
1616
#define AUTOWARE__GEOGRAPHY_UTILS__HEIGHT_HPP_
1717

18+
#include <functional>
1819
#include <string>
20+
#include <string_view>
1921

2022
namespace autoware::geography_utils
2123
{
22-
23-
using HeightConversionFunction =
24-
double (*)(const double height, const double latitude, const double longitude);
24+
using HeightConversionFunction = std::function<double(double, double, double)>;
2525

2626
double convert_wgs84_to_egm2008(const double height, const double latitude, const double longitude);
2727
double convert_egm2008_to_wgs84(const double height, const double latitude, const double longitude);
2828
double convert_height(
2929
const double height, const double latitude, const double longitude,
30-
const std::string & source_vertical_datum, const std::string & target_vertical_datum);
30+
std::string_view source_vertical_datum, std::string_view target_vertical_datum);
3131

3232
} // namespace autoware::geography_utils
3333

Diff for: common/autoware_geography_utils/src/height.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "autoware/geography_utils/height.hpp"
16+
1517
#include <GeographicLib/Geoid.hpp>
16-
#include <autoware/geography_utils/height.hpp>
1718

1819
#include <map>
1920
#include <stdexcept>
2021
#include <string>
22+
#include <string_view>
2123
#include <utility>
2224

2325
namespace autoware::geography_utils
@@ -39,12 +41,12 @@ double convert_egm2008_to_wgs84(const double height, const double latitude, cons
3941

4042
double convert_height(
4143
const double height, const double latitude, const double longitude,
42-
const std::string & source_vertical_datum, const std::string & target_vertical_datum)
44+
std::string_view source_vertical_datum, std::string_view target_vertical_datum)
4345
{
4446
if (source_vertical_datum == target_vertical_datum) {
4547
return height;
4648
}
47-
static const std::map<std::pair<std::string, std::string>, HeightConversionFunction>
49+
static const std::map<std::pair<std::string_view, std::string_view>, HeightConversionFunction>
4850
conversion_map{
4951
{{"WGS84", "EGM2008"}, convert_wgs84_to_egm2008},
5052
{{"EGM2008", "WGS84"}, convert_egm2008_to_wgs84},
@@ -55,8 +57,10 @@ double convert_height(
5557
return it->second(height, latitude, longitude);
5658
}
5759

58-
throw std::invalid_argument(
59-
"Invalid conversion types: " + source_vertical_datum + " to " + target_vertical_datum);
60+
throw std::invalid_argument(std::string{"Invalid conversion types: "}
61+
.append(source_vertical_datum)
62+
.append(" to ")
63+
.append(target_vertical_datum));
6064
}
6165

6266
} // namespace autoware::geography_utils

Diff for: common/autoware_geography_utils/src/lanelet2_projector.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ std::unique_ptr<lanelet::Projector> get_lanelet2_projector(const MapProjectorInf
6161
return std::make_unique<lanelet::projection::LocalCartesianProjector>(projector);
6262
}
6363

64-
throw std::invalid_argument(
65-
"Invalid map projector type: " + projector_info.projector_type +
66-
". Currently supported types: MGRS, LocalCartesianUTM, LocalCartesian and TransverseMercator");
64+
throw std::invalid_argument(std::string{"Invalid map projector type: "}
65+
.append(projector_info.projector_type)
66+
.append(". Currently supported types: MGRS, LocalCartesianUTM, "
67+
"LocalCartesian and TransverseMercator"));
6768
}
6869

6970
} // namespace autoware::geography_utils

0 commit comments

Comments
 (0)