Skip to content

Commit

Permalink
Always put const at the end of type
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 committed Apr 18, 2023
1 parent c5a945e commit b7e195b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
12 changes: 6 additions & 6 deletions include/tl2cgen/c_api_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef void* TL2cgenDMatrixHandle;
* Note. Each thread will get the last error occurred in its own context.
* \return error string
*/
TL2CGEN_DLL const char* TL2cgenGetLastError(void);
TL2CGEN_DLL char const* TL2cgenGetLastError(void);

/*!
* \brief Register callback function for LOG(INFO) messages -- helpful messages
Expand All @@ -43,28 +43,28 @@ TL2CGEN_DLL const char* TL2cgenGetLastError(void);
* will run on the thread that registered it
* \return 0 for success, -1 for failure
*/
TL2CGEN_DLL int TL2cgenRegisterLogCallback(void (*callback)(const char*));
TL2CGEN_DLL int TL2cgenRegisterLogCallback(void (*callback)(char const*));

/*!
* \brief Register callback function for LOG(WARNING) messages
* Note: This function can be called by multiple threads. The callback function
* will run on the thread that registered it
* \return 0 for success, -1 for failure
*/
TL2CGEN_DLL int TL2cgenRegisterWarningCallback(void (*callback)(const char*));
TL2CGEN_DLL int TL2cgenRegisterWarningCallback(void (*callback)(char const*));

/*!
* \brief Get the version string for the TL2cgen library.
* \return version string, of form MAJOR.MINOR.PATCH
*/
TL2CGEN_DLL const char* TL2cgenQueryTL2cgenVersion(void);
TL2CGEN_DLL char const* TL2cgenQueryTL2cgenVersion(void);

#ifdef __cplusplus
extern "C" {
extern const char* TREELITE_VERSION;
extern char const* TREELITE_VERSION;
}
#else
extern const char* TREELITE_VERSION;
extern char const* TREELITE_VERSION;
#endif

#endif // TL2CGEN_C_API_COMMON_H_
4 changes: 2 additions & 2 deletions include/tl2cgen/c_api_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
* \brief Set the last error message needed by C API
* \param msg The error message to set.
*/
void TL2cgenAPISetLastError(const char* msg);
void TL2cgenAPISetLastError(char const* msg);
/*!
* \brief handle exception thrown out
* \param e the exception
* \return the return value of API after exception is handled
*/
inline int TL2cgenAPIHandleException(const std::exception& e) {
inline int TL2cgenAPIHandleException(std::exception const& e) {
TL2cgenAPISetLastError(e.what());
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion include/tl2cgen/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace tl2cgen {
* \brief Exception class that will be thrown by TL2cgen
*/
struct Error : public std::runtime_error {
explicit Error(const std::string& s) : std::runtime_error(s) {}
explicit Error(std::string const& s) : std::runtime_error(s) {}
};

} // namespace tl2cgen
Expand Down
24 changes: 12 additions & 12 deletions include/tl2cgen/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace tl2cgen {

template <typename X, typename Y>
std::unique_ptr<std::string> LogCheckFormat(const X& x, const Y& y) {
std::unique_ptr<std::string> LogCheckFormat(X const& x, Y const& y) {
std::ostringstream os;
os << " (" << x << " vs. " << y << ") ";
/* CHECK_XX(x, y) requires x and y can be serialized to string. Use CHECK(x OP y) otherwise. */
Expand Down Expand Up @@ -83,7 +83,7 @@ class DateLogger {
_tzset();
#endif // defined(_MSC_VER)
}
const char* HumanDate() {
char const* HumanDate() {
#if defined(_MSC_VER)
_strtime_s(buffer_, sizeof(buffer_));
#else // defined(_MSC_VER)
Expand All @@ -107,11 +107,11 @@ class DateLogger {

class LogMessageFatal {
public:
LogMessageFatal(const char* file, int line) {
LogMessageFatal(char const* file, int line) {
log_stream_ << "[" << pretty_date_.HumanDate() << "] " << file << ":" << line << ": ";
}
LogMessageFatal(const LogMessageFatal&) = delete;
void operator=(const LogMessageFatal&) = delete;
LogMessageFatal(LogMessageFatal const&) = delete;
void operator=(LogMessageFatal const&) = delete;

std::ostringstream& stream() {
return log_stream_;
Expand All @@ -127,7 +127,7 @@ class LogMessageFatal {

class LogMessage {
public:
LogMessage(const char* file, int line) {
LogMessage(char const* file, int line) {
log_stream_ << "[" << DateLogger().HumanDate() << "] " << file << ":" << line << ": ";
}
~LogMessage() {
Expand All @@ -136,15 +136,15 @@ class LogMessage {
std::ostream& stream() {
return log_stream_;
}
static void Log(const std::string& msg);
static void Log(std::string const& msg);

private:
std::ostringstream log_stream_;
};

class LogMessageWarning {
public:
LogMessageWarning(const char* file, int line) {
LogMessageWarning(char const* file, int line) {
log_stream_ << "[" << DateLogger().HumanDate() << "] " << file << ":" << line << ": ";
}
~LogMessageWarning() {
Expand All @@ -153,18 +153,18 @@ class LogMessageWarning {
std::ostream& stream() {
return log_stream_;
}
static void Log(const std::string& msg);
static void Log(std::string const& msg);

private:
std::ostringstream log_stream_;
};

class LogCallbackRegistry {
public:
using Callback = void (*)(const char*);
using Callback = void (*)(char const*);
LogCallbackRegistry()
: log_callback_info_([](const char* msg) { std::cerr << msg << std::endl; }),
log_callback_warn_([](const char* msg) { std::cerr << msg << std::endl; }) {}
: log_callback_info_([](char const* msg) { std::cerr << msg << std::endl; }),
log_callback_warn_([](char const* msg) { std::cerr << msg << std::endl; }) {}
inline void RegisterCallBackLogInfo(Callback log_callback) {
this->log_callback_info_ = log_callback;
}
Expand Down
1 change: 1 addition & 0 deletions src/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
QualifierAlignment: Right
4 changes: 2 additions & 2 deletions src/c_api/c_api_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

using namespace tl2cgen; // NOLINT(build/namespaces)

int TL2cgenRegisterLogCallback(void (*callback)(const char*)) {
int TL2cgenRegisterLogCallback(void (*callback)(char const*)) {
API_BEGIN();
LogCallbackRegistry* registry = LogCallbackRegistryStore::Get();
registry->RegisterCallBackLogInfo(callback);
API_END();
}

int TL2cgenRegisterWarningCallback(void (*callback)(const char*)) {
int TL2cgenRegisterWarningCallback(void (*callback)(char const*)) {
API_BEGIN();
LogCallbackRegistry* registry = LogCallbackRegistryStore::Get();
registry->RegisterCallBackLogWarning(callback);
Expand Down
8 changes: 4 additions & 4 deletions src/c_api/c_api_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ using TL2cgenAPIErrorStore = tl2cgen::ThreadLocalStore<TL2cgenAPIErrorEntry>;

} // anonymous namespace

const char* TL2cgenGetLastError() {
char const* TL2cgenGetLastError() {
return TL2cgenAPIErrorStore::Get()->last_error.c_str();
}

void TL2cgenAPISetLastError(const char* msg) {
void TL2cgenAPISetLastError(char const* msg) {
TL2cgenAPIErrorStore::Get()->last_error = msg;
}

const char* TL2cgenQueryTL2cgenVersion() {
char const* TL2cgenQueryTL2cgenVersion() {
std::ostringstream oss;
oss << TL2CGEN_VER_MAJOR << "." << TL2CGEN_VER_MINOR << "." << TL2CGEN_VER_PATCH;
std::string& version_str = TL2cgenAPIErrorStore::Get()->version_str;
version_str = oss.str();
return version_str.c_str();
}

const char* TL2CGEN_VERSION = "TL2CGEN_VERSION_" STR(TREELITE_VER_MAJOR) "." STR(
char const* TL2CGEN_VERSION = "TL2CGEN_VERSION_" STR(TREELITE_VER_MAJOR) "." STR(
TREELITE_VER_MINOR) "." STR(TREELITE_VER_PATCH);

0 comments on commit b7e195b

Please sign in to comment.