Skip to content

Commit

Permalink
address clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Feb 9, 2024
1 parent f2094d6 commit e64919e
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 79 deletions.
2 changes: 1 addition & 1 deletion bridge/src/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool service::shutdown(tateyama::framework::environment& env) {

static thread_local std::unique_ptr<Worker> worker_for_this_thread{};

bool service::operator()(std::shared_ptr<tateyama::api::server::request> req, std::shared_ptr<tateyama::api::server::response> res) {
bool service::operator()(std::shared_ptr<tateyama::api::server::request> req, std::shared_ptr<tateyama::api::server::response> res) { //NOLINT(readability-function-cognitive-complexity)
auto payload = req->payload();
std::istringstream ifs(std::string{payload});
boost::archive::binary_iarchive ia(ifs);
Expand Down
30 changes: 14 additions & 16 deletions bridge/src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ ERROR_CODE Worker::deploy_table(jogasaki::api::database& db, std::string_view st
return do_deploy_table(db, ia);
}

ERROR_CODE Worker::do_deploy_table(jogasaki::api::database& db, boost::archive::binary_iarchive& ia)
ERROR_CODE Worker::do_deploy_table(jogasaki::api::database& db, boost::archive::binary_iarchive& ia) //NOLINT(readability-function-cognitive-complexity)
{
std::size_t table_id;

std::size_t table_id{};
boost::property_tree::ptree table;
ia >> table_id;
ia >> table;
Expand Down Expand Up @@ -299,7 +298,7 @@ ERROR_CODE Worker::do_deploy_table(jogasaki::api::database& db, boost::archive::
bool use_default_length = false;
std::vector<boost::optional<int64_t>> data_length_vector;
get_data_length_vector(column, data_length_vector);
if (data_length_vector.size() == 0) {
if (data_length_vector.empty()) {
if(varying_value) { // no data_length field, use default
use_default_length = true;
}
Expand Down Expand Up @@ -334,15 +333,16 @@ ERROR_CODE Worker::do_deploy_table(jogasaki::api::database& db, boost::archive::
}
case manager::metadata::DataTypes::DataTypesId::NUMERIC: // decimal
{
std::optional<takatori::type::decimal::size_type> p{}, s{};
std::optional<takatori::type::decimal::size_type> p{};
std::optional<takatori::type::decimal::size_type> s{};
std::vector<boost::optional<int64_t>> data_length_vector;
get_data_length_vector(column, data_length_vector);
if (data_length_vector.size() == 0) {
if (data_length_vector.empty()) {
columns.emplace_back(yugawara::storage::column(name_value,
takatori::type::decimal(),
yugawara::variable::nullity(!is_not_null_value)));
} else {
if (data_length_vector.size() > 0) {
if (!data_length_vector.empty()) {
if (auto po = data_length_vector.at(0); po) {
p = po.value();
}
Expand Down Expand Up @@ -371,7 +371,7 @@ ERROR_CODE Worker::do_deploy_table(jogasaki::api::database& db, boost::archive::
return ERROR_CODE::INVALID_PARAMETER;
}
std::string dvs = default_expression_value.substr(1, index - 2);
struct tm tm;
struct tm tm{};
memset(&tm, 0, sizeof(struct tm));
if (auto ts = strptime(dvs.c_str(), "%Y-%m-%d", &tm); ts == nullptr) {
VLOG(log_debug) << "<-- INVALID_PARAMETER";
Expand All @@ -396,7 +396,7 @@ ERROR_CODE Worker::do_deploy_table(jogasaki::api::database& db, boost::archive::
return ERROR_CODE::INVALID_PARAMETER;
}
std::string dvs = default_expression_value.substr(1, index - 2);
struct tm tm;
struct tm tm{};
memset(&tm, 0, sizeof(struct tm));
if (auto ts = strptime(dvs.c_str(), "%H:%M:%S", &tm); ts != nullptr) {
std::string rem(ts);
Expand Down Expand Up @@ -424,7 +424,7 @@ ERROR_CODE Worker::do_deploy_table(jogasaki::api::database& db, boost::archive::
}
std::string dvs = default_expression_value.substr(1, index - 2);
std::string dvs_t = dvs.substr(0, index - 5);
struct tm tm;
struct tm tm{};
memset(&tm, 0, sizeof(struct tm));
if (auto ts = strptime(dvs_t.c_str(), "%H:%M:%S", &tm); ts != nullptr) {
auto td = stoi(dvs.substr(index - 5, index - 2)); // FIXME use time differnce value
Expand Down Expand Up @@ -454,7 +454,7 @@ ERROR_CODE Worker::do_deploy_table(jogasaki::api::database& db, boost::archive::
return ERROR_CODE::INVALID_PARAMETER;
}
std::string dvs = default_expression_value.substr(1, index - 2);
struct tm tm;
struct tm tm{};
memset(&tm, 0, sizeof(struct tm));
if (auto ts = strptime(dvs.c_str(), "%Y-%m-%d %H:%M:%S", &tm); ts != nullptr) {
std::string rem(ts);
Expand Down Expand Up @@ -482,7 +482,7 @@ ERROR_CODE Worker::do_deploy_table(jogasaki::api::database& db, boost::archive::
}
std::string dvs = default_expression_value.substr(1, index - 2);
std::string dvs_t = dvs.substr(0, index - 5);
struct tm tm;
struct tm tm{};
memset(&tm, 0, sizeof(struct tm));
if (auto ts = strptime(dvs_t.c_str(), "%Y-%m-%d %H:%M:%S", &tm); ts != nullptr) {
auto td = stoi(dvs.substr(index - 5, index - 2)); // FIXME use time differnce value
Expand Down Expand Up @@ -623,9 +623,7 @@ ERROR_CODE Worker::withdraw_table(jogasaki::api::database& db, std::string_view

ERROR_CODE Worker::do_withdraw_table(jogasaki::api::database& db, boost::archive::binary_iarchive& ia)
{
manager::metadata::ErrorCode error;
std::size_t table_id;

std::size_t table_id{};
boost::property_tree::ptree table;
ia >> table_id;
ia >> table;
Expand All @@ -652,7 +650,7 @@ ERROR_CODE Worker::do_withdraw_table(jogasaki::api::database& db, boost::archive
return ERROR_CODE::OK;
}

ERROR_CODE Worker::do_deploy_index(jogasaki::api::database& db, boost::archive::binary_iarchive& ia)
ERROR_CODE Worker::do_deploy_index(jogasaki::api::database& db, boost::archive::binary_iarchive& ia) //NOLINT(readability-function-cognitive-complexity)
{
std::string table_name;
boost::property_tree::ptree index;
Expand Down
4 changes: 2 additions & 2 deletions include/ogawayama/stub/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class Command {
public:
// C'tors
Command(std::string command_type_name, uint64_t object_id)
: command_type_name(command_type_name), object_id(object_id) {};
: command_type_name(std::move(command_type_name)), object_id(object_id) {};
std::string get_command_type_name() { return command_type_name; }
uint64_t get_object_id() { return object_id; }
[[nodiscard]] uint64_t get_object_id() const { return object_id; }

private:
std::string command_type_name; //command type name ex)"CREATE TABLE"
Expand Down
47 changes: 36 additions & 11 deletions include/ogawayama/stub/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ class ResultSet{
/**
* @brief Construct a new object.
*/
ResultSet(std::unique_ptr<Impl>);
explicit ResultSet(std::unique_ptr<Impl>);

/**
* @brief destructs this object.
*/
~ResultSet();

ResultSet(const ResultSet&) = delete;
ResultSet& operator=(const ResultSet&) = delete;
ResultSet(ResultSet&&) = delete;
ResultSet& operator=(ResultSet&&) = delete;

/**
* @brief get metadata for the result set.
* @param metadata returns the metadata class
Expand Down Expand Up @@ -118,13 +123,18 @@ class PreparedStatement {
/**
* @brief Construct a new object.
*/
PreparedStatement(std::unique_ptr<Impl>);
explicit PreparedStatement(std::unique_ptr<Impl>);

/**
* @brief destructs this object.
*/
~PreparedStatement();

PreparedStatement(const PreparedStatement&) = delete;
PreparedStatement& operator=(const PreparedStatement&) = delete;
PreparedStatement(PreparedStatement&&) = delete;
PreparedStatement& operator=(PreparedStatement&&) = delete;

private:
std::unique_ptr<Impl> impl_;

Expand Down Expand Up @@ -157,13 +167,18 @@ class Transaction {
/**
* @brief Construct a new object.
*/
Transaction(std::unique_ptr<Impl>);
explicit Transaction(std::unique_ptr<Impl>);

/**
* @brief destructs this object.
*/
~Transaction();

Transaction(const Transaction&) = delete;
Transaction& operator=(const Transaction&) = delete;
Transaction(Transaction&&) = delete;
Transaction& operator=(Transaction&&) = delete;

/**
* @brief execute a statement.
* @param statement the SQL statement string
Expand Down Expand Up @@ -242,13 +257,18 @@ class Connection : public manager::message::Receiver {
/**
* @brief Construct a new object.
*/
Connection(std::unique_ptr<Impl> impl);
explicit Connection(std::unique_ptr<Impl> impl);

/**
* @brief destructs this object.
*/
~Connection();

Connection(const Connection&) = delete;
Connection& operator=(const Connection&) = delete;
Connection(Connection&&) = delete;
Connection& operator=(Connection&&) = delete;

/**
* @brief begin a transaction and get Transaction class.
* @param transaction returns a transaction class
Expand Down Expand Up @@ -276,37 +296,37 @@ class Connection : public manager::message::Receiver {
* @brief implements begin_ddl() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
manager::message::Status receive_begin_ddl(const int64_t mode) const;
[[nodiscard]] manager::message::Status receive_begin_ddl(int64_t mode) const override;

/**
* @brief implements end_ddl() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
manager::message::Status receive_end_ddl() const;
[[nodiscard]] manager::message::Status receive_end_ddl() const override;

/**
* @brief implements receive_create_table() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
manager::message::Status receive_create_table(const manager::metadata::ObjectIdType object_id) const;
[[nodiscard]] manager::message::Status receive_create_table(manager::metadata::ObjectIdType object_id) const override;

/**
* @brief implements drop_table() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
manager::message::Status receive_drop_table(const manager::metadata::ObjectIdType object_id) const;
[[nodiscard]] manager::message::Status receive_drop_table(manager::metadata::ObjectIdType object_id) const override;

/**
* @brief implements receive_create_index() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
manager::message::Status receive_create_index(const manager::metadata::ObjectIdType object_id) const;
[[nodiscard]] manager::message::Status receive_create_index(manager::metadata::ObjectIdType object_id) const override;

/**
* @brief implements drop_index() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
manager::message::Status receive_drop_index(const manager::metadata::ObjectIdType object_id) const;
[[nodiscard]] manager::message::Status receive_drop_index(manager::metadata::ObjectIdType object_id) const override;

private:
std::unique_ptr<Impl> impl_;
Expand Down Expand Up @@ -337,13 +357,18 @@ class Stub {
/**
* @brief Construct a new object.
*/
Stub(std::string_view);
explicit Stub(std::string_view);

/**
* @brief destructs this object.
*/
~Stub();

Stub(Stub const& other) = delete;
Stub& operator=(Stub const& other) = delete;
Stub(Stub&& other) noexcept = delete;
Stub& operator=(Stub&& other) noexcept = delete;

/**
* @brief connect to the DB and get Connection class.
* @param supposed to be given MyProc->pgprocno for the first param
Expand Down
11 changes: 8 additions & 3 deletions include/ogawayama/stub/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Metadata {
* @param type tag for the column type
* @param byte length for the column data
*/
ColumnType(Type type) : type_(type) {}
explicit ColumnType(Type type) : type_(type) {}

/**
* @brief Copy and move constructers.
Expand All @@ -132,7 +132,7 @@ class Metadata {
* @brief get type for this column.
* @return Type of this column
*/
ColumnType::Type get_type() const { return type_; }
[[nodiscard]] ColumnType::Type get_type() const { return type_; }

private:
Type type_{};
Expand All @@ -153,12 +153,17 @@ class Metadata {
*/
~Metadata() noexcept = default;

Metadata(Metadata const& other) = delete;
Metadata& operator=(Metadata const& other) = delete;
Metadata(Metadata&& other) noexcept = delete;
Metadata& operator=(Metadata&& other) noexcept = delete;

/**
* @brief get a set of type data for this result set.
* @param columns returns the type data
* @return error code defined in error_code.h
*/
const SetOfTypeData& get_types() const noexcept { return columns_; }
[[nodiscard]] const SetOfTypeData& get_types() const noexcept { return columns_; }

/**
* @brief push a column type.
Expand Down
Loading

0 comments on commit e64919e

Please sign in to comment.