diff --git a/src/Base/UnitsApi.cpp b/src/Base/UnitsApi.cpp index 87b9208d38..68fc03d4b2 100644 --- a/src/Base/UnitsApi.cpp +++ b/src/Base/UnitsApi.cpp @@ -34,6 +34,7 @@ #include "UnitsSchemaMKS.h" #include "UnitsSchemaCentimeters.h" #include "UnitsSchemaMmMin.h" +#include "StdStlTools.h" #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -61,7 +62,7 @@ using namespace Base; // === static attributes ================================================ double UnitsApi::defaultFactor = 1.0; -UnitsSchema *UnitsApi::UserPrefSystem = new UnitsSchemaInternal(); +UnitsSchemaPtr UnitsApi::UserPrefSystem(new UnitsSchemaInternal()); UnitSystem UnitsApi::actSystem = UnitSystem::SI1; //double UnitsApi::UserPrefFactor [50]; @@ -104,38 +105,36 @@ const char* UnitsApi::getDescription(UnitSystem system) } } -UnitsSchema* UnitsApi::createSchema(UnitSystem s) +UnitsSchemaPtr UnitsApi::createSchema(UnitSystem s) { switch (s) { case UnitSystem::SI1: - return new UnitsSchemaInternal(); + return std::make_unique(); case UnitSystem::SI2: - return new UnitsSchemaMKS(); + return std::make_unique(); case UnitSystem::Imperial1: - return new UnitsSchemaImperial1(); + return std::make_unique(); case UnitSystem::ImperialDecimal: - return new UnitsSchemaImperialDecimal(); + return std::make_unique(); case UnitSystem::Centimeters: - return new UnitsSchemaCentimeters(); + return std::make_unique(); case UnitSystem::ImperialBuilding: - return new UnitsSchemaImperialBuilding(); + return std::make_unique(); case UnitSystem::MmMin: - return new UnitsSchemaMmMin(); + return std::make_unique(); case UnitSystem::ImperialCivil: - return new UnitsSchemaImperialCivil(); + return std::make_unique(); default: break; } - return 0; + return nullptr; } void UnitsApi::setSchema(UnitSystem s) { if (UserPrefSystem) { UserPrefSystem->resetSchemaUnits(); // for schemas changed the Quantity constants - delete UserPrefSystem; - UserPrefSystem = 0; } UserPrefSystem = createSchema(s); @@ -143,7 +142,7 @@ void UnitsApi::setSchema(UnitSystem s) // for wrong value fall back to standard schema if (!UserPrefSystem) { - UserPrefSystem = new UnitsSchemaInternal(); + UserPrefSystem = std::make_unique(); actSystem = UnitSystem::SI1; } diff --git a/src/Base/UnitsApi.h b/src/Base/UnitsApi.h index 11a598b3f6..e3fb958693 100644 --- a/src/Base/UnitsApi.h +++ b/src/Base/UnitsApi.h @@ -25,6 +25,7 @@ #define BASE_UNITSAPI_H #include +#include #include #include #include "UnitsSchema.h" @@ -32,7 +33,7 @@ namespace Base { - +typedef std::unique_ptr UnitsSchemaPtr; /** * The UnitsApi @@ -87,11 +88,11 @@ public: protected: /// return an instance of the given enum value - static UnitsSchema* createSchema(UnitSystem s); + static UnitsSchemaPtr createSchema(UnitSystem s); protected: // not used at the moment - static UnitsSchema * UserPrefSystem; + static UnitsSchemaPtr UserPrefSystem; static UnitSystem actSystem; /// number of decimals for floats static int UserPrefDecimals;