Skip to content

Commit

Permalink
Code improvements through clang tidy comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen committed Jul 25, 2024
1 parent 9746e5d commit c379241
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 44 deletions.
2 changes: 1 addition & 1 deletion ecal/core/include/ecal/config/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace eCAL

ECAL_API void InitConfigWithDefaultYaml();
ECAL_API void InitConfigWithDefaults();
ECAL_API void InitConfigFromFile(const std::string yaml_path_);
ECAL_API void InitConfigFromFile(const std::string& yaml_path_);

ECAL_API std::string GetYamlFilePath();

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/include/ecal/types/ecal_custom_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace eCAL
ECAL_API IpAddressV4& operator=(const std::string& ip_string_);
ECAL_API IpAddressV4& operator=(const char* ip_string_);
ECAL_API operator std::string();
ECAL_API bool operator==(const eCAL::Types::IpAddressV4 rhs) const;
ECAL_API bool operator==(const eCAL::Types::IpAddressV4& rhs) const;
ECAL_API friend bool operator==(eCAL::Types::IpAddressV4 lhs, const char* ip_string_);
ECAL_API friend bool operator==(const char* ip_string_, eCAL::Types::IpAddressV4 rhs);
ECAL_API friend bool operator==(eCAL::Types::IpAddressV4 lhs, const std::string& ip_string_);
Expand Down
18 changes: 9 additions & 9 deletions ecal/core/src/config/configuration_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ namespace eCAL
{
void YamlFileToConfig(const std::string& filename_, eCAL::Configuration& config_)
{
YAML::Node yaml = YAML::LoadFile(filename_);
const YAML::Node yaml = YAML::LoadFile(filename_);

MapConfiguration(yaml, config_);
};

void YamlStringToConfig(const std::string& yaml_string_, eCAL::Configuration& config_)
{
YAML::Node yaml = YAML::Load(yaml_string_);
const YAML::Node yaml = YAML::Load(yaml_string_);

MapConfiguration(yaml, config_);
};

bool ConfigToYamlFile(const std::string& file_name_, const eCAL::Configuration& config_)
{
YAML::Node node(config_);
const YAML::Node node(config_);
std::ofstream file(file_name_);
if (file.is_open())
{
Expand All @@ -52,22 +52,22 @@ namespace eCAL
void MergeYamlNodes(YAML::Node& base, const YAML::Node& other)
{
std::stack<std::pair<YAML::Node, YAML::Node>> nodes;
nodes.push(std::make_pair(base, other));
nodes.emplace(std::make_pair(base, other));

while (!nodes.empty())
{
std::pair<YAML::Node, YAML::Node> nodePair = nodes.top();
const std::pair<YAML::Node, YAML::Node> nodePair = nodes.top();
nodes.pop();

YAML::Node baseNode = nodePair.first;
YAML::Node otherNode = nodePair.second;

for (YAML::const_iterator it = otherNode.begin(); it != otherNode.end(); ++it)
{
YAML::Node key = it->first;
YAML::Node value = it->second;
const YAML::Node key = it->first;
const YAML::Node value = it->second;

std::string key_as_string = "";
std::string key_as_string;

switch (key.Type())
{
Expand All @@ -83,7 +83,7 @@ namespace eCAL
{
if (value.IsMap() && baseNode[key_as_string].IsMap())
{
nodes.push(std::make_pair(baseNode[key_as_string], value)); // Push nested nodes to stack
nodes.emplace(baseNode[key_as_string], value); // Push nested nodes to stack
}
else
{
Expand Down
36 changes: 18 additions & 18 deletions ecal/core/src/config/configuration_to_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace YAML
{
// create excluding filter list
char filter_mask = log_level_none;
for (auto& it : filter_)
for (const auto& it : filter_)
{
if (it == "all") filter_mask |= log_level_all;
if (it == "info") filter_mask |= log_level_info;
Expand All @@ -41,27 +41,27 @@ namespace YAML
std::vector<std::string> LogLevelToVector(eCAL_Logging_Filter filter_mask)
{
std::vector<std::string> filter;
if (filter_mask & log_level_all) filter.push_back("all");
if (filter_mask & log_level_info) filter.push_back("info");
if (filter_mask & log_level_warning)filter.push_back("warning");
if (filter_mask & log_level_error) filter.push_back("error");
if (filter_mask & log_level_fatal) filter.push_back("fatal");
if (filter_mask & log_level_debug1) filter.push_back("debug1");
if (filter_mask & log_level_debug2) filter.push_back("debug2");
if (filter_mask & log_level_debug3) filter.push_back("debug3");
if (filter_mask & log_level_debug4) filter.push_back("debug4");
if ((filter_mask & log_level_all) != 0) filter.emplace_back("all");
if ((filter_mask & log_level_info) != 0) filter.emplace_back("info");
if ((filter_mask & log_level_warning) != 0) filter.emplace_back("warning");
if ((filter_mask & log_level_error) != 0) filter.emplace_back("error");
if ((filter_mask & log_level_fatal) != 0) filter.emplace_back("fatal");
if ((filter_mask & log_level_debug1) != 0) filter.emplace_back("debug1");
if ((filter_mask & log_level_debug2) != 0) filter.emplace_back("debug2");
if ((filter_mask & log_level_debug3) != 0) filter.emplace_back("debug3");
if ((filter_mask & log_level_debug4) != 0) filter.emplace_back("debug4");

return filter;
}

eCAL::Publisher::Configuration::LayerPriorityVector transformLayerStrToEnum(const std::vector<std::string>& string_vector_)
{
eCAL::Publisher::Configuration::LayerPriorityVector layer_priority_vector;
for (auto& layer_as_string : string_vector_)
for (const auto& layer_as_string : string_vector_)
{
if (layer_as_string == "shm") layer_priority_vector.push_back(eCAL::TLayer::tlayer_shm);
if (layer_as_string == "udp") layer_priority_vector.push_back(eCAL::TLayer::tlayer_udp_mc);
if (layer_as_string == "tcp") layer_priority_vector.push_back(eCAL::TLayer::tlayer_tcp);
if (layer_as_string == "shm") layer_priority_vector.emplace_back(eCAL::TLayer::tlayer_shm);
if (layer_as_string == "udp") layer_priority_vector.emplace_back(eCAL::TLayer::tlayer_udp_mc);
if (layer_as_string == "tcp") layer_priority_vector.emplace_back(eCAL::TLayer::tlayer_tcp);
}

return layer_priority_vector;
Expand All @@ -70,18 +70,18 @@ namespace YAML
std::vector<std::string> transformLayerEnumToStr(const eCAL::Publisher::Configuration::LayerPriorityVector& enum_vector_)
{
std::vector<std::string> layer_priority_vector;
for (auto& layer_as_enum : enum_vector_)
for (const auto& layer_as_enum : enum_vector_)
{
switch (layer_as_enum)
{
case eCAL::TLayer::tlayer_shm:
layer_priority_vector.push_back("shm");
layer_priority_vector.emplace_back("shm");
break;
case eCAL::TLayer::tlayer_udp_mc:
layer_priority_vector.push_back("udp");
layer_priority_vector.emplace_back("udp");
break;
case eCAL::TLayer::tlayer_tcp:
layer_priority_vector.push_back("tcp");
layer_priority_vector.emplace_back("tcp");
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/config/default_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <string>

std::string default_config = R"(# _____ _ _ ____ _ _
const std::string default_config = R"(# _____ _ _ ____ _ _
# | ____|___| (_)_ __ ___ ___ ___ / ___| / \ | |
# | _| / __| | | '_ \/ __|/ _ \ _____ / _ \ | / _ \ | |
# | |__| (__| | | |_) \__ \ __/ |_____| | __/ |___ / ___ \| |___
Expand Down
19 changes: 10 additions & 9 deletions ecal/core/src/config/ecal_config_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ namespace
// -----------------------------------------------------------
// precedence 0: relative path to executable
// -----------------------------------------------------------
std::string cwd_directory_path = cwdPath();
const std::string cwd_directory_path = cwdPath();

std::vector<std::string> ecal_default_paths = getEcalDefaultPaths();
ecal_default_paths.emplace(ecal_default_paths.begin(), cwd_directory_path);

std::string found_path = findValidConfigPath(ecal_default_paths, config_file_);
const std::string found_path = findValidConfigPath(ecal_default_paths, config_file_);

// check in case user provided whole path
if (found_path.empty())
Expand All @@ -196,9 +196,9 @@ namespace

namespace eCAL
{
void Configuration::InitConfigFromFile(const std::string yaml_path_)
void Configuration::InitConfigFromFile(const std::string& yaml_path_)
{
std::string yaml_path = checkForValidConfigFilePath(yaml_path_);
const std::string yaml_path = checkForValidConfigFilePath(yaml_path_);
if (!yaml_path.empty())
{
eCAL::Config::YamlFileToConfig(yaml_path, *this);
Expand Down Expand Up @@ -233,9 +233,9 @@ namespace eCAL
Init(args_);
}

void Configuration::Init(const std::vector<std::string>& arguments_)
void Configuration::Init(const std::vector<std::string>& args_)
{
Config::CmdParser parser(arguments_);
Config::CmdParser parser(args_);

command_line_arguments.user_yaml = parser.getUserIni();
command_line_arguments.dump_config = parser.getDumpConfig();
Expand Down Expand Up @@ -301,7 +301,7 @@ namespace eCAL
ECAL_API std::string GeteCALConfigPath()
{
// Check for first directory which contains the ini file.
std::vector<std::string> search_directories = getEcalDefaultPaths();
const std::vector<std::string> search_directories = getEcalDefaultPaths();

return findValidConfigPath(search_directories, ECAL_DEFAULT_CFG);
}
Expand All @@ -325,8 +325,9 @@ namespace eCAL
#endif /* ECAL_OS_WINDOWS */

#ifdef ECAL_OS_LINUX
const char *hdir;
if ((hdir = getenv("HOME")) == NULL) {
const char *hdir = nullptr;
hdir = getenv("HOME");
if (hdir == nullptr) {
hdir = getpwuid(getuid())->pw_dir;
}
home_path += hdir;
Expand Down
10 changes: 5 additions & 5 deletions ecal/core/src/types/ecal_custom_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ namespace eCAL

std::ostream& operator<<(std::ostream& os, const IpAddressV4& ipv4) { os << ipv4.Get(); return os; };

bool IpAddressV4::operator==(const eCAL::Types::IpAddressV4 other) const { return m_ip_address == other.Get(); };
bool operator==(eCAL::Types::IpAddressV4 lhs, const char* ip_string_) { return lhs.Get() == std::string(ip_string_); };
bool operator==(const char* ip_string_, eCAL::Types::IpAddressV4 rhs) { return rhs == ip_string_; };
bool operator==(eCAL::Types::IpAddressV4 lhs, const std::string& ip_string_) { return lhs.Get() == ip_string_; };
bool operator==(const std::string& ip_string_, eCAL::Types::IpAddressV4 rhs) { return rhs == ip_string_; };
bool IpAddressV4::operator==(const eCAL::Types::IpAddressV4& rhs) const { return m_ip_address == rhs.Get(); };
bool operator==(eCAL::Types::IpAddressV4 lhs, const char* ip_string_) { return lhs.Get() == std::string(ip_string_); };
bool operator==(const char* ip_string_, eCAL::Types::IpAddressV4 rhs) { return rhs == ip_string_; };
bool operator==(eCAL::Types::IpAddressV4 lhs, const std::string& ip_string_) { return lhs.Get() == ip_string_; };
bool operator==(const std::string& ip_string_, eCAL::Types::IpAddressV4 rhs) { return rhs == ip_string_; };
}
}

0 comments on commit c379241

Please sign in to comment.