Misc c++ updates

feature/tidy-ups
Dan Warner 2022-11-13 12:59:41 +00:00
parent 16f4717840
commit 1a57bb43f9
17 changed files with 64 additions and 77 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build/

View File

@ -5,7 +5,11 @@ if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW) cmake_policy(SET CMP0054 NEW)
endif() 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_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)

View File

@ -38,4 +38,4 @@ set(SRCS
add_library(sgp4 STATIC ${SRCS} ${INCS}) add_library(sgp4 STATIC ${SRCS} ${INCS})
add_library(sgp4s SHARED ${SRCS} ${INCS}) add_library(sgp4s SHARED ${SRCS} ${INCS})
install( TARGETS sgp4s LIBRARY DESTINATION lib ) install( TARGETS sgp4s LIBRARY DESTINATION lib )
install( FILES ${INCS} DESTINATION include/SGP4 ) install( FILES ${INCS} DESTINATION include/libsgp4 )

View File

@ -37,12 +37,7 @@ public:
/** /**
* Default constructor * Default constructor
*/ */
CoordGeodetic() CoordGeodetic() = default;
: latitude(0.0),
longitude(0.0),
altitude(0.0)
{
}
/** /**
* Constructor * Constructor
@ -111,11 +106,11 @@ public:
} }
/** latitude in radians (-PI >= latitude < PI) */ /** latitude in radians (-PI >= latitude < PI) */
double latitude; double latitude{};
/** latitude in radians (-PI/2 >= latitude <= PI/2) */ /** latitude in radians (-PI/2 >= latitude <= PI/2) */
double longitude; double longitude{};
/** altitude in kilometers */ /** altitude in kilometers */
double altitude; double altitude{};
}; };
/** /**

View File

@ -39,13 +39,7 @@ public:
/** /**
* Default constructor * Default constructor
*/ */
CoordTopocentric() CoordTopocentric() = default;
: azimuth(0.0)
, elevation(0.0)
, range(0.0)
, range_rate(0.0)
{
}
/** /**
* Constructor * Constructor
@ -110,13 +104,13 @@ public:
} }
/** azimuth in radians */ /** azimuth in radians */
double azimuth; double azimuth{};
/** elevations in radians */ /** elevations in radians */
double elevation; double elevation{};
/** range in kilometers */ /** range in kilometers */
double range; double range{};
/** range rate in kilometers per second */ /** range rate in kilometers per second */
double range_rate; double range_rate{};
}; };

View File

@ -61,7 +61,7 @@ public:
* Constructor * Constructor
* @param[in] ticks raw tick value * @param[in] ticks raw tick value
*/ */
DateTime(int64_t ticks) explicit DateTime(int64_t ticks)
: m_encoded(ticks) : m_encoded(ticks)
{ {
} }
@ -450,7 +450,7 @@ public:
DateTime AddMicroseconds(const double microseconds) const DateTime AddMicroseconds(const double microseconds) const
{ {
int64_t ticks = static_cast<int64_t>(microseconds * TicksPerMicrosecond); auto ticks = static_cast<int64_t>(microseconds * TicksPerMicrosecond);
return AddTicks(ticks); return AddTicks(ticks);
} }
@ -603,7 +603,7 @@ public:
*/ */
double ToJulian() const double ToJulian() const
{ {
TimeSpan ts = TimeSpan(Ticks()); auto ts = TimeSpan(Ticks());
return ts.TotalDays() + 1721425.5; return ts.TotalDays() + 1721425.5;
} }
@ -665,7 +665,7 @@ public:
} }
private: private:
int64_t m_encoded; int64_t m_encoded{};
}; };
inline std::ostream& operator<<(std::ostream& strm, const DateTime& dt) inline std::ostream& operator<<(std::ostream& strm, const DateTime& dt)

View File

@ -50,7 +50,7 @@ public:
* Constructor * Constructor
* @param[in] geo the observers position * @param[in] geo the observers position
*/ */
Observer(const CoordGeodetic &geo) explicit Observer(const CoordGeodetic &geo)
: m_geo(geo) : m_geo(geo)
, m_eci(DateTime(), geo) , m_eci(DateTime(), geo)
{ {

View File

@ -31,7 +31,7 @@ class Tle;
class OrbitalElements class OrbitalElements
{ {
public: public:
OrbitalElements(const Tle& tle); explicit OrbitalElements(const Tle& tle);
/* /*
* XMO * XMO

View File

@ -38,7 +38,7 @@ namespace libsgp4
class SGP4 class SGP4
{ {
public: public:
SGP4(const Tle& tle) explicit SGP4(const Tle& tle)
: elements_(tle) : elements_(tle)
{ {
Initialise(); Initialise();

View File

@ -29,7 +29,7 @@ namespace libsgp4
class SatelliteException : public std::runtime_error class SatelliteException : public std::runtime_error
{ {
public: public:
SatelliteException(const char* message) explicit SatelliteException(const char* message)
: runtime_error(message) : runtime_error(message)
{ {
} }

View File

@ -29,9 +29,7 @@ namespace libsgp4
class SolarPosition class SolarPosition
{ {
public: public:
SolarPosition() SolarPosition() = default;
{
}
Eci FindPosition(const DateTime& dt); Eci FindPosition(const DateTime& dt);

View File

@ -21,7 +21,7 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <cmath> #include <cmath>
#include <stdint.h> #include <cstdint>
namespace libsgp4 namespace libsgp4
{ {
@ -53,7 +53,7 @@ namespace
class TimeSpan class TimeSpan
{ {
public: public:
TimeSpan(int64_t ticks) explicit TimeSpan(int64_t ticks)
: m_ticks(ticks) : m_ticks(ticks)
{ {
} }
@ -197,7 +197,7 @@ public:
} }
private: private:
int64_t m_ticks; int64_t m_ticks{};
void CalculateTicks(int days, void CalculateTicks(int days,
int hours, int hours,

View File

@ -146,9 +146,13 @@ void Tle::Initialize()
TLE2_LEN_REVATEPOCH), orbit_number_); TLE2_LEN_REVATEPOCH), orbit_number_);
if (year < 57) if (year < 57)
{
year += 2000; year += 2000;
}
else else
{
year += 1900; year += 1900;
}
epoch_ = DateTime(year, day); epoch_ = DateTime(year, day);
} }
@ -174,18 +178,18 @@ void Tle::ExtractInteger(const std::string& str, unsigned int& val)
bool found_digit = false; bool found_digit = false;
unsigned int temp = 0; 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; found_digit = true;
temp = (temp * 10) + static_cast<unsigned int>(*i - '0'); temp = (temp * 10) + static_cast<unsigned int>(i - '0');
} }
else if (found_digit) else if (found_digit)
{ {
throw TleException("Unexpected non digit"); throw TleException("Unexpected non digit");
} }
else if (*i != ' ') else if (i != ' ')
{ {
throw TleException("Invalid character"); throw TleException("Invalid character");
} }

View File

@ -37,10 +37,9 @@ public:
* @param[in] line_one Tle line one * @param[in] line_one Tle line one
* @param[in] line_two Tle line two * @param[in] line_two Tle line two
*/ */
Tle(const std::string& line_one, Tle(std::string line_one, std::string line_two)
const std::string& line_two) : line_one_(std::move(line_one))
: line_one_(line_one) , line_two_(std::move(line_two))
, line_two_(line_two)
{ {
Initialize(); Initialize();
} }
@ -51,12 +50,10 @@ public:
* @param[in] line_one Tle line one * @param[in] line_one Tle line one
* @param[in] line_two Tle line two * @param[in] line_two Tle line two
*/ */
Tle(const std::string& name, Tle(std::string name, std::string line_one, std::string line_two)
const std::string& line_one, : name_(std::move(name))
const std::string& line_two) , line_one_(std::move(line_one))
: name_(name) , line_two_(std::move(line_two))
, line_one_(line_one)
, line_two_(line_two)
{ {
Initialize(); Initialize();
} }
@ -319,17 +316,17 @@ private:
std::string int_designator_; std::string int_designator_;
DateTime epoch_; DateTime epoch_;
double mean_motion_dt2_; double mean_motion_dt2_{};
double mean_motion_ddt6_; double mean_motion_ddt6_{};
double bstar_; double bstar_{};
double inclination_; double inclination_{};
double right_ascending_node_; double right_ascending_node_{};
double eccentricity_; double eccentricity_{};
double argument_perigee_; double argument_perigee_{};
double mean_anomaly_; double mean_anomaly_{};
double mean_motion_; double mean_motion_{};
unsigned int norad_number_; unsigned int norad_number_{};
unsigned int orbit_number_; unsigned int orbit_number_{};
static const unsigned int TLE_LEN_LINE_DATA = 69; static const unsigned int TLE_LEN_LINE_DATA = 69;
static const unsigned int TLE_LEN_LINE_NAME = 22; static const unsigned int TLE_LEN_LINE_NAME = 22;

View File

@ -35,7 +35,7 @@ public:
* Constructor * Constructor
* @param message Exception message * @param message Exception message
*/ */
TleException(const char* message) explicit TleException(const char* message)
: runtime_error(message) : runtime_error(message)
{ {
} }

View File

@ -21,9 +21,7 @@
#include <locale> #include <locale>
#include <functional> #include <functional>
namespace libsgp4 namespace libsgp4::Util
{
namespace Util
{ {
namespace namespace
{ {
@ -53,5 +51,4 @@ namespace Util
TrimLeft(s); TrimLeft(s);
TrimRight(s); TrimRight(s);
} }
} // namespace Util } // namespace libsgp4::Util
} // namespace libsgp4

View File

@ -37,10 +37,7 @@ public:
/** /**
* Default constructor * Default constructor
*/ */
Vector() Vector() = default;
: x(0.0), y(0.0), z(0.0), w(0.0)
{
}
/** /**
* Constructor * Constructor
@ -51,7 +48,7 @@ public:
Vector(const double arg_x, Vector(const double arg_x,
const double arg_y, const double arg_y,
const double arg_z) 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)
{ {
} }
@ -146,13 +143,13 @@ public:
} }
/** x value */ /** x value */
double x; double x{};
/** y value */ /** y value */
double y; double y{};
/** z value */ /** z value */
double z; double z{};
/** w value */ /** w value */
double w; double w{};
}; };
inline std::ostream& operator<<(std::ostream& strm, const Vector& v) inline std::ostream& operator<<(std::ostream& strm, const Vector& v)