Skip to content

Commit

Permalink
src code rework
Browse files Browse the repository at this point in the history
use LOG(INFO) instead of std::cout
  • Loading branch information
Mizux committed Oct 16, 2024
1 parent 0826214 commit f203e44
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 215 deletions.
2 changes: 1 addition & 1 deletion Bar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set_target_properties(Bar PROPERTIES
VERSION ${PROJECT_VERSION}
POSITION_INDEPENDENT_CODE ON
PUBLIC_HEADER include/bar/Bar.hpp)
#target_link_libraries(Bar PUBLIC ...)
target_link_libraries(Bar PRIVATE absl::log)
add_library(${PROJECT_NAMESPACE}::Bar ALIAS Bar)

add_subdirectory(tests)
Expand Down
130 changes: 66 additions & 64 deletions Bar/src/Bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,167 +4,169 @@
#include <string>
#include <utility>

#include "absl/log/log.h"

namespace bar {
std::vector<std::string> stringVectorOutput(int level) {
std::cout << "[" << level << "] Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "[" << level << "] Enter " << __func__ << "()" << std::endl;
std::vector<std::string> result(level, std::to_string(level));
std::cout << "[" << level << "] Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "[" << level << "] Exit " << __func__ << "()" << std::endl;
return result;
}

int stringVectorInput(std::vector<std::string> data) {
std::cout << "Enter " << __func__ << "()" << std::endl;
std::cout << "{";
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "{";
for (const auto& item : data) {
std::cout << item << ", ";
LOG(INFO) << item << ", ";
}
std::cout << "}" << std::endl;
std::cout << "Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "}" << std::endl;
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
return data.size();
}

int stringVectorRefInput(const std::vector<std::string>& data) {
std::cout << "Enter " << __func__ << "()" << std::endl;
std::cout << "{";
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "{";
for (const auto& item : data) {
std::cout << item << ", ";
LOG(INFO) << item << ", ";
}
std::cout << "}" << std::endl;
std::cout << "Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "}" << std::endl;
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
return data.size();
}

std::vector<std::vector<std::string>> stringJaggedArrayOutput(int level) {
std::cout << "[" << level << "] Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "[" << level << "] Enter " << __func__ << "()" << std::endl;
std::vector<std::vector<std::string>> result;
result.reserve(level);
for (int i = 1; i <= level; ++i) {
result.emplace_back(std::vector<std::string>(i, std::to_string(i)));
}
std::cout << "[" << level << "] Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "[" << level << "] Exit " << __func__ << "()" << std::endl;
return result;
}

int stringJaggedArrayInput(std::vector<std::vector<std::string>> data) {
std::cout << "Enter " << __func__ << "()" << std::endl;
std::cout << "{";
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "{";
for (const auto& inner : data) {
std::cout << "{";
LOG(INFO) << "{";
for (const auto& item : inner) {
std::cout << item << ", ";
LOG(INFO) << item << ", ";
}
std::cout << "}, ";
LOG(INFO) << "}, ";
}
std::cout << "}" << std::endl;
std::cout << "Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "}" << std::endl;
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
return data.size();
}

int stringJaggedArrayRefInput(const std::vector<std::vector<std::string>>& data) {
std::cout << "Enter " << __func__ << "()" << std::endl;
std::cout << "{";
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "{";
for (const auto& inner : data) {
std::cout << "{";
LOG(INFO) << "{";
for (const auto& item : inner) {
std::cout << item << ", ";
LOG(INFO) << item << ", ";
}
std::cout << "}, ";
LOG(INFO) << "}, ";
}
std::cout << "}" << std::endl;
std::cout << "Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "}" << std::endl;
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
return data.size();
}

std::vector<std::pair<int, int>> pairVectorOutput(int level) {
std::cout << "[" << level << "] Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "[" << level << "] Enter " << __func__ << "()" << std::endl;
std::vector<std::pair<int, int>> result(level, std::make_pair(level, level));
std::cout << "[" << level << "] Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "[" << level << "] Exit " << __func__ << "()" << std::endl;
return result;
}

int pairVectorInput(std::vector<std::pair<int, int>> data) {
std::cout << "Enter " << __func__ << "()" << std::endl;
std::cout << "{";
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "{";
for (const auto& item : data) {
std::cout << "[" << item.first << "," << item.second << "], ";
LOG(INFO) << "[" << item.first << "," << item.second << "], ";
}
std::cout << "}" << std::endl;
std::cout << "Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "}" << std::endl;
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
return data.size();
}

int pairVectorRefInput(const std::vector<std::pair<int, int>>& data) {
std::cout << "Enter " << __func__ << "()" << std::endl;
std::cout << "{";
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "{";
for (const auto& item : data) {
std::cout << "[" << item.first << "," << item.second << "], ";
LOG(INFO) << "[" << item.first << "," << item.second << "], ";
}
std::cout << "}" << std::endl;
std::cout << "Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "}" << std::endl;
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
return data.size();
}

std::vector<std::vector<std::pair<int, int>>> pairJaggedArrayOutput(int level) {
std::cout << "[" << level << "] Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "[" << level << "] Enter " << __func__ << "()" << std::endl;
std::vector<std::vector<std::pair<int, int>>> result;
result.reserve(level);
for (int i = 1; i <= level; ++i) {
result.emplace_back(std::vector<std::pair<int, int>>(i, std::make_pair(i, i)));
}
std::cout << "[" << level << "] Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "[" << level << "] Exit " << __func__ << "()" << std::endl;
return result;
}

int pairJaggedArrayInput(std::vector<std::vector<std::pair<int, int>>> data) {
std::cout << "Enter " << __func__ << "()" << std::endl;
std::cout << "{";
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "{";
for (const auto& inner : data) {
std::cout << "{";
LOG(INFO) << "{";
for (const auto& item : inner) {
std::cout << "[" << item.first << "," << item.second << "], ";
LOG(INFO) << "[" << item.first << "," << item.second << "], ";
}
std::cout << "}, ";
LOG(INFO) << "}, ";
}
std::cout << "}" << std::endl;
std::cout << "Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "}" << std::endl;
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
return data.size();
}

int pairJaggedArrayRefInput(const std::vector<std::vector<std::pair<int, int>>>& data) {
std::cout << "Enter " << __func__ << "()" << std::endl;
std::cout << "{";
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
LOG(INFO) << "{";
for (const auto& inner : data) {
std::cout << "{";
LOG(INFO) << "{";
for (const auto& item : inner) {
std::cout << "[" << item.first << "," << item.second << "], ";
LOG(INFO) << "[" << item.first << "," << item.second << "], ";
}
std::cout << "}, ";
LOG(INFO) << "}, ";
}
std::cout << "}" << std::endl;
std::cout << "Exit " << __func__ << "()" << std::endl;
LOG(INFO) << "}" << std::endl;
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
return data.size();
}

void freeFunction(int level) {
std::cout << "[" << level << "] Enter " << __func__ << "(int)" << std::endl;
std::cout << "[" << level << "] Exit " << __func__ << "(int)" << std::endl;
LOG(INFO) << "[" << level << "] Enter " << __func__ << "(int)" << std::endl;
LOG(INFO) << "[" << level << "] Exit " << __func__ << "(int)" << std::endl;
}

void freeFunction(int64_t level) {
std::cout << "[" << level << "] Enter " << __func__ << "(int64_t)" << std::endl;
std::cout << "[" << level << "] Exit " << __func__ << "(int64_t)" << std::endl;
LOG(INFO) << "[" << level << "] Enter " << __func__ << "(int64_t)" << std::endl;
LOG(INFO) << "[" << level << "] Exit " << __func__ << "(int64_t)" << std::endl;
}

void Bar::staticFunction(int level) {
std::cout << "[" << level << "] Enter " << __func__ << "(int)" << std::endl;
LOG(INFO) << "[" << level << "] Enter " << __func__ << "(int)" << std::endl;
freeFunction(level + 1);
std::cout << "[" << level << "] Exit " << __func__ << "(int)" << std::endl;
LOG(INFO) << "[" << level << "] Exit " << __func__ << "(int)" << std::endl;
}

void Bar::staticFunction(int64_t level) {
std::cout << "[" << level << "] Enter " << __func__ << "(int64_t)" << std::endl;
LOG(INFO) << "[" << level << "] Enter " << __func__ << "(int64_t)" << std::endl;
freeFunction(level + 1);
std::cout << "[" << level << "] Exit " << __func__ << "(int64_t)" << std::endl;
LOG(INFO) << "[" << level << "] Exit " << __func__ << "(int64_t)" << std::endl;
}

int Bar::getInt() const {
Expand Down
2 changes: 1 addition & 1 deletion Foo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set_target_properties(Foo PROPERTIES
VERSION ${PROJECT_VERSION}
POSITION_INDEPENDENT_CODE ON
PUBLIC_HEADER include/foo/Foo.hpp)
#target_link_libraries(Foo PUBLIC ...)
target_link_libraries(Foo PRIVATE absl::log)
add_library(${PROJECT_NAMESPACE}::Foo ALIAS Foo)

add_subdirectory(tests)
Expand Down
Loading

0 comments on commit f203e44

Please sign in to comment.