Skip to content

Commit

Permalink
Merge pull request #4375 from rouault/make_unique
Browse files Browse the repository at this point in the history
Use std::make_unique<> instead of internal::make_unique<>
  • Loading branch information
rouault authored Jan 11, 2025
2 parents f30c6a4 + 53ed2e0 commit 6754b7c
Show file tree
Hide file tree
Showing 22 changed files with 788 additions and 313 deletions.
6 changes: 0 additions & 6 deletions include/proj/internal/internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ template <typename To, typename From> inline To down_cast(From *f) {
return static_cast<To>(f);
}

/* Borrowed from C++14 */
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Args &&...args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

PROJ_FOR_TEST std::string replaceAll(const std::string &str,
const std::string &before,
const std::string &after);
Expand Down
18 changes: 8 additions & 10 deletions src/filemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1985,12 +1985,11 @@ void pj_load_ini(PJ_CONTEXT *ctx) {
}

const char *native_ca = getenv("PROJ_NATIVE_CA");
if (native_ca && native_ca[0] != '\0'){
if (native_ca && native_ca[0] != '\0') {
ctx->native_ca = ci_equal(native_ca, "ON") ||
ci_equal(native_ca, "YES") ||
ci_equal(native_ca, "TRUE");
}
else {
ci_equal(native_ca, "YES") ||
ci_equal(native_ca, "TRUE");
} else {
native_ca = nullptr;
}

Expand Down Expand Up @@ -2059,11 +2058,10 @@ void pj_load_ini(PJ_CONTEXT *ctx) {
ctx->errorIfBestTransformationNotAvailableDefault =
ci_equal(value, "ON") || ci_equal(value, "YES") ||
ci_equal(value, "TRUE");
}
else if (native_ca == nullptr && key == "native_ca"){
ctx->native_ca =
ci_equal(value, "ON") || ci_equal(value, "YES") ||
ci_equal(value, "TRUE");
} else if (native_ca == nullptr && key == "native_ca") {
ctx->native_ca = ci_equal(value, "ON") ||
ci_equal(value, "YES") ||
ci_equal(value, "TRUE");
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/grids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ GTXVerticalShiftGrid *GTXVerticalShiftGrid::open(PJ_CONTEXT *ctx,

// Cache up to 1 megapixel per GTX file
const int maxLinesInCache = 1024 * 1024 / columns;
auto cache = internal::make_unique<FloatLineCache>(maxLinesInCache);
auto cache = std::make_unique<FloatLineCache>(maxLinesInCache);
return new GTXVerticalShiftGrid(ctx, std::move(fp), name, columns, rows,
extent, std::move(cache));
}
Expand Down Expand Up @@ -1588,8 +1588,7 @@ GTiffVGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
const std::string &gridName = grid->metadataItem("grid_name");
const std::string &parentName = grid->metadataItem("parent_grid_name");

auto vgrid =
internal::make_unique<GTiffVGrid>(std::move(grid), idxSample);
auto vgrid = std::make_unique<GTiffVGrid>(std::move(grid), idxSample);

insertIntoHierarchy(ctx, std::move(vgrid), gridName, parentName,
set->m_grids, mapGrids);
Expand Down Expand Up @@ -2324,7 +2323,7 @@ std::unique_ptr<NTv2GridSet> NTv2GridSet::open(PJ_CONTEXT *ctx,

// Cache up to 1 megapixel per NTv2 file
const int maxLinesInCache = 1024 * 1024 / largestLine;
set->m_cache = internal::make_unique<FloatLineCache>(maxLinesInCache);
set->m_cache = std::make_unique<FloatLineCache>(maxLinesInCache);
for (const auto &kv : mapGrids) {
kv.second->setCache(set->m_cache.get());
}
Expand Down Expand Up @@ -2633,7 +2632,7 @@ GTiffHGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
const std::string &gridName = grid->metadataItem("grid_name");
const std::string &parentName = grid->metadataItem("parent_grid_name");

auto hgrid = internal::make_unique<GTiffHGrid>(
auto hgrid = std::make_unique<GTiffHGrid>(
std::move(grid), idxLatShift, idxLongShift, convFactorToRadian,
positiveEast);

Expand Down Expand Up @@ -3030,7 +3029,7 @@ GTiffGenericGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
const std::string &gridName = grid->metadataItem("grid_name");
const std::string &parentName = grid->metadataItem("parent_grid_name");

auto ggrid = internal::make_unique<GTiffGenericGrid>(std::move(grid));
auto ggrid = std::make_unique<GTiffGenericGrid>(std::move(grid));
if (!set->m_grids.empty() && ggrid->metadataItem("TYPE").empty() &&
!set->m_grids[0]->metadataItem("TYPE").empty()) {
ggrid->setFirstGrid(set->m_grids[0].get());
Expand Down
2 changes: 1 addition & 1 deletion src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2751,7 +2751,7 @@ PJ_OBJ_LIST *proj_identify(PJ_CONTEXT *ctx, const PJ *obj,
++i;
}
}
auto ret = internal::make_unique<PJ_OBJ_LIST>(std::move(objects));
auto ret = std::make_unique<PJ_OBJ_LIST>(std::move(objects));
if (out_confidence) {
*out_confidence = confidenceTemp;
confidenceTemp = nullptr;
Expand Down
34 changes: 17 additions & 17 deletions src/iso19111/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ UnitOfMeasure::UnitOfMeasure(const std::string &nameIn, double toSIIn,
UnitOfMeasure::Type typeIn,
const std::string &codeSpaceIn,
const std::string &codeIn)
: d(internal::make_unique<Private>(nameIn, toSIIn, typeIn, codeSpaceIn,
codeIn)) {}
: d(std::make_unique<Private>(nameIn, toSIIn, typeIn, codeSpaceIn,
codeIn)) {}

// ---------------------------------------------------------------------------

UnitOfMeasure::UnitOfMeasure(const UnitOfMeasure &other)
: d(internal::make_unique<Private>(*(other.d))) {}
: d(std::make_unique<Private>(*(other.d))) {}

// ---------------------------------------------------------------------------

Expand Down Expand Up @@ -376,12 +376,12 @@ struct Measure::Private {
/** \brief Instantiate a Measure.
*/
Measure::Measure(double valueIn, const UnitOfMeasure &unitIn)
: d(internal::make_unique<Private>(valueIn, unitIn)) {}
: d(std::make_unique<Private>(valueIn, unitIn)) {}

// ---------------------------------------------------------------------------

Measure::Measure(const Measure &other)
: d(internal::make_unique<Private>(*(other.d))) {}
: d(std::make_unique<Private>(*(other.d))) {}

// ---------------------------------------------------------------------------

Expand Down Expand Up @@ -555,18 +555,18 @@ struct DateTime::Private {

// ---------------------------------------------------------------------------

DateTime::DateTime() : d(internal::make_unique<Private>(std::string())) {}
DateTime::DateTime() : d(std::make_unique<Private>(std::string())) {}

// ---------------------------------------------------------------------------

DateTime::DateTime(const std::string &str)
: d(internal::make_unique<Private>(str)) {}
: d(std::make_unique<Private>(str)) {}

// ---------------------------------------------------------------------------

//! @cond Doxygen_Suppress
DateTime::DateTime(const DateTime &other)
: d(internal::make_unique<Private>(*(other.d))) {}
: d(std::make_unique<Private>(*(other.d))) {}
//! @endcond

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -626,12 +626,12 @@ struct IdentifiedObject::Private {

// ---------------------------------------------------------------------------

IdentifiedObject::IdentifiedObject() : d(internal::make_unique<Private>()) {}
IdentifiedObject::IdentifiedObject() : d(std::make_unique<Private>()) {}

// ---------------------------------------------------------------------------

IdentifiedObject::IdentifiedObject(const IdentifiedObject &other)
: d(internal::make_unique<Private>(*(other.d))) {}
: d(std::make_unique<Private>(*(other.d))) {}

// ---------------------------------------------------------------------------

Expand Down Expand Up @@ -975,13 +975,13 @@ struct ObjectDomain::Private {
//! @cond Doxygen_Suppress
ObjectDomain::ObjectDomain(const optional<std::string> &scopeIn,
const ExtentPtr &extent)
: d(internal::make_unique<Private>(scopeIn, extent)) {}
: d(std::make_unique<Private>(scopeIn, extent)) {}
//! @endcond

// ---------------------------------------------------------------------------

ObjectDomain::ObjectDomain(const ObjectDomain &other)
: d(internal::make_unique<Private>(*(other.d))) {}
: d(std::make_unique<Private>(*(other.d))) {}

// ---------------------------------------------------------------------------

Expand Down Expand Up @@ -1167,12 +1167,12 @@ struct ObjectUsage::Private {

// ---------------------------------------------------------------------------

ObjectUsage::ObjectUsage() : d(internal::make_unique<Private>()) {}
ObjectUsage::ObjectUsage() : d(std::make_unique<Private>()) {}

// ---------------------------------------------------------------------------

ObjectUsage::ObjectUsage(const ObjectUsage &other)
: IdentifiedObject(other), d(internal::make_unique<Private>(*(other.d))) {}
: IdentifiedObject(other), d(std::make_unique<Private>(*(other.d))) {}

// ---------------------------------------------------------------------------

Expand Down Expand Up @@ -1320,17 +1320,17 @@ struct DataEpoch::Private {

// ---------------------------------------------------------------------------

DataEpoch::DataEpoch() : d(internal::make_unique<Private>(Measure())) {}
DataEpoch::DataEpoch() : d(std::make_unique<Private>(Measure())) {}

// ---------------------------------------------------------------------------

DataEpoch::DataEpoch(const Measure &coordinateEpochIn)
: d(internal::make_unique<Private>(coordinateEpochIn)) {}
: d(std::make_unique<Private>(coordinateEpochIn)) {}

// ---------------------------------------------------------------------------

DataEpoch::DataEpoch(const DataEpoch &other)
: d(internal::make_unique<Private>(*(other.d))) {}
: d(std::make_unique<Private>(*(other.d))) {}

// ---------------------------------------------------------------------------

Expand Down
9 changes: 4 additions & 5 deletions src/iso19111/coordinates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,15 @@ struct CoordinateMetadata::Private {
// ---------------------------------------------------------------------------

CoordinateMetadata::CoordinateMetadata(const crs::CRSNNPtr &crsIn)
: d(internal::make_unique<Private>(crsIn)) {}
: d(std::make_unique<Private>(crsIn)) {}

// ---------------------------------------------------------------------------

CoordinateMetadata::CoordinateMetadata(const crs::CRSNNPtr &crsIn,
double coordinateEpochAsDecimalYearIn)
: d(internal::make_unique<Private>(
crsIn,
common::DataEpoch(common::Measure(coordinateEpochAsDecimalYearIn,
common::UnitOfMeasure::YEAR)))) {}
: d(std::make_unique<Private>(crsIn, common::DataEpoch(common::Measure(
coordinateEpochAsDecimalYearIn,
common::UnitOfMeasure::YEAR)))) {}

// ---------------------------------------------------------------------------

Expand Down
13 changes: 6 additions & 7 deletions src/iso19111/coordinatesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ struct Meridian::Private {
// ---------------------------------------------------------------------------

Meridian::Meridian(const common::Angle &longitudeIn)
: d(internal::make_unique<Private>(longitudeIn)) {}
: d(std::make_unique<Private>(longitudeIn)) {}

// ---------------------------------------------------------------------------

#ifdef notdef
Meridian::Meridian(const Meridian &other)
: IdentifiedObject(other), d(internal::make_unique<Private>(*other.d)) {}
: IdentifiedObject(other), d(std::make_unique<Private>(*other.d)) {}
#endif

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -182,14 +182,13 @@ struct CoordinateSystemAxis::Private {

// ---------------------------------------------------------------------------

CoordinateSystemAxis::CoordinateSystemAxis()
: d(internal::make_unique<Private>()) {}
CoordinateSystemAxis::CoordinateSystemAxis() : d(std::make_unique<Private>()) {}

// ---------------------------------------------------------------------------

#ifdef notdef
CoordinateSystemAxis::CoordinateSystemAxis(const CoordinateSystemAxis &other)
: IdentifiedObject(other), d(internal::make_unique<Private>(*other.d)) {}
: IdentifiedObject(other), d(std::make_unique<Private>(*other.d)) {}
#endif

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -599,13 +598,13 @@ struct CoordinateSystem::Private {

CoordinateSystem::CoordinateSystem(
const std::vector<CoordinateSystemAxisNNPtr> &axisIn)
: d(internal::make_unique<Private>(axisIn)) {}
: d(std::make_unique<Private>(axisIn)) {}

// ---------------------------------------------------------------------------

#ifdef notdef
CoordinateSystem::CoordinateSystem(const CoordinateSystem &other)
: IdentifiedObject(other), d(internal::make_unique<Private>(*other.d)) {}
: IdentifiedObject(other), d(std::make_unique<Private>(*other.d)) {}
#endif

// ---------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 6754b7c

Please sign in to comment.