From 0877e193419aa43d7e04cebe65070fcd6b705f83 Mon Sep 17 00:00:00 2001 From: Cesar Munoz Date: Fri, 29 Sep 2023 10:25:16 -0400 Subject: [PATCH] Added cppcheck --- .../cppcheck-suppressions.txt | 2 + C++/.gitignore | 1 + C++/Makefile | 2 +- C++/include/AircraftState.h | 6 +- C++/include/Alerter.h | 6 +- C++/include/CDCylinder.h | 5 +- C++/include/ConflictData.h | 8 +- C++/include/CriteriaCore.h | 12 +-- C++/include/Daidalus.h | 10 +- C++/include/Detection3DParameterWriter.h | 4 +- C++/include/FixedAircraftUrgencyStrategy.h | 2 +- C++/include/GreatCircle.h | 2 +- C++/include/Kinematics.h | 6 +- C++/include/Position.h | 2 +- C++/include/Projection.h | 2 +- C++/include/SeparatedInput.h | 39 +++---- C++/include/SeparatedOutput.h | 6 +- C++/include/Util.h | 2 +- C++/include/format.h | 8 +- C++/src/AircraftState.cpp | 6 +- C++/src/Alerter.cpp | 12 +-- C++/src/BandsRange.cpp | 5 +- C++/src/CDCylinder.cpp | 35 +++--- C++/src/ConflictData.cpp | 36 +++---- C++/src/CriteriaCore.cpp | 20 ++-- C++/src/Daidalus.cpp | 10 +- C++/src/DaidalusFileWalker.cpp | 3 +- C++/src/Detection3DParameterWriter.cpp | 4 +- C++/src/FixedAircraftUrgencyStrategy.cpp | 10 +- C++/src/GreatCircle.cpp | 2 +- C++/src/Kinematics.cpp | 6 +- C++/src/OrthographicProjection.cpp | 15 +-- C++/src/ParameterData.cpp | 15 ++- C++/src/Position.cpp | 2 +- C++/src/Projection.cpp | 2 +- C++/src/SeparatedInput.cpp | 100 ++++++++---------- C++/src/SeparatedOutput.cpp | 6 +- C++/src/TCAS3D.cpp | 10 +- C++/src/Util.cpp | 2 +- C++/src/format.cpp | 21 ++-- .../gov/nasa/larcfm/ACCoRD/CriteriaCore.java | 4 - .../gov/nasa/larcfm/Util/ParameterData.java | 2 +- 42 files changed, 202 insertions(+), 251 deletions(-) create mode 100644 C++/.cppcheck-config/cppcheck-suppressions.txt create mode 100644 C++/.gitignore diff --git a/C++/.cppcheck-config/cppcheck-suppressions.txt b/C++/.cppcheck-config/cppcheck-suppressions.txt new file mode 100644 index 00000000..0e1d905b --- /dev/null +++ b/C++/.cppcheck-config/cppcheck-suppressions.txt @@ -0,0 +1,2 @@ +stlFindInsert:src/Detection3DParameterReader.cpp +stlFindInsert:src/SequenceReader.cpp diff --git a/C++/.gitignore b/C++/.gitignore new file mode 100644 index 00000000..a4695770 --- /dev/null +++ b/C++/.gitignore @@ -0,0 +1 @@ +.cppcheck-config \ No newline at end of file diff --git a/C++/Makefile b/C++/Makefile index 905de280..050f10f4 100644 --- a/C++/Makefile +++ b/C++/Makefile @@ -52,7 +52,7 @@ clean: rm -f DaidalusExample DaidalusAlerting DaidalusBatch src/*.o examples/*.o lib/*.a check: - cppcheck --enable=all $(INCLUDEFLAGS) -q $(SRC) + cppcheck --enable=performance --cppcheck-build-dir=.cppcheck-config --suppressions-list=.cppcheck-config/cppcheck-suppressions.txt $(INCLUDEFLAGS) -q $(SRC) mold: examples ./DaidalusExample --config no_sum --verbose > ../Regression/C++/DaidalusExample-no_sum.out diff --git a/C++/include/AircraftState.h b/C++/include/AircraftState.h index 0671349a..fd5636cb 100644 --- a/C++/include/AircraftState.h +++ b/C++/include/AircraftState.h @@ -91,7 +91,7 @@ class AircraftState : public ErrorReporter { double lastZeroTrackRateThreshold; - void init(std::string name, int buffer_size); + void init(const std::string& name, int buffer_size); // This inserts the given data at point i--no questions asked. Everything // from index 0..i is shifted down one place. i is an external index @@ -319,7 +319,7 @@ class AircraftState : public ErrorReporter { * Be sure to note if the returned projection point has a zero altitude or not. * @return the current projection object */ - EuclideanProjection getProjection() const; + const EuclideanProjection& getProjection() const; @@ -384,7 +384,7 @@ class AircraftState : public ErrorReporter { * @param v2 velocity of another aircraft * @return true, if close */ - static bool closeEnough(Velocity v1, Velocity v2); + static bool closeEnough(const Velocity& v1, const Velocity& v2); /** Last time when track rate was near zero * diff --git a/C++/include/Alerter.h b/C++/include/Alerter.h index 63529e5d..feea328d 100644 --- a/C++/include/Alerter.h +++ b/C++/include/Alerter.h @@ -29,14 +29,14 @@ class Alerter : ParameterAcceptor { public: - Alerter(); - virtual ~Alerter() {} static const Alerter& INVALID(); bool isValid() const; + Alerter(); + Alerter(const std::string& id); /** @@ -258,7 +258,7 @@ class Alerter : ParameterAcceptor { * alerting time, and lookahead time. The single bands region is NEAR */ static Alerter SingleBands(const Detection3D* detector, double alerting_time, double lookahead_time, - const std::string name="default"); + const std::string& name="default"); /** * @return alerting thresholds for ACCoRD's CD3D, i.e., diff --git a/C++/include/CDCylinder.h b/C++/include/CDCylinder.h index 95665970..b0d85376 100644 --- a/C++/include/CDCylinder.h +++ b/C++/include/CDCylinder.h @@ -61,10 +61,11 @@ namespace larcfm { class CDCylinder : public Detection3D { private: - std::string id; - std::map units_; + double D_; double H_; + std::map units_; + std::string id; public: diff --git a/C++/include/ConflictData.h b/C++/include/ConflictData.h index 9a185bc6..d2d0995f 100644 --- a/C++/include/ConflictData.h +++ b/C++/include/ConflictData.h @@ -26,15 +26,17 @@ namespace larcfm { class ConflictData : public LossData { +public: + + double time_crit; // relative time to critical point + double dist_crit; // distance or severity at critical point (0 is most critical, +inf is least severe) + private: Vect3 s_; // Relative position Vect3 v_; // Relative velocity public: - double time_crit; // relative time to critical point - double dist_crit; // distance or severity at critical point (0 is most critical, +inf is least severe) - std::string toString() const; ConflictData(double t_in, double t_out, double t_crit, double d_crit, const Vect3& s, const Vect3& v); diff --git a/C++/include/CriteriaCore.h b/C++/include/CriteriaCore.h index e8940eae..c0fa0ca0 100644 --- a/C++/include/CriteriaCore.h +++ b/C++/include/CriteriaCore.h @@ -72,7 +72,7 @@ class CriteriaCore { * -1 corresponds to reducing current vertical speed, * +1 corresponds to increasing current vertical speed */ - static int verticalCoordination(const Vect3& s, const Vect3& vo, const Vect3& vi,double D, double H, std::string ownship, std::string traffic); + static int verticalCoordination(const Vect3& s, const Vect3& vo, const Vect3& vi,double D, double H, const std::string& ownship, const std::string& traffic); /** The fundamental horizontal criterion (Conflict Case) * @param sp relative position assumed to be horizontally separated (Sp_vect2 : TYPE = (horizontal_sep?)) @@ -242,15 +242,13 @@ class CriteriaCore { */ static bool vertical_new_repulsive_criterion(const Vect3& s, const Vect3& vo, const Vect3& vi, const Vect3& nvo, int eps); - static int verticalCoordinationLoS(const Vect3& s, const Vect3& vo, const Vect3& vi, std::string ownship, std::string traffic); + static int verticalCoordinationLoS(const Vect3& s, const Vect3& vo, const Vect3& vi, const std::string& ownship, const std::string& traffic); private: static bool horizontal_criterion_0(const Vect2& sp, int eps, const Vect2& v, double D); - static int verticalCoordinationConflict(const Vect3& s, const Vect3& v, double D, std::string ownship, std::string traffic); - - // static int sign_vz(const Vect3& s, const double voz, const double viz, std::string ownship, std::string traffic); + static int verticalCoordinationConflict(const Vect3& s, const Vect3& v, double D, const std::string& ownship, const std::string& traffic); static bool criterion_3D(const Vect3& sp, const Velocity& v, int epsH, int epsV, const Velocity& nv, double D, double H); @@ -258,7 +256,7 @@ class CriteriaCore { static Vect3 vertical_decision_vect(const Vect3& s, const Vect3& vo, const Vect3& vi, double caD, double caH); // Compute an absolute repulsive vertical direction - static int losr_vs_dir(const Vect3& s, const Vect3& vo, const Vect3& vi, double caD, double caH, std::string ownship, std::string traffic); + static int losr_vs_dir(const Vect3& s, const Vect3& vo, const Vect3& vi, double caD, double caH, const std::string& ownship, const std::string& traffic); static bool vs_bound_crit(const Vect3& v, const Vect3& nv, int eps); @@ -267,7 +265,7 @@ class CriteriaCore { static bool vertical_los_criterion(const Vect3& s, const Vect3& v, const Vect3& nv, int eps, double H, double minrelvs); /** Perform a symmetry calculation */ - static int breakSymmetry(const Vect3& s, std::string ownship, std::string traffic); + static int breakSymmetry(const Vect3& s, const std::string& ownship, const std::string& traffic); }; diff --git a/C++/include/Daidalus.h b/C++/include/Daidalus.h index 56363352..0137f1c2 100644 --- a/C++/include/Daidalus.h +++ b/C++/include/Daidalus.h @@ -544,7 +544,7 @@ class Daidalus : public ErrorReporter { /** * Return index of alerter with a given name. Return 0 if it doesn't exist */ - int getAlerterIndex(std::string id) const; + int getAlerterIndex(const std::string& id) const; /** * Clear all alert thresholds @@ -819,7 +819,7 @@ class Daidalus : public ErrorReporter { /** * @return the vertical climb/descend rate for altitude bands in specified units [u]. */ - double getVerticalRate(std::string u) const; + double getVerticalRate(const std::string& u) const; /** * @return horizontal NMAC distance in internal units [m]. @@ -1077,7 +1077,7 @@ class Daidalus : public ErrorReporter { * Set horizontal speed in given units (below current value) for the * computation of relative bands */ - void setBelowRelativeHorizontalSpeed(double val,std::string u); + void setBelowRelativeHorizontalSpeed(double val,const std::string& u); /** * Set horizontal speed in internal units (above current value) for the @@ -1575,7 +1575,7 @@ class Daidalus : public ErrorReporter { /** * @return Distance (in given units) at which h_vel_z_score scales from min to max as range decreases */ - double getHorizontalVelocityZDistance(std::string u) const; + double getHorizontalVelocityZDistance(const std::string& u) const; /** * @return Set distance (in internal units) at which h_vel_z_score scales from min to max as range decreases @@ -1619,7 +1619,7 @@ class Daidalus : public ErrorReporter { * the left/right of current aircraft direction. A value of 0 means only conflict contours. * A value of pi means all contours. */ - double getHorizontalContourThreshold(std::string u) const; + double getHorizontalContourThreshold(const std::string& u) const; /** * Set horizontal contour threshold, specified in internal units [rad] [0 - pi] as an angle to diff --git a/C++/include/Detection3DParameterWriter.h b/C++/include/Detection3DParameterWriter.h index 8c9692a5..18323b84 100644 --- a/C++/include/Detection3DParameterWriter.h +++ b/C++/include/Detection3DParameterWriter.h @@ -26,7 +26,7 @@ class Detection3DParameterWriter { * @param res resolution instance -- this may be null * Note: this may modify the instance identifiers if they are not already unique. */ - static ParameterData writeCoreDetection(std::vector dlist, Detection3D* det, Detection3D* res); + static ParameterData writeCoreDetection(std::vector& dlist, Detection3D* det, Detection3D* res); /** * Return a ParameterData suitable to be read by readCoreDetection() based on the supplied Detection3D instances. * @param dlist list of Detection3D instances -- this may be empty. det and res instances will be automatically added to the list (if they are not already in it) @@ -34,7 +34,7 @@ class Detection3DParameterWriter { * @param res resolution instance -- this may be null * @param ordered true to modify detection identifiers to ensure they retain the input list's ordering when decoded, false will only modify identifiers if they are not unique */ - static ParameterData writeCoreDetection(std::vector dlist, Detection3D* det, Detection3D* res, bool ordered); + static ParameterData writeCoreDetection(std::vector& dlist, Detection3D* det, Detection3D* res, bool ordered); /** * This removes all standard core detection parameters from a ParameterData object diff --git a/C++/include/FixedAircraftUrgencyStrategy.h b/C++/include/FixedAircraftUrgencyStrategy.h index a82b99f9..553e8f26 100644 --- a/C++/include/FixedAircraftUrgencyStrategy.h +++ b/C++/include/FixedAircraftUrgencyStrategy.h @@ -26,7 +26,7 @@ class FixedAircraftUrgencyStrategy : public UrgencyStrategy { public: FixedAircraftUrgencyStrategy(); explicit FixedAircraftUrgencyStrategy(const std::string& id); - std::string getFixedAircraftId() const; + const std::string& getFixedAircraftId() const; void setFixedAircraftId(const std::string& id); /** * @return index of aircraft id diff --git a/C++/include/GreatCircle.h b/C++/include/GreatCircle.h index 5d4f934c..330c44c0 100644 --- a/C++/include/GreatCircle.h +++ b/C++/include/GreatCircle.h @@ -391,7 +391,7 @@ namespace larcfm { * @param d distance from point #1 [m] * @return a new position that is distance d from point #1 */ - static LatLonAlt linear_gc(LatLonAlt p1, LatLonAlt p2, double d); + static LatLonAlt linear_gc(const LatLonAlt& p1, const LatLonAlt& p2, double d); /** diff --git a/C++/include/Kinematics.h b/C++/include/Kinematics.h index 0e6e2941..85167686 100644 --- a/C++/include/Kinematics.h +++ b/C++/include/Kinematics.h @@ -215,7 +215,7 @@ class Kinematics { static std::pair linear(const std::pair& sv0, double t); - static std::pair linear(Vect3 so, Velocity vo, double t); + static std::pair linear(const Vect3& so, const Velocity& vo, double t); @@ -533,7 +533,7 @@ class Kinematics { * @param v velocity * @return elevation angle [radians] */ - static double elevationAngle(Velocity v); + static double elevationAngle(const Velocity& v); /** @@ -794,7 +794,7 @@ class Kinematics { * @param p2 * @return track angle of p2 - p1 */ - static double trackFrom(Vect3 p1, Vect3 p2); + static double trackFrom(const Vect3& p1, const Vect3& p2); private: diff --git a/C++/include/Position.h b/C++/include/Position.h index f56453b1..85a89448 100644 --- a/C++/include/Position.h +++ b/C++/include/Position.h @@ -429,7 +429,7 @@ class Position { */ bool LoS(const Position& p2, double D, double H); - bool collinear(Position p1, Position p2) const; + bool collinear(const Position& p1, const Position& p2) const; std::string toUnitTest() const; diff --git a/C++/include/Projection.h b/C++/include/Projection.h index c36ac207..8d1bc87c 100644 --- a/C++/include/Projection.h +++ b/C++/include/Projection.h @@ -130,7 +130,7 @@ class Projection { * @param s name of projection type * @return projection type */ - static ProjectionType getProjectionTypeFromString(std::string s); + static ProjectionType getProjectionTypeFromString(const std::string& s); /** * Return the current ProjectionType diff --git a/C++/include/SeparatedInput.h b/C++/include/SeparatedInput.h index f9ad6d91..0eb91a30 100644 --- a/C++/include/SeparatedInput.h +++ b/C++/include/SeparatedInput.h @@ -127,7 +127,7 @@ namespace larcfm { * Return the regular expression used to divide each line into columns. * @return pattern */ - std::string getColumnDelimiters() const; + const std::string& getColumnDelimiters() const; void setFixedColumn(const std::string& widths, const std::string& nameList, const std::string& unitList); @@ -308,39 +308,30 @@ namespace larcfm { private: - std::istream* reader; - mutable ErrorLog error; - bool header; // header line read in - std::vector header_str; // header line raw string - bool bunits; // units line read in - bool first_bunits; // units line read in - std::vector units_str; // Units type - std::vector units_factor; // Units conversion value - std::vector line_str; // raw line + std::istream* reader; + bool header; // header line read in + bool bunits; // units line read in + bool first_bunits; // units line read in + bool caseSensitive; + int linenum; + std::string patternStr; bool fixed_width; // Instead of using a delimiter, use fixed width columns - std::vector width_int; // The width of columns - char quoteCharacter; // If a non-empty value, use that character to delimit complex string tokens bool quoteCharDefined; // because we don't have null - - int linenum; - - bool caseSensitive; - - std::string patternStr; - + ParameterData parameters; std::string preambleImage; -// typedef std::map > paramtype; -// paramtype parameters; + std::vector header_str; // header line raw string + std::vector units_str; // Units type + std::vector units_factor; // Units conversion value + std::vector line_str; // raw line + std::vector width_int; // The width of columns - ParameterData parameters; - double getUnitFactor(int i) const; bool process_units(const std::string& str); - bool process_preamble(std::string str); + bool process_preamble(const std::string& str); void process_line(const std::string& str); std::vector processQuotes(const std::string& str) const; diff --git a/C++/include/SeparatedOutput.h b/C++/include/SeparatedOutput.h index 306e5eae..e2e727c7 100644 --- a/C++/include/SeparatedOutput.h +++ b/C++/include/SeparatedOutput.h @@ -246,7 +246,7 @@ class SeparatedOutput : public ErrorReporter { * The value to be displayed if a column is "skipped". Empty values are only added inside a line, not at the end. * @param e value to indicate empty */ - void setEmptyValue(std::string e); + void setEmptyValue(const std::string& e); /** * Set the code indicating the start of a comment. @@ -282,10 +282,10 @@ class SeparatedOutput : public ErrorReporter { void flush(); private: - void print_line(std::vector vals); // throws IOException; + void print_line(const std::vector& vals); // throws IOException; public: - std::string toString(); + std::string toString() const; // ErrorReporter Interface Methods diff --git a/C++/include/Util.h b/C++/include/Util.h index a21f4bb6..1d64f656 100644 --- a/C++/include/Util.h +++ b/C++/include/Util.h @@ -468,7 +468,7 @@ class Util { * @param s2 another string * @return true, if s1 is less or equals to s2 */ - static bool less_or_equal(std::string s1, std::string s2); + static bool less_or_equal(const std::string& s1, const std::string& s2); /** * Returns true if a turn from track angle alpha to track angle beta is diff --git a/C++/include/format.h b/C++/include/format.h index 7e6f0d40..b75dd5d3 100644 --- a/C++/include/format.h +++ b/C++/include/format.h @@ -55,14 +55,14 @@ namespace larcfm { std::string Fmb(bool b); /** Format a vector */ - std::string FmVec(Vect2 v); + std::string FmVec(const Vect2& v); /** Format a vector */ - std::string FmVec(Vect3 v); + std::string FmVec(const Vect3& v); /** Return a string 'n' long with 's' left-justified */ - std::string padLeft(std::string s, int n); + std::string padLeft(const std::string& s, int n); /** Return a string 'n' long with 's' right-justified */ - std::string padRight(std::string s, int n); + std::string padRight(const std::string& s, int n); /** Returns true/false string */ std::string bool2str(bool b); diff --git a/C++/src/AircraftState.cpp b/C++/src/AircraftState.cpp index 32bc8ff7..93668c96 100644 --- a/C++/src/AircraftState.cpp +++ b/C++/src/AircraftState.cpp @@ -81,7 +81,7 @@ AircraftState::~AircraftState() { if (projT) delete [] projT; } -void AircraftState::init(string name, int buffer_size) { +void AircraftState::init(const string& name, int buffer_size) { sz = 0; bufferSize = buffer_size < 1 ? DEFAULT_BUFFER_SIZE : buffer_size; s_list = new Position[bufferSize]; @@ -460,7 +460,7 @@ void AircraftState::updateProjection() { regression_done = false; } -EuclideanProjection AircraftState::getProjection() const { +const EuclideanProjection& AircraftState::getProjection() const { return sp; } @@ -613,7 +613,7 @@ bool AircraftState::inLevelFlight() { return std::abs(vol.z()) < minClimbVelocity && std::abs(vonl.z()) < minClimbVelocity; } -bool AircraftState::closeEnough(Velocity v1, Velocity v2) { +bool AircraftState::closeEnough(const Velocity& v1, const Velocity& v2) { double delTrk = std::abs(v1.trk() - v2.trk()); double delGs = std::abs(v1.gs() - v2.gs()) ; double delVs = std::abs(v1.vs() - v2.vs()) ; diff --git a/C++/src/Alerter.cpp b/C++/src/Alerter.cpp index 12c14023..3099f538 100644 --- a/C++/src/Alerter.cpp +++ b/C++/src/Alerter.cpp @@ -22,17 +22,13 @@ namespace larcfm { -Alerter::Alerter() { - id_ = "default"; -} - bool Alerter::isValid() const { return !levels_.empty(); } -Alerter::Alerter(const std::string& id) { - id_ = equals(id, "") ? "default" : id; -} +Alerter::Alerter() : id_("default") {} + +Alerter::Alerter(const std::string& id) : id_(id) {} const Alerter& Alerter::INVALID() { static Alerter a; @@ -369,7 +365,7 @@ const Alerter& Alerter::Buffered_DWC_Phase_I() { * alerting time, and lookahead time. The single bands region is NEAR */ Alerter Alerter::SingleBands(const Detection3D* detector, double alerting_time, double lookahead_time, - const std::string name) { + const std::string& name) { Alerter alerter(name); alerter.addLevel(AlertThresholds(detector,alerting_time,lookahead_time,BandsRegion::NEAR)); return alerter; diff --git a/C++/src/BandsRange.cpp b/C++/src/BandsRange.cpp index 09b8568e..33f46d13 100644 --- a/C++/src/BandsRange.cpp +++ b/C++/src/BandsRange.cpp @@ -11,10 +11,7 @@ namespace larcfm { -BandsRange::BandsRange(const Interval& i, BandsRegion::Region r) { - interval = i; - region = r; -} +BandsRange::BandsRange(const Interval& i, BandsRegion::Region r) : interval(i), region(r) {} // NONE's when in recovery, become RECOVERY BandsRegion::Region BandsRange::resolution_region(BandsRegion::Region region, bool recovery) { diff --git a/C++/src/CDCylinder.cpp b/C++/src/CDCylinder.cpp index e3571d3c..1bcd30df 100644 --- a/C++/src/CDCylinder.cpp +++ b/C++/src/CDCylinder.cpp @@ -27,35 +27,34 @@ namespace larcfm { /** * Instantiates a new CD3D object. */ -CDCylinder::CDCylinder(const std::string& s) { - D_ = Units::from("nmi", 5.0); - H_ = Units::from("ft", 1000.0); +CDCylinder::CDCylinder(const std::string& s) : + D_(Units::from("nmi", 5.0)), + H_(Units::from("ft", 1000.0)), + id(s) { units_["D"] = "nmi"; units_["H"] = "ft"; - id = s; } -CDCylinder::CDCylinder(const CDCylinder& cdc) { - D_ = cdc.D_; - H_ = cdc.H_; - units_ = cdc.units_; - id = cdc.id; -} +CDCylinder::CDCylinder(const CDCylinder& cdc) : + D_(cdc.D_), + H_(cdc.H_), + units_(cdc.units_), + id(cdc.id) {} -CDCylinder::CDCylinder(double d, double h) { - D_ = std::abs(d); - H_ = std::abs(h); +CDCylinder::CDCylinder(double d, double h) : + D_(std::abs(d)), + H_(std::abs(h)), + id("") { units_["D"] = "m"; units_["H"] = "m"; - id = ""; } -CDCylinder::CDCylinder(double d, const std::string& dunit, double h, const std::string& hunit) { - D_ = Units::from(dunit,std::abs(d)); - H_ = Units::from(hunit,std::abs(h)); +CDCylinder::CDCylinder(double d, const std::string& dunit, double h, const std::string& hunit) : + D_(Units::from(dunit,std::abs(d))), + H_(Units::from(hunit,std::abs(h))), + id("") { units_["D"] = dunit; units_["H"] = hunit; - id = ""; } CDCylinder CDCylinder::make(double distance, const std::string& dUnits, double height, const std::string& hUnits) { diff --git a/C++/src/ConflictData.cpp b/C++/src/ConflictData.cpp index 85211cf5..22a3be68 100644 --- a/C++/src/ConflictData.cpp +++ b/C++/src/ConflictData.cpp @@ -17,31 +17,31 @@ namespace larcfm { -ConflictData::ConflictData(double t_in, double t_out, double t_crit, double d_crit, const Vect3& s, const Vect3& v) : LossData(t_in, t_out) { - time_crit = t_crit; - dist_crit = d_crit; - s_ = s; - v_ = v; -} +ConflictData::ConflictData(double t_in, double t_out, double t_crit, double d_crit, const Vect3& s, const Vect3& v) : + LossData(t_in, t_out), + time_crit(t_crit), + dist_crit(d_crit), + s_(s), + v_(v) {} + +ConflictData::ConflictData() : + time_crit(PINFINITY), + dist_crit(PINFINITY), + s_(Vect3::INVALID()), + v_(Vect3::INVALID()) {} -ConflictData::ConflictData() { - time_crit = PINFINITY; - dist_crit = PINFINITY; - s_ = Vect3::INVALID(); - v_ = Vect3::INVALID(); -} const ConflictData& ConflictData::EMPTY() { static ConflictData tmp; return tmp; } -ConflictData::ConflictData(const LossData& ld, double t_crit, double d_crit, const Vect3& s, const Vect3& v) : LossData(ld) { - time_crit = t_crit; - dist_crit = d_crit; - s_ = s; - v_ = v; -} +ConflictData::ConflictData(const LossData& ld, double t_crit, double d_crit, const Vect3& s, const Vect3& v) : + LossData(ld), + time_crit(t_crit), + dist_crit(d_crit), + s_(s), + v_(v) {} /** * Returns internal vector representation of relative aircraft position. diff --git a/C++/src/CriteriaCore.cpp b/C++/src/CriteriaCore.cpp index 841d9da7..f10a5283 100644 --- a/C++/src/CriteriaCore.cpp +++ b/C++/src/CriteriaCore.cpp @@ -45,7 +45,7 @@ bool gt(double a,double b,double e) { e < 0 && sq(a)*b < sq(e); } -int CriteriaCore::verticalCoordination(const Vect3& s, const Vect3& vo, const Vect3& vi, double D, double H, std::string ownship, std::string traffic) { +int CriteriaCore::verticalCoordination(const Vect3& s, const Vect3& vo, const Vect3& vi, double D, double H, const std::string& ownship, const std::string& traffic) { if (CD3D::LoS(s,D,H)) { return verticalCoordinationLoS(s,vo,vi,ownship,traffic); } else { @@ -54,7 +54,7 @@ int CriteriaCore::verticalCoordination(const Vect3& s, const Vect3& vo, const Ve } } -int CriteriaCore::verticalCoordinationConflict(const Vect3& s, const Vect3& v, double D, std::string ownship, std::string traffic) { +int CriteriaCore::verticalCoordinationConflict(const Vect3& s, const Vect3& v, double D, const std::string& ownship, const std::string& traffic) { Vect2 s2 = s.vect2(); Vect2 v2 = v.vect2(); double a = v2.sqv(); @@ -71,7 +71,7 @@ int CriteriaCore::verticalCoordinationConflict(const Vect3& s, const Vect3& v, d return 1; } -int CriteriaCore::verticalCoordinationLoS(const Vect3& s, const Vect3& vo, const Vect3& vi, std::string ownship, std::string traffic) { +int CriteriaCore::verticalCoordinationLoS(const Vect3& s, const Vect3& vo, const Vect3& vi, const std::string& ownship, const std::string& traffic) { int epsv; epsv = losr_vs_dir(s,vo,vi,ACCoRDConfig::NMAC_D, ACCoRDConfig::NMAC_H,ownship,traffic); return epsv; @@ -152,7 +152,7 @@ Vect3 CriteriaCore::vertical_decision_vect(const Vect3& s, const Vect3& vo, cons // Compute an absolute repulsive vertical direction int CriteriaCore::losr_vs_dir(const Vect3& s, const Vect3& vo, const Vect3& vi, - double caD, double caH, std::string ownship, std::string traffic) { + double caD, double caH, const std::string& ownship, const std::string& traffic) { int rtn = breakSymmetry(vertical_decision_vect(s,vo,vi,caD,caH),ownship,traffic); return rtn; } @@ -225,10 +225,8 @@ bool CriteriaCore::verticalRepulsiveCriterion(const Vect3& s, const Vect3& vo, c } /** Perform a symmetry calculation */ -int CriteriaCore::breakSymmetry(const Vect3& s, std::string ownship, std::string traffic) { - if (Util::almost_equals(s.z,0)) { - reverse(ownship.begin(), ownship.end()); - reverse(traffic.begin(), traffic.end()); +int CriteriaCore::breakSymmetry(const Vect3& s, const std::string& ownship, const std::string& traffic) { + if (Util::almost_equals(s.z,0)) { return Util::less_or_equal(ownship, traffic) ? 1 : -1; } else if (s.z > 0) { return 1; @@ -237,15 +235,15 @@ int CriteriaCore::breakSymmetry(const Vect3& s, std::string ownship, std::string } } -static bool trkChanged(Velocity vo, Velocity nvo) { +static bool trkChanged(const Velocity& vo, const Velocity& nvo) { return std::abs(vo.trk() - nvo.trk()) > Units::from("deg",0.001); } -static bool gsChanged(Velocity vo, Velocity nvo) { +static bool gsChanged(const Velocity& vo, const Velocity& nvo) { return std::abs(vo.gs() - nvo.gs()) > Units::from("kn",0.001); } -static bool vsChanged(Velocity vo, Velocity nvo) { +static bool vsChanged(const Velocity& vo, const Velocity& nvo) { return std::abs(vo.vs() - nvo.vs()) > Units::from("fpm",0.001); } diff --git a/C++/src/Daidalus.cpp b/C++/src/Daidalus.cpp index 430f162b..438af7a5 100644 --- a/C++/src/Daidalus.cpp +++ b/C++/src/Daidalus.cpp @@ -850,7 +850,7 @@ const Alerter& Daidalus::getAlerterAt(int i) const { /** * Return index of alerter with a given name. Return 0 if it doesn't exist */ -int Daidalus::getAlerterIndex(std::string id) const { +int Daidalus::getAlerterIndex(const std::string& id) const { return core_.parameters.getAlerterIndex(id); } @@ -1231,7 +1231,7 @@ double Daidalus::getVerticalRate() const { /** * @return the vertical climb/descend rate for altitude bands in specified units [u]. */ -double Daidalus::getVerticalRate(std::string u) const { +double Daidalus::getVerticalRate(const std::string& u) const { return core_.parameters.getVerticalRate(u); } @@ -1611,7 +1611,7 @@ void Daidalus::setBelowRelativeHorizontalSpeed(double val) { * Set horizontal speed in given units (below current value) for the * computation of relative bands */ -void Daidalus::setBelowRelativeHorizontalSpeed(double val,std::string u) { +void Daidalus::setBelowRelativeHorizontalSpeed(double val,const std::string& u) { core_.parameters.setBelowRelativeHorizontalSpeed(val,u); reset(); } @@ -2371,7 +2371,7 @@ double Daidalus::getHorizontalVelocityZDistance() const { /** * @return Distance (in given units) at which h_vel_z_score scales from min to max as range decreases */ -double Daidalus::getHorizontalVelocityZDistance(std::string u) const { +double Daidalus::getHorizontalVelocityZDistance(const std::string& u) const { return core_.parameters.getHorizontalVelocityZDistance(u); } @@ -2435,7 +2435,7 @@ double Daidalus::getHorizontalContourThreshold() const { * the left/right of current aircraft direction. A value of 0 means only conflict contours. * A value of pi means all contours. */ -double Daidalus::getHorizontalContourThreshold(std::string u) const { +double Daidalus::getHorizontalContourThreshold(const std::string& u) const { return core_.parameters.getHorizontalContourThreshold(u); } diff --git a/C++/src/DaidalusFileWalker.cpp b/C++/src/DaidalusFileWalker.cpp index bcb13393..b812a457 100644 --- a/C++/src/DaidalusFileWalker.cpp +++ b/C++/src/DaidalusFileWalker.cpp @@ -14,8 +14,7 @@ namespace larcfm { -DaidalusFileWalker::DaidalusFileWalker(const std::string& filename) { - sr_ = SequenceReader(filename); +DaidalusFileWalker::DaidalusFileWalker(const std::string& filename) : sr_(SequenceReader(filename)) { init(); } diff --git a/C++/src/Detection3DParameterWriter.cpp b/C++/src/Detection3DParameterWriter.cpp index f43c730d..be1a9640 100644 --- a/C++/src/Detection3DParameterWriter.cpp +++ b/C++/src/Detection3DParameterWriter.cpp @@ -20,11 +20,11 @@ namespace larcfm { -ParameterData Detection3DParameterWriter::writeCoreDetection(std::vector dlist, Detection3D* det, Detection3D* res) { +ParameterData Detection3DParameterWriter::writeCoreDetection(std::vector& dlist, Detection3D* det, Detection3D* res) { return writeCoreDetection(dlist, det, res, false); } -ParameterData Detection3DParameterWriter::writeCoreDetection(std::vector dlist, Detection3D* det, Detection3D* res, bool ordered) { +ParameterData Detection3DParameterWriter::writeCoreDetection(std::vector& dlist, Detection3D* det, Detection3D* res, bool ordered) { // make sure det and res are in the list, if necessary if (det != NULL && std::find(dlist.begin(), dlist.end(),det) == dlist.end()) { dlist.push_back(det); diff --git a/C++/src/FixedAircraftUrgencyStrategy.cpp b/C++/src/FixedAircraftUrgencyStrategy.cpp index 2c480565..8d8cb323 100644 --- a/C++/src/FixedAircraftUrgencyStrategy.cpp +++ b/C++/src/FixedAircraftUrgencyStrategy.cpp @@ -15,15 +15,11 @@ namespace larcfm { -FixedAircraftUrgencyStrategy::FixedAircraftUrgencyStrategy() { - ac_ = TrafficState::INVALID().getId(); -} +FixedAircraftUrgencyStrategy::FixedAircraftUrgencyStrategy() : ac_(TrafficState::INVALID().getId()) {} -FixedAircraftUrgencyStrategy::FixedAircraftUrgencyStrategy(const std::string& id) { - ac_ = id; -} +FixedAircraftUrgencyStrategy::FixedAircraftUrgencyStrategy(const std::string& id) : ac_(id) {} -std::string FixedAircraftUrgencyStrategy::getFixedAircraftId() const { +const std::string& FixedAircraftUrgencyStrategy::getFixedAircraftId() const { return ac_; } diff --git a/C++/src/GreatCircle.cpp b/C++/src/GreatCircle.cpp index f5ef8ac3..39385c56 100644 --- a/C++/src/GreatCircle.cpp +++ b/C++/src/GreatCircle.cpp @@ -368,7 +368,7 @@ LatLonAlt GreatCircle::linear_gcgs(const LatLonAlt& p1, const LatLonAlt& p2, con return interpolate_impl(p1, p2, d, f, p1.alt() + v.z()*t); } -LatLonAlt GreatCircle::linear_gc(LatLonAlt p1, LatLonAlt p2, double d) { +LatLonAlt GreatCircle::linear_gc(const LatLonAlt& p1, const LatLonAlt& p2, double d) { //return GreatCircle.linear_initial(p1, initial_course(p1,p2), d); double dist = angular_distance(p1,p2); double f = angle_from_distance(d)/dist; diff --git a/C++/src/Kinematics.cpp b/C++/src/Kinematics.cpp index 5af83a21..fe059443 100644 --- a/C++/src/Kinematics.cpp +++ b/C++/src/Kinematics.cpp @@ -139,7 +139,7 @@ std::pair Kinematics::linear(const std::pair& sv return linear(sv0.first, sv0.second, t); } -std::pair Kinematics::linear(Vect3 so, Velocity vo, double t) { +std::pair Kinematics::linear(const Vect3& so, const Velocity& vo, double t) { return std::pair(so.linear(vo.vect3(),t),vo); } @@ -634,7 +634,7 @@ bool Kinematics::testLoSGs(const Vect3& so, const Velocity& vo, const Velocity& * Return the elevation angle (alternatively the negative glide-slope angle) for a climb (descent) * @return elevation angle [radians] */ -double Kinematics::elevationAngle(Velocity v) { +double Kinematics::elevationAngle(const Velocity& v) { return Util::atan2_safe(v.vs(), v.gs()); } @@ -1185,7 +1185,7 @@ std::pair Kinematics::vsLevelOut(const std::pairfirst; std::string keylc = toLowerCase(key); - if (keylc.find(prefixlc) == 0) { + if (startsWith(keylc,prefixlc)) { p.parameters[key.substr(prefix.length())] = pos->second; } } @@ -75,7 +74,7 @@ ParameterData ParameterData::removeKeysWithPrefix(const std::string& prefix) con for (paramtype::const_iterator pos = parameters.begin(); pos != parameters.end(); ++pos) { std::string key = pos->first; std::string keylc = toLowerCase(key); - if (keylc.find(prefixlc) != 0) { + if (startsWith(keylc,prefixlc)) { p.parameters[key] = pos->second; } } diff --git a/C++/src/Position.cpp b/C++/src/Position.cpp index 89f537b2..e8396bb2 100644 --- a/C++/src/Position.cpp +++ b/C++/src/Position.cpp @@ -495,7 +495,7 @@ bool Position::LoS(const Position& p2, double D, double H) { return (distH < D && distV < H); } -bool Position::collinear(Position p1, Position p2) const { +bool Position::collinear(const Position& p1, const Position& p2) const { if (latlon) return GreatCircle::collinear(lla(),p1.lla(),p2.lla()); else diff --git a/C++/src/Projection.cpp b/C++/src/Projection.cpp index c4c61061..75c8e6cf 100644 --- a/C++/src/Projection.cpp +++ b/C++/src/Projection.cpp @@ -56,7 +56,7 @@ namespace larcfm { void Projection::setProjectionType(ProjectionType t) { } - ProjectionType Projection::getProjectionTypeFromString(std::string s) { + ProjectionType Projection::getProjectionTypeFromString(const std::string& s) { ProjectionType p = UNKNOWN_PROJECTION; if (toLowerCase(s).compare("simple") == 0) { p = SIMPLE; diff --git a/C++/src/SeparatedInput.cpp b/C++/src/SeparatedInput.cpp index 2d9b76a3..9b76c171 100644 --- a/C++/src/SeparatedInput.cpp +++ b/C++/src/SeparatedInput.cpp @@ -40,68 +40,60 @@ SeparatedInput::SeparatedInputException::SeparatedInputException( } SeparatedInput::SeparatedInput() : - error("SeparatedInput") { - header = false; - bunits = false; - first_bunits = false; - caseSensitive = true; - parameters = ParameterData(); - patternStr = Constants::wsPatternBase; - reader = 0; - linenum = 0; - fixed_width = false; - quoteCharDefined = false; - quoteCharacter = '"'; // not needed, just to eliminate warnings - preambleImage = ""; -} + error("SeparatedInput"), + reader(0), + header(false), + bunits(false), + first_bunits(false), + caseSensitive(true), + linenum(0), + patternStr(Constants::wsPatternBase), + fixed_width(false), + quoteCharacter('"'), // not needed, just to eliminate warnings + quoteCharDefined(false), + parameters(ParameterData()), + preambleImage("") {} // fs must already be opened!!! SeparatedInput::SeparatedInput(std::istream* ins) : - error("SeparatedInput") { - reader = ins; - header = false; - bunits = false; - first_bunits = false; - caseSensitive = true; + error("SeparatedInput"), + reader(ins), + header(false), + bunits(false), + first_bunits(false), + caseSensitive(true), + linenum(0), + patternStr(Constants::wsPatternBase), + fixed_width(false), + quoteCharacter('"'), // not needed, just to eliminate warnings + quoteCharDefined(false), + parameters(ParameterData()), + preambleImage("") { header_str.reserve(10); // note: reserve() is appropriate because we exclusively use push_back to populate the vectors units_str.reserve(10); units_factor.reserve(10); line_str.reserve(10); - linenum = 0; - patternStr = Constants::wsPatternBase; - fixed_width = false; - parameters = ParameterData(); - quoteCharDefined = false; - quoteCharacter = '"'; // not needed, just to eliminate warnings - preambleImage = ""; - } // This should never be used, it should exit SeparatedInput::SeparatedInput(const SeparatedInput& x) : - error("SeparatedInputError") { - error = x.error; - reader = x.reader; - header = x.header; - bunits = x.bunits; - first_bunits = x.first_bunits; - caseSensitive = x.caseSensitive; - header_str = x.header_str; - units_str = x.units_str; - units_factor = x.units_factor; - line_str = x.line_str; - linenum = x.linenum; - patternStr = x.patternStr; - parameters = x.parameters; - fixed_width = x.fixed_width; - quoteCharDefined = x.quoteCharDefined; - quoteCharacter = x.quoteCharacter; - preambleImage = x.preambleImage; - - - // std::cout << "SeparatedInput copy constructor failure" << std::endl; - // exit(1); -} + error(x.error), + reader(x.reader), + header(x.header), + bunits(x.bunits), + first_bunits(x.first_bunits), + caseSensitive(x.caseSensitive), + linenum(x.linenum), + patternStr(x.patternStr), + fixed_width(x.fixed_width), + quoteCharacter(x.quoteCharacter), + quoteCharDefined(x.quoteCharDefined), + parameters(x.parameters), + preambleImage(x.preambleImage), + header_str(x.header_str), + units_str(x.units_str), + units_factor(x.units_factor), + line_str(x.line_str) {} // This should never be used, it should exit SeparatedInput& SeparatedInput::operator=(const SeparatedInput& x) { @@ -133,7 +125,7 @@ void SeparatedInput::setColumnDelimiters(const std::string& delim) { patternStr = delim; } -std::string SeparatedInput::getColumnDelimiters() const { +const std::string& SeparatedInput::getColumnDelimiters() const { return patternStr; } @@ -340,7 +332,7 @@ bool SeparatedInput::readLine() { // Remove comments from line size_t comment_num = str.find('#'); if (comment_num != string::npos) { //if (comment_num >= 0) { - str = str.substr(0,comment_num); + str.resize(comment_num); } trim(str); // Skip empty lines @@ -420,7 +412,7 @@ int SeparatedInput::lineNumber() const { return linenum; } -bool SeparatedInput::process_preamble(string str) { +bool SeparatedInput::process_preamble(const string& str) { vector fields = split(str, "="); // C++ version of split doesn't need the "-2" parameter that java needs. // parameter keys are lower case only diff --git a/C++/src/SeparatedOutput.cpp b/C++/src/SeparatedOutput.cpp index 448c4066..f37de33f 100644 --- a/C++/src/SeparatedOutput.cpp +++ b/C++/src/SeparatedOutput.cpp @@ -351,7 +351,7 @@ namespace larcfm { /** * The value to be displayed if a column is "skipped". Empty values are only added inside a line, not at the end. */ - void SeparatedOutput::setEmptyValue(std::string e) { + void SeparatedOutput::setEmptyValue(const std::string& e) { empty = e; } @@ -428,7 +428,7 @@ namespace larcfm { // } } - void SeparatedOutput::print_line(std::vector vals) { // throws IOException { + void SeparatedOutput::print_line(const std::vector& vals) { // throws IOException { if (vals.size() == 0) { return; } @@ -441,7 +441,7 @@ namespace larcfm { } - std::string SeparatedOutput::toString() { + std::string SeparatedOutput::toString() const { std::string str = "SeparateOutput: "; str += "\n"; str += " header_str:"; diff --git a/C++/src/TCAS3D.cpp b/C++/src/TCAS3D.cpp index 2fc0baca..a20d2af2 100644 --- a/C++/src/TCAS3D.cpp +++ b/C++/src/TCAS3D.cpp @@ -22,15 +22,9 @@ namespace larcfm { -TCAS3D::TCAS3D() { - table_ = TCASTable::make_TCASII_Table(true); - id = ""; -} +TCAS3D::TCAS3D() : table_(TCASTable::make_TCASII_Table(true)), id("") {} -TCAS3D::TCAS3D(const TCASTable& tab) { - table_ = tab; - id = ""; -} +TCAS3D::TCAS3D(const TCASTable& tab) : table_(tab), id("") {} /** * @return one static TCAS3D diff --git a/C++/src/Util.cpp b/C++/src/Util.cpp index 101f6e44..1a3e76b0 100644 --- a/C++/src/Util.cpp +++ b/C++/src/Util.cpp @@ -404,7 +404,7 @@ double Util::to_180(double deg) { } -bool Util::less_or_equal(std::string s1, std::string s2) { +bool Util::less_or_equal(const std::string& s1, const std::string& s2) { if (s1.compare(s2) >= 0) return true; return false; } diff --git a/C++/src/format.cpp b/C++/src/format.cpp index ec77345f..f20aaa64 100644 --- a/C++/src/format.cpp +++ b/C++/src/format.cpp @@ -364,34 +364,33 @@ string Farray(std::string const v[], int sz) { } -string FmVec(Vect2 v) { +string FmVec(const Vect2& v) { return "("+Fm16(v.x)+","+Fm16(v.y)+")"; } -string FmVec(Vect3 v) { +string FmVec(const Vect3& v) { return "("+Fm16(v.x)+","+Fm16(v.y)+","+Fm16(v.z)+")"; } -string padLeft(string s, int n) { +string padLeft(const string& s, int n) { string pad = ""; - for (int i = 0; i < n-(int)s.size(); i++) { - pad = pad + " "; + for (size_t i = 0; i < n-s.size(); i++) { + pad += " "; } return pad+s; } -string padRight(string s, int n) { - //return string.format("%1$-" + n + "s", s); - while ((int)s.length() < n) { - s = s + " "; +string padRight(const string& s, int n) { + string pad = ""; + for (size_t i = 0; i < n-s.size(); i++) { + pad += " "; } - return s; + return pad+s; } - void fpln(const string& str) { cout << str << endl; cout.flush(); diff --git a/Java/src/gov/nasa/larcfm/ACCoRD/CriteriaCore.java b/Java/src/gov/nasa/larcfm/ACCoRD/CriteriaCore.java index 954b1ecc..1f787cc0 100644 --- a/Java/src/gov/nasa/larcfm/ACCoRD/CriteriaCore.java +++ b/Java/src/gov/nasa/larcfm/ACCoRD/CriteriaCore.java @@ -378,10 +378,6 @@ public static boolean verticalRepulsiveCriterion(Vect3 s, Vect3 vo, Vect3 vi, Ve /** Perform a symmetry calculation */ private static int breakSymmetry(Vect3 s, String ownship, String traffic) { if (Util.almost_equals(s.z,0)) { - StringBuffer own = new StringBuffer(ownship); - ownship = own.reverse().toString(); - StringBuffer traf = new StringBuffer(traffic); - traffic = traf.reverse().toString(); return Util.less_or_equal(ownship,traffic) ? 1 : -1; } else if (s.z > 0) { return 1; diff --git a/Java/src/gov/nasa/larcfm/Util/ParameterData.java b/Java/src/gov/nasa/larcfm/Util/ParameterData.java index cd743e1b..23239a4d 100644 --- a/Java/src/gov/nasa/larcfm/Util/ParameterData.java +++ b/Java/src/gov/nasa/larcfm/Util/ParameterData.java @@ -115,7 +115,7 @@ public ParameterData extractPrefix(String prefix) { p.unitCompatibility = unitCompatibility; for (Map.Entry entry : parameters.entrySet()) { String keylc = entry.getKey().toLowerCase(); - if (keylc.indexOf(prefixlc) == 0) { + if (keylc.startsWith(prefixlc)) { p.parameters.put(entry.getKey().substring(prefix.length()), ParameterEntry.make(entry.getValue())); // make sure this is a copy } }