diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 4000f2a..149156f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,11 @@ if (POLICY CMP0054) cmake_policy(SET CMP0054 NEW) endif() -set(CMAKE_CXX_STANDARD 11) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "..." FORCE) +endif() + +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/libsgp4/CMakeLists.txt b/libsgp4/CMakeLists.txt index b816645..f70d73b 100644 --- a/libsgp4/CMakeLists.txt +++ b/libsgp4/CMakeLists.txt @@ -38,4 +38,4 @@ set(SRCS add_library(sgp4 STATIC ${SRCS} ${INCS}) add_library(sgp4s SHARED ${SRCS} ${INCS}) install( TARGETS sgp4s LIBRARY DESTINATION lib ) -install( FILES ${INCS} DESTINATION include/SGP4 ) +install( FILES ${INCS} DESTINATION include/libsgp4 ) diff --git a/libsgp4/CoordGeodetic.h b/libsgp4/CoordGeodetic.h index 9dbb789..8007168 100644 --- a/libsgp4/CoordGeodetic.h +++ b/libsgp4/CoordGeodetic.h @@ -37,12 +37,7 @@ public: /** * Default constructor */ - CoordGeodetic() - : latitude(0.0), - longitude(0.0), - altitude(0.0) - { - } + CoordGeodetic() = default; /** * Constructor @@ -111,11 +106,11 @@ public: } /** latitude in radians (-PI >= latitude < PI) */ - double latitude; + double latitude{}; /** latitude in radians (-PI/2 >= latitude <= PI/2) */ - double longitude; + double longitude{}; /** altitude in kilometers */ - double altitude; + double altitude{}; }; /** diff --git a/libsgp4/CoordTopocentric.h b/libsgp4/CoordTopocentric.h index 8d9e2a9..f70b8fe 100644 --- a/libsgp4/CoordTopocentric.h +++ b/libsgp4/CoordTopocentric.h @@ -39,13 +39,7 @@ public: /** * Default constructor */ - CoordTopocentric() - : azimuth(0.0) - , elevation(0.0) - , range(0.0) - , range_rate(0.0) - { - } + CoordTopocentric() = default; /** * Constructor @@ -110,13 +104,13 @@ public: } /** azimuth in radians */ - double azimuth; + double azimuth{}; /** elevations in radians */ - double elevation; + double elevation{}; /** range in kilometers */ - double range; + double range{}; /** range rate in kilometers per second */ - double range_rate; + double range_rate{}; }; diff --git a/libsgp4/DateTime.h b/libsgp4/DateTime.h index 68982d9..7005ba6 100644 --- a/libsgp4/DateTime.h +++ b/libsgp4/DateTime.h @@ -61,7 +61,7 @@ public: * Constructor * @param[in] ticks raw tick value */ - DateTime(int64_t ticks) + explicit DateTime(int64_t ticks) : m_encoded(ticks) { } @@ -450,7 +450,7 @@ public: DateTime AddMicroseconds(const double microseconds) const { - int64_t ticks = static_cast(microseconds * TicksPerMicrosecond); + auto ticks = static_cast(microseconds * TicksPerMicrosecond); return AddTicks(ticks); } @@ -603,7 +603,7 @@ public: */ double ToJulian() const { - TimeSpan ts = TimeSpan(Ticks()); + auto ts = TimeSpan(Ticks()); return ts.TotalDays() + 1721425.5; } @@ -665,7 +665,7 @@ public: } private: - int64_t m_encoded; + int64_t m_encoded{}; }; inline std::ostream& operator<<(std::ostream& strm, const DateTime& dt) diff --git a/libsgp4/Observer.h b/libsgp4/Observer.h index df889f7..89387e8 100644 --- a/libsgp4/Observer.h +++ b/libsgp4/Observer.h @@ -50,7 +50,7 @@ public: * Constructor * @param[in] geo the observers position */ - Observer(const CoordGeodetic &geo) + explicit Observer(const CoordGeodetic &geo) : m_geo(geo) , m_eci(DateTime(), geo) { diff --git a/libsgp4/OrbitalElements.h b/libsgp4/OrbitalElements.h index 4b7847d..9ce389a 100644 --- a/libsgp4/OrbitalElements.h +++ b/libsgp4/OrbitalElements.h @@ -31,7 +31,7 @@ class Tle; class OrbitalElements { public: - OrbitalElements(const Tle& tle); + explicit OrbitalElements(const Tle& tle); /* * XMO diff --git a/libsgp4/SGP4.h b/libsgp4/SGP4.h index 274d393..e67aa1f 100644 --- a/libsgp4/SGP4.h +++ b/libsgp4/SGP4.h @@ -38,7 +38,7 @@ namespace libsgp4 class SGP4 { public: - SGP4(const Tle& tle) + explicit SGP4(const Tle& tle) : elements_(tle) { Initialise(); diff --git a/libsgp4/SatelliteException.h b/libsgp4/SatelliteException.h index 0905b04..900947a 100644 --- a/libsgp4/SatelliteException.h +++ b/libsgp4/SatelliteException.h @@ -29,7 +29,7 @@ namespace libsgp4 class SatelliteException : public std::runtime_error { public: - SatelliteException(const char* message) + explicit SatelliteException(const char* message) : runtime_error(message) { } diff --git a/libsgp4/SolarPosition.h b/libsgp4/SolarPosition.h index c8cb105..7e19c19 100644 --- a/libsgp4/SolarPosition.h +++ b/libsgp4/SolarPosition.h @@ -29,9 +29,7 @@ namespace libsgp4 class SolarPosition { public: - SolarPosition() - { - } + SolarPosition() = default; Eci FindPosition(const DateTime& dt); diff --git a/libsgp4/TimeSpan.h b/libsgp4/TimeSpan.h index 5190182..0bfdcdb 100644 --- a/libsgp4/TimeSpan.h +++ b/libsgp4/TimeSpan.h @@ -21,7 +21,7 @@ #include #include #include -#include +#include namespace libsgp4 { @@ -53,7 +53,7 @@ namespace class TimeSpan { public: - TimeSpan(int64_t ticks) + explicit TimeSpan(int64_t ticks) : m_ticks(ticks) { } @@ -197,7 +197,7 @@ public: } private: - int64_t m_ticks; + int64_t m_ticks{}; void CalculateTicks(int days, int hours, diff --git a/libsgp4/Tle.cc b/libsgp4/Tle.cc index 2616039..c74aaa3 100644 --- a/libsgp4/Tle.cc +++ b/libsgp4/Tle.cc @@ -146,9 +146,13 @@ void Tle::Initialize() TLE2_LEN_REVATEPOCH), orbit_number_); if (year < 57) + { year += 2000; + } else + { year += 1900; + } epoch_ = DateTime(year, day); } @@ -174,18 +178,18 @@ void Tle::ExtractInteger(const std::string& str, unsigned int& val) bool found_digit = false; unsigned int temp = 0; - for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) + for (auto& i : str) { - if (isdigit(*i)) + if (isdigit(i)) { found_digit = true; - temp = (temp * 10) + static_cast(*i - '0'); + temp = (temp * 10) + static_cast(i - '0'); } else if (found_digit) { throw TleException("Unexpected non digit"); } - else if (*i != ' ') + else if (i != ' ') { throw TleException("Invalid character"); } diff --git a/libsgp4/Tle.h b/libsgp4/Tle.h index b39dd63..a822a40 100644 --- a/libsgp4/Tle.h +++ b/libsgp4/Tle.h @@ -37,10 +37,9 @@ public: * @param[in] line_one Tle line one * @param[in] line_two Tle line two */ - Tle(const std::string& line_one, - const std::string& line_two) - : line_one_(line_one) - , line_two_(line_two) + Tle(std::string line_one, std::string line_two) + : line_one_(std::move(line_one)) + , line_two_(std::move(line_two)) { Initialize(); } @@ -51,12 +50,10 @@ public: * @param[in] line_one Tle line one * @param[in] line_two Tle line two */ - Tle(const std::string& name, - const std::string& line_one, - const std::string& line_two) - : name_(name) - , line_one_(line_one) - , line_two_(line_two) + Tle(std::string name, std::string line_one, std::string line_two) + : name_(std::move(name)) + , line_one_(std::move(line_one)) + , line_two_(std::move(line_two)) { Initialize(); } @@ -319,17 +316,17 @@ private: std::string int_designator_; DateTime epoch_; - double mean_motion_dt2_; - double mean_motion_ddt6_; - double bstar_; - double inclination_; - double right_ascending_node_; - double eccentricity_; - double argument_perigee_; - double mean_anomaly_; - double mean_motion_; - unsigned int norad_number_; - unsigned int orbit_number_; + double mean_motion_dt2_{}; + double mean_motion_ddt6_{}; + double bstar_{}; + double inclination_{}; + double right_ascending_node_{}; + double eccentricity_{}; + double argument_perigee_{}; + double mean_anomaly_{}; + double mean_motion_{}; + unsigned int norad_number_{}; + unsigned int orbit_number_{}; static const unsigned int TLE_LEN_LINE_DATA = 69; static const unsigned int TLE_LEN_LINE_NAME = 22; diff --git a/libsgp4/TleException.h b/libsgp4/TleException.h index ba5f39f..1caf6d0 100644 --- a/libsgp4/TleException.h +++ b/libsgp4/TleException.h @@ -35,7 +35,7 @@ public: * Constructor * @param message Exception message */ - TleException(const char* message) + explicit TleException(const char* message) : runtime_error(message) { } diff --git a/libsgp4/Util.cc b/libsgp4/Util.cc index 47f1546..3437aab 100644 --- a/libsgp4/Util.cc +++ b/libsgp4/Util.cc @@ -21,30 +21,17 @@ #include #include -namespace libsgp4 +namespace libsgp4::Util { -namespace Util -{ - namespace - { - struct IsDigit: std::unary_function - { - bool operator()(char c) const - { - return std::isdigit(c, std::locale::classic()) == 0; - } - }; - } - void TrimLeft(std::string& s) { s.erase(s.begin(), - std::find_if(s.begin(), s.end(), std::not1(IsDigit()))); + std::find_if(s.begin(), s.end(), [](unsigned char c){ return std::isgraph(c) != 0; })); } void TrimRight(std::string& s) { - s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(IsDigit())).base(), + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char c){ return std::isgraph(c) != 0; }).base(), s.end()); } @@ -53,5 +40,4 @@ namespace Util TrimLeft(s); TrimRight(s); } -} // namespace Util -} // namespace libsgp4 +} // namespace libsgp4::Util diff --git a/libsgp4/Vector.h b/libsgp4/Vector.h index 5129129..40856e5 100644 --- a/libsgp4/Vector.h +++ b/libsgp4/Vector.h @@ -37,10 +37,7 @@ public: /** * Default constructor */ - Vector() - : x(0.0), y(0.0), z(0.0), w(0.0) - { - } + Vector() = default; /** * Constructor @@ -51,7 +48,7 @@ public: Vector(const double arg_x, const double arg_y, const double arg_z) - : x(arg_x), y(arg_y), z(arg_z), w(0.0) + : x(arg_x), y(arg_y), z(arg_z) { } @@ -69,7 +66,7 @@ public: : x(arg_x), y(arg_y), z(arg_z), w(arg_w) { } - + /** * Copy constructor * @param v value to copy from @@ -146,13 +143,13 @@ public: } /** x value */ - double x; + double x{}; /** y value */ - double y; + double y{}; /** z value */ - double z; + double z{}; /** w value */ - double w; + double w{}; }; inline std::ostream& operator<<(std::ostream& strm, const Vector& v)