Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting Changes to Scrimmage-20.04 #603

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 5 additions & 6 deletions include/scrimmage/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
// custom specialization of std::hash can be injected in namespace std
// see http://en.cppreference.com/w/cpp/utility/hash
namespace std {
template<> struct hash<scrimmage::ID> {
template <>
struct hash<scrimmage::ID> {
size_t operator()(scrimmage::ID const& id) const {
// assume up to 16 teams and 64 subswarms
// for a 32-bit int this leaves 16 bits (up to 65000 ids)
return id.team_id() &
(id.sub_swarm_id() << 4) &
(id.id() << 12);
return id.team_id() & (id.sub_swarm_id() << 4) & (id.id() << 12);
}
};
} // namespace std
} // namespace std

#endif // INCLUDE_SCRIMMAGE_HASH_H_
#endif // INCLUDE_SCRIMMAGE_HASH_H_
34 changes: 18 additions & 16 deletions include/scrimmage/autonomy/Autonomy.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#ifndef INCLUDE_SCRIMMAGE_AUTONOMY_AUTONOMY_H_
#define INCLUDE_SCRIMMAGE_AUTONOMY_AUTONOMY_H_

#include <scrimmage/fwd_decl.h>
#include <scrimmage/entity/EntityPlugin.h>
#include <scrimmage/fwd_decl.h>

#include <list>
#include <map>
Expand All @@ -51,28 +51,30 @@ class Autonomy : public EntityPlugin {
virtual bool step_autonomy(double t, double dt);
virtual bool posthumous(double t);
virtual void init();
bool ready() override { return true; }
virtual void init(std::map<std::string, std::string> &params);
bool ready() override {
return true;
}
virtual void init(std::map<std::string, std::string>& params);
void close(double t) override;
bool need_reset();

// getters/setters
StatePtr &desired_state();
StatePtr& desired_state();
void set_desired_state(StatePtr desired_state);

ContactMapPtr &get_contacts();
ContactMap &get_contacts_raw();
virtual void set_contacts(ContactMapPtr &contacts);
virtual void set_contacts_from_plugin(AutonomyPtr &ptr);
virtual void set_projection(std::shared_ptr<GeographicLib::LocalCartesian> &proj);
ContactMapPtr& get_contacts();
ContactMap& get_contacts_raw();
virtual void set_contacts(ContactMapPtr& contacts);
virtual void set_contacts_from_plugin(AutonomyPtr& ptr);
virtual void set_projection(std::shared_ptr<GeographicLib::LocalCartesian>& proj);

scrimmage::RTreePtr &rtree();
void set_rtree(scrimmage::RTreePtr &rtree);
scrimmage::RTreePtr& rtree();
void set_rtree(scrimmage::RTreePtr& rtree);

StatePtr &state();
virtual void set_state(StatePtr &state);
StatePtr& state();
virtual void set_state(StatePtr& state);

std::string &logging_msg();
std::string& logging_msg();

bool get_is_controlling();
void set_is_controlling(bool is_controlling);
Expand All @@ -90,5 +92,5 @@ class Autonomy : public EntityPlugin {

bool is_controlling_;
};
} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_AUTONOMY_AUTONOMY_H_
} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_AUTONOMY_AUTONOMY_H_
24 changes: 12 additions & 12 deletions include/scrimmage/common/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#ifndef INCLUDE_SCRIMMAGE_COMMON_ALGORITHM_H_
#define INCLUDE_SCRIMMAGE_COMMON_ALGORITHM_H_

#include <iterator>
#include <algorithm>
#include <iterator>
#include <unordered_set>

namespace scrimmage {
Expand All @@ -43,7 +43,7 @@ namespace scrimmage {
* This implementation assumes the first argument has an erase method.
*/
template <class ContainerType, class Predicate>
void remove_if(ContainerType &container, Predicate pred) {
void remove_if(ContainerType& container, Predicate pred) {
auto it = container.begin();
while (it != container.end()) {
it = pred(*it) ? container.erase(it) : std::next(it);
Expand All @@ -55,29 +55,29 @@ void remove_if(ContainerType &container, Predicate pred) {
* std::set_difference does not work on unordered_sets
*/
template <class T = std::unordered_set<int>>
std::unordered_set<T>
set_difference(const std::unordered_set<T> &container1, const std::unordered_set<T> &container2) {
std::unordered_set<T> set_difference(const std::unordered_set<T>& container1,
const std::unordered_set<T>& container2) {
std::unordered_set<T> out;
std::copy_if(container1.begin(), container1.end(), std::inserter(out, out.end()),
[&](const T &val) {return container2.count(val) == 0;});
[&](const T& val) { return container2.count(val) == 0; });
return out;
}

template <class T = std::unordered_set<int>>
std::unordered_set<T>
set_union(const std::unordered_set<T> &container1, const std::unordered_set<T> &container2) {
std::unordered_set<T> set_union(const std::unordered_set<T>& container1,
const std::unordered_set<T>& container2) {
std::unordered_set<T> out = container1;
out.insert(container2.begin(), container2.end());
return out;
}

template <class T = std::unordered_set<int>>
std::unordered_set<T>
set_intersection(const std::unordered_set<T> &container1, const std::unordered_set<T> &container2) {
std::unordered_set<T> set_intersection(const std::unordered_set<T>& container1,
const std::unordered_set<T>& container2) {
std::unordered_set<T> out;
std::copy_if(container1.begin(), container1.end(), std::inserter(out, out.end()),
[&](const T &val) {return container2.count(val) != 0;});
[&](const T& val) { return container2.count(val) != 0; });
return out;
}
} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_COMMON_ALGORITHM_H_
} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_COMMON_ALGORITHM_H_
15 changes: 8 additions & 7 deletions include/scrimmage/common/Battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@
namespace scrimmage {
class Battery {
public:
Battery() {}
Battery(const double &min, const double &max, const double &current);
void add_charge(const double &amount);
bool deplete(const double &amount);
Battery() {
}
Battery(const double& min, const double& max, const double& current);
void add_charge(const double& amount);
bool deplete(const double& amount);
bool is_full();
bool has_charge();
const double &current_charge();
const double& current_charge();
double charge_percentage();

protected:
double min_charge_ = 0;
double max_charge_ = 1;
double current_charge_ = 1;
};
} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_COMMON_BATTERY_H_
} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_COMMON_BATTERY_H_
43 changes: 24 additions & 19 deletions include/scrimmage/common/CSV.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
#define INCLUDE_SCRIMMAGE_COMMON_CSV_H_

#include <fstream>
#include <map>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <memory>

namespace scrimmage {

Expand All @@ -49,45 +49,50 @@ class CSV {

~CSV();

void set_column_headers(const Headers &headers, bool write = true);
void set_column_headers(const Headers& headers, bool write = true);

void set_column_headers(const std::string &headers, bool write = true);
void set_column_headers(const std::string& headers, bool write = true);

bool append(const Pairs &pairs, bool write = true, bool keep_in_memory = false);
bool append(const Pairs& pairs, bool write = true, bool keep_in_memory = false);

bool open_output(const std::string &filename,
std::ios_base::openmode mode = (std::ios_base::out |
std::ios_base::trunc));
bool open_output(const std::string& filename,
std::ios_base::openmode mode = (std::ios_base::out | std::ios_base::trunc));

bool output_is_open();

bool close_output();

bool to_csv(const std::string &filename);
bool to_csv(const std::string& filename);

bool read_csv(const std::string &filename, const bool& contains_header = true);
bool read_csv(const std::string& filename, const bool& contains_header = true);

bool read_csv_from_string(const std::string &str, const bool& contains_header = true);
bool read_csv_from_string(const std::string& str, const bool& contains_header = true);

void set_no_value_string(const std::string &str);
void set_no_value_string(const std::string& str);

std::string to_string() const;

size_t rows();

double at(int row, const std::string &header);
double at(int row, const std::string& header);

friend std::ostream& operator<<(std::ostream& os, const CSV& csv);

bool equals(const CSV& other);

// double parameters
void set_double_precision(int precision) { double_precision_ = precision; }
void set_double_fixed(bool is_fixed) { double_is_fixed_ = is_fixed; }
void set_double_scientific(bool is_scientific) { double_is_scientific_ = is_scientific; }
void set_double_precision(int precision) {
double_precision_ = precision;
}
void set_double_fixed(bool is_fixed) {
double_is_fixed_ = is_fixed;
}
void set_double_scientific(bool is_scientific) {
double_is_scientific_ = is_scientific;
}

protected:
std::list<std::string> get_csv_line_elements(const std::string &str);
std::list<std::string> get_csv_line_elements(const std::string& str);

void write_headers();

Expand Down Expand Up @@ -115,6 +120,6 @@ class CSV {
std::string rows_to_string() const;
std::string row_to_string(const int& i) const;
};
} // namespace scrimmage
} // namespace scrimmage

#endif // INCLUDE_SCRIMMAGE_COMMON_CSV_H_
#endif // INCLUDE_SCRIMMAGE_COMMON_CSV_H_
4 changes: 2 additions & 2 deletions include/scrimmage/common/ColorMaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ Color_t GetColor(double v, double vmin, double vmax);

int GetGray(Color_t c, double vmin, double vmax);

} // namespace scrimmage
} // namespace scrimmage

#endif // INCLUDE_SCRIMMAGE_COMMON_COLORMAPS_H_
#endif // INCLUDE_SCRIMMAGE_COMMON_COLORMAPS_H_
6 changes: 3 additions & 3 deletions include/scrimmage/common/DelayedTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#ifndef INCLUDE_SCRIMMAGE_COMMON_DELAYEDTASK_H_
#define INCLUDE_SCRIMMAGE_COMMON_DELAYEDTASK_H_

#include <utility>
#include <functional>
#include <utility>

namespace scrimmage {

Expand Down Expand Up @@ -64,5 +64,5 @@ class DelayedTask {
bool repeat_infinitely_;
int repeats_left_;
};
} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_COMMON_DELAYEDTASK_H_
} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_COMMON_DELAYEDTASK_H_
20 changes: 10 additions & 10 deletions include/scrimmage/common/ExponentialFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ namespace scrimmage {

class ExponentialFilter {
public:
ExponentialFilter();
explicit ExponentialFilter(double time_constant);
void set_time_constant(double time_constant);
double add_estimate(double estimate, double t);
double get_estimate() const;
ExponentialFilter();
explicit ExponentialFilter(double time_constant);
void set_time_constant(double time_constant);
double add_estimate(double estimate, double t);
double get_estimate() const;

protected:
double estimate_;
double time_last_estimate_;
double time_constant_;
double estimate_;
double time_last_estimate_;
double time_constant_;
};

} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_COMMON_EXPONENTIALFILTER_H_
} // namespace scrimmage
#endif // INCLUDE_SCRIMMAGE_COMMON_EXPONENTIALFILTER_H_
18 changes: 11 additions & 7 deletions include/scrimmage/common/FSMBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@
#include <scrimmage/autonomy/Autonomy.h>

#include <map>
#include <string>
#include <memory>
#include <string>

namespace scrimmage {
namespace common {
class FSMBehavior : public scrimmage::Autonomy {
public:
virtual void entered() {}
virtual void step_inactive() {}
virtual void exited() {}
virtual void entered() {
}
virtual void step_inactive() {
}
virtual void exited() {
}

protected:
};
using FSMBehaviorPtr = std::shared_ptr<FSMBehavior>;
} // namespace common
} // namespace scrimmage
} // namespace common
} // namespace scrimmage

#endif // INCLUDE_SCRIMMAGE_COMMON_FSMBEHAVIOR_H_
#endif // INCLUDE_SCRIMMAGE_COMMON_FSMBEHAVIOR_H_
26 changes: 14 additions & 12 deletions include/scrimmage/common/FileSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
#ifndef INCLUDE_SCRIMMAGE_COMMON_FILESEARCH_H_
#define INCLUDE_SCRIMMAGE_COMMON_FILESEARCH_H_

#include <unordered_map>
#include <list>
#include <memory>
#include <string>
#include <unordered_map>

namespace boost {
template <class T> class optional;
template <class T>
class optional;
}

namespace scrimmage {
Expand All @@ -57,20 +58,21 @@ class FileSearch {
*/
boost::optional<std::string> find_mission(std::string mission, bool verbose = false);

bool find_file(const std::string &filename, std::string ext,
const std::string &env_var, std::string &result, bool verbose = false);
void find_files(std::string env_var, const std::string &ext,
std::unordered_map<std::string, std::list<std::string>> &out,
bool verbose = false);
bool find_file(const std::string& filename, std::string ext, const std::string& env_var,
std::string& result, bool verbose = false);
void find_files(std::string env_var, const std::string& ext,
std::unordered_map<std::string, std::list<std::string>>& out,
bool verbose = false);

protected:
// cache_[env_var][ext][filename] = list of full paths to files with that filename
std::unordered_map<std::string,
std::unordered_map<std::string,
std::unordered_map<std::string, std::list<std::string>>>> cache_;
std::unordered_map<
std::string,
std::unordered_map<std::string, std::unordered_map<std::string, std::list<std::string>>>>
cache_;
};

using FileSearchPtr = std::shared_ptr<FileSearch>;
} // namespace scrimmage
} // namespace scrimmage

#endif // INCLUDE_SCRIMMAGE_COMMON_FILESEARCH_H_
#endif // INCLUDE_SCRIMMAGE_COMMON_FILESEARCH_H_
Loading