Skip to content

Commit

Permalink
Added cppcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Munoz committed Sep 29, 2023
1 parent efbaed5 commit 0877e19
Show file tree
Hide file tree
Showing 42 changed files with 202 additions and 251 deletions.
2 changes: 2 additions & 0 deletions C++/.cppcheck-config/cppcheck-suppressions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
stlFindInsert:src/Detection3DParameterReader.cpp
stlFindInsert:src/SequenceReader.cpp
1 change: 1 addition & 0 deletions C++/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cppcheck-config
2 changes: 1 addition & 1 deletion C++/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions C++/include/AircraftState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;



Expand Down Expand Up @@ -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
*
Expand Down
6 changes: 3 additions & 3 deletions C++/include/Alerter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class Alerter : ParameterAcceptor {

public:

Alerter();

virtual ~Alerter() {}

static const Alerter& INVALID();

bool isValid() const;

Alerter();

Alerter(const std::string& id);

/**
Expand Down Expand Up @@ -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.,
Expand Down
5 changes: 3 additions & 2 deletions C++/include/CDCylinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ namespace larcfm {
class CDCylinder : public Detection3D {

private:
std::string id;
std::map<std::string,std::string> units_;

double D_;
double H_;
std::map<std::string,std::string> units_;
std::string id;

public:

Expand Down
8 changes: 5 additions & 3 deletions C++/include/ConflictData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions C++/include/CriteriaCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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?))
Expand Down Expand Up @@ -242,23 +242,21 @@ 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);

// caD and caH are the diameter and height of a collision avoidance zone, e.g., 350ft x 100 ft
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);

Expand All @@ -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);

};

Expand Down
10 changes: 5 additions & 5 deletions C++/include/Daidalus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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].
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions C++/include/Detection3DParameterWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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<Detection3D*> dlist, Detection3D* det, Detection3D* res);
static ParameterData writeCoreDetection(std::vector<Detection3D*>& 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)
* @param det detection instance -- this may be null
* @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<Detection3D*> dlist, Detection3D* det, Detection3D* res, bool ordered);
static ParameterData writeCoreDetection(std::vector<Detection3D*>& dlist, Detection3D* det, Detection3D* res, bool ordered);

/**
* This removes all standard core detection parameters from a ParameterData object
Expand Down
2 changes: 1 addition & 1 deletion C++/include/FixedAircraftUrgencyStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion C++/include/GreatCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);


/**
Expand Down
6 changes: 3 additions & 3 deletions C++/include/Kinematics.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class Kinematics {
static std::pair<Vect3,Velocity> linear(const std::pair<Vect3,Velocity>& sv0, double t);


static std::pair<Vect3,Velocity> linear(Vect3 so, Velocity vo, double t);
static std::pair<Vect3,Velocity> linear(const Vect3& so, const Velocity& vo, double t);



Expand Down Expand Up @@ -533,7 +533,7 @@ class Kinematics {
* @param v velocity
* @return elevation angle [radians]
*/
static double elevationAngle(Velocity v);
static double elevationAngle(const Velocity& v);


/**
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion C++/include/Position.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion C++/include/Projection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 15 additions & 24 deletions C++/include/SeparatedInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -308,39 +308,30 @@ namespace larcfm {


private:
std::istream* reader;

mutable ErrorLog error;
bool header; // header line read in
std::vector<std::string> header_str; // header line raw string
bool bunits; // units line read in
bool first_bunits; // units line read in
std::vector<std::string> units_str; // Units type
std::vector<double> units_factor; // Units conversion value
std::vector<std::string> 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<int> 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<std::string, Quad<std::string,double,std::string,bool> > paramtype;
// paramtype parameters;
std::vector<std::string> header_str; // header line raw string
std::vector<std::string> units_str; // Units type
std::vector<double> units_factor; // Units conversion value
std::vector<std::string> line_str; // raw line
std::vector<int> 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<std::string> processQuotes(const std::string& str) const;
Expand Down
6 changes: 3 additions & 3 deletions C++/include/SeparatedOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class SeparatedOutput : public ErrorReporter {
* The value to be displayed if a column is &quot;skipped&quot;. 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.
Expand Down Expand Up @@ -282,10 +282,10 @@ class SeparatedOutput : public ErrorReporter {
void flush();

private:
void print_line(std::vector<std::string> vals); // throws IOException;
void print_line(const std::vector<std::string>& vals); // throws IOException;

public:
std::string toString();
std::string toString() const;


// ErrorReporter Interface Methods
Expand Down
2 changes: 1 addition & 1 deletion C++/include/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions C++/include/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 0877e19

Please sign in to comment.