clang-tidy修改。

This commit is contained in:
taynpg 2025-04-14 22:49:10 +08:00
parent a7c61f6ea2
commit 4869b0d494
12 changed files with 49 additions and 48 deletions

View File

@ -1,4 +1,5 @@
Checks: '-*, Checks: "-*,
clang-*, clang-*,
google-build-explicit-make-pair, google-build-explicit-make-pair,
@ -9,11 +10,12 @@ Checks: '-*,
google-runtime-int, google-runtime-int,
google-runtime-operator, google-runtime-operator,
readability-non-const-parameter,
-readability-non-const-parameter,
readability-avoid-const-params-in-decls, readability-avoid-const-params-in-decls,
readability-const-return-type, readability-const-return-type,
readability-container-size-empty, readability-container-size-empty,
readability-convert-member-functions-to-static, -readability-convert-member-functions-to-static,
readability-delete-null-pointer, readability-delete-null-pointer,
readability-deleted-default, readability-deleted-default,
readability-make-member-function-const, readability-make-member-function-const,
@ -33,7 +35,8 @@ Checks: '-*,
cert-dcl21-cpp, cert-dcl21-cpp,
cert-dcl50-cpp, cert-dcl50-cpp,
cert-env33-c, # 不要使用 system()
-cert-env33-c,
cert-err34-c, cert-err34-c,
cert-err52-cpp, cert-err52-cpp,
cert-flp30-c, cert-flp30-c,
@ -46,7 +49,7 @@ Checks: '-*,
modernize-loop-convert, modernize-loop-convert,
modernize-make-shared, modernize-make-shared,
modernize-make-unique, modernize-make-unique,
modernize-pass-by-value, -modernize-pass-by-value,
modernize-raw-string-literal, modernize-raw-string-literal,
modernize-redundant-void-arg, modernize-redundant-void-arg,
modernize-replace-auto-ptr, modernize-replace-auto-ptr,
@ -130,7 +133,6 @@ Checks: '-*,
performance-unnecessary-copy-initialization, performance-unnecessary-copy-initialization,
boost-use-to-string, boost-use-to-string,
boost-use-ranges, boost-use-ranges"
'
WarningsAsErrors: '*' WarningsAsErrors: "*"

View File

@ -1,8 +1,6 @@
{ {
"files.autoSave": "onFocusChange", "files.autoSave": "onFocusChange",
"editor.fontSize": 14, "editor.fontSize": 14,
"editor.fontFamily": "'Monaspace Krypton Light', 'Monaspace Krypton Light', 'Monaspace Krypton Light'",
"terminal.integrated.fontFamily": "Monaspace Krypton Light",
"cmake.configureOnOpen": true, "cmake.configureOnOpen": true,
"cmake.debugConfig": { "cmake.debugConfig": {
"console": "integratedTerminal", "console": "integratedTerminal",
@ -39,6 +37,7 @@
"--all-scopes-completion", "--all-scopes-completion",
"--completion-style=detailed", "--completion-style=detailed",
"-j=4", "-j=4",
"--clang-tidy",
"--pch-storage=memory", "--pch-storage=memory",
"--compile-commands-dir=build", "--compile-commands-dir=build",
"--background-index", "--background-index",

View File

@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (MSVC) if (MSVC)
add_compile_options(/utf-8) add_compile_options(/utf-8)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif() endif()
add_definitions(-D_WIN32_WINNT=0x0601) add_definitions(-D_WIN32_WINNT=0x0601)

View File

@ -64,5 +64,4 @@ FrameData* OpenAIClient::ask_openai(const std::string& text)
void OpenAIClient::disconnect() void OpenAIClient::disconnect()
{ {
} }

View File

@ -7,7 +7,7 @@
class OpenAIClient class OpenAIClient
{ {
public: public:
OpenAIClient(asio::io_context& io_context); explicit OpenAIClient(asio::io_context& io_context);
public: public:
bool connect(const std::string& ip, unsigned int port); bool connect(const std::string& ip, unsigned int port);
@ -15,11 +15,11 @@ public:
void disconnect(); void disconnect();
private: private:
std::string ip_{}; std::string ip_;
std::string port_{}; std::string port_;
asio::ip::tcp::socket socket_; asio::ip::tcp::socket socket_;
asio::io_context& io_context_; asio::io_context& io_context_;
CMutBuffer buffer_{}; CMutBuffer buffer_;
std::array<char, g_BuffSize> tmp_buf_{}; std::array<char, g_BuffSize> tmp_buf_{};
}; };

View File

@ -8,7 +8,7 @@ struct Configuration {
std::string user_name; std::string user_name;
std::string model_name; std::string model_name;
std::string assistant_name; std::string assistant_name;
long max_tokens{}; int32_t max_tokens{};
}; };
class ConfigSet class ConfigSet
@ -16,6 +16,7 @@ class ConfigSet
public: public:
ConfigSet() = default; ConfigSet() = default;
~ConfigSet() = default; ~ConfigSet() = default;
public: public:
static bool parse_config(Configuration& config, const std::string& config_path = ""); static bool parse_config(Configuration& config, const std::string& config_path = "");
}; };

View File

@ -1,6 +1,6 @@
#include "jsondata.h" #include "jsondata.h"
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
CJsonOper::CJsonOper(const std::string& user_name, const std::string& model, const std::string& assistant_name) CJsonOper::CJsonOper(const std::string& user_name, const std::string& model, const std::string& assistant_name)
: user_(user_name), model_(model), assistant_(assistant_name) : user_(user_name), model_(model), assistant_(assistant_name)
@ -92,15 +92,15 @@ size_t CJsonOper::get_u8_len(unsigned char ch)
{ {
if (ch <= 0x7F) { if (ch <= 0x7F) {
return 1; return 1;
} else if ((ch & 0xE0) == 0xC0) { } else if ((ch & (unsigned char)0xE0) == 0xC0) {
return 2; return 2;
} else if ((ch & 0xF0) == 0xE0) { } else if ((ch & (unsigned char)0xF0) == 0xE0) {
return 3; return 3;
} else if ((ch & 0xF8) == 0xF0) { } else if ((ch & (unsigned char)0xF8) == 0xF0) {
return 4; return 4;
} else if ((ch & 0xFC) == 0xF8) { } else if ((ch & (unsigned char)0xFC) == 0xF8) {
return 5; return 5;
} else if ((ch & 0xFE) == 0xFC) { } else if ((ch & (unsigned char)0xFE) == 0xFC) {
return 6; return 6;
} else { } else {
std::cerr << "invalid u8 first ch." << std::endl; std::cerr << "invalid u8 first ch." << std::endl;
@ -118,4 +118,3 @@ std::string CJsonOper::trim(const std::string& input)
size_t end = input.find_last_not_of(" \t\n\r\f\v"); size_t end = input.find_last_not_of(" \t\n\r\f\v");
return input.substr(start, end - start + 1); return input.substr(start, end - start + 1);
} }

View File

@ -78,7 +78,8 @@ int main(int argc, char* argv[])
// std::cout << "post success!" << std::endl; // std::cout << "post success!" << std::endl;
// auto re = json->parse(out); // auto re = json->parse(out);
// std::string use = "本次tokens消耗:" + std::to_string(re.prompt_tokens) + "+" + std::to_string(re.completion_tokens) + "=" + // std::string use = "本次tokens消耗:" + std::to_string(re.prompt_tokens) + "+" + std::to_string(re.completion_tokens) + "="
// +
// std::to_string(re.total_tokens); // std::to_string(re.total_tokens);
// std::cout << use << std::endl; // std::cout << use << std::endl;

View File

@ -1,9 +1,9 @@
#include "server.h" #include "server.h"
#include <cstdint>
#include <iostream> #include <iostream>
Server::Server(asio::io_context& io_context, uint16_t port) : io_context_(io_context), acceptor_(io_context)
Server::Server(asio::io_context& io_context, short port) : io_context_(io_context), acceptor_(io_context)
{ {
port_ = port; port_ = port;
} }
@ -44,7 +44,7 @@ void Server::set_worker(std::shared_ptr<COpenAI> worker, std::shared_ptr<CJsonOp
json_ = json; json_ = json;
} }
void Server::set_token(long tokens) void Server::set_token(int32_t tokens)
{ {
tokens_ = tokens; tokens_ = tokens;
} }
@ -58,8 +58,7 @@ void Server::do_accept()
std::string client_key = endpoint.address().to_string() + ":" + std::to_string(endpoint.port()); std::string client_key = endpoint.address().to_string() + ":" + std::to_string(endpoint.port());
std::unique_lock<std::mutex> lock(cli_mutex_); std::unique_lock<std::mutex> lock(cli_mutex_);
client_map_[client_key] = std::make_shared<ClientCache>(); client_map_[client_key] = std::make_shared<ClientCache>();
clients_.insert( clients_.insert(std::make_pair(socket->remote_endpoint().address().to_string(),
std::make_pair(socket->remote_endpoint().address().to_string(),
std::thread([this, socket, client_key]() { th_client(socket, client_key); }))); std::thread([this, socket, client_key]() { th_client(socket, client_key); })));
} }
@ -100,7 +99,7 @@ void Server::th_client(const std::shared_ptr<asio::ip::tcp::socket>& socket, con
cache->buffer_.push(cache->tmp_buf_.data(), len); cache->buffer_.push(cache->tmp_buf_.data(), len);
while (true) { while (true) {
auto frame = com_parse(cache->buffer_); auto* frame = com_parse(cache->buffer_);
if (frame == nullptr) { if (frame == nullptr) {
break; break;
} }

View File

@ -11,13 +11,13 @@
struct ClientCache { struct ClientCache {
std::array<char, g_BuffSize> tmp_buf_{}; std::array<char, g_BuffSize> tmp_buf_{};
CMutBuffer buffer_{}; CMutBuffer buffer_;
}; };
class Server class Server
{ {
public: public:
Server(asio::io_context& io_context, short port); Server(asio::io_context& io_context, uint16_t port);
~Server(); ~Server();
public: public:
@ -26,7 +26,7 @@ public:
public: public:
void set_worker(std::shared_ptr<COpenAI> worker, std::shared_ptr<CJsonOper> json); void set_worker(std::shared_ptr<COpenAI> worker, std::shared_ptr<CJsonOper> json);
void set_token(long tokens); void set_token(int32_t tokens);
private: private:
void do_accept(); void do_accept();
@ -40,16 +40,16 @@ private:
asio::io_context& io_context_; asio::io_context& io_context_;
asio::ip::tcp::acceptor acceptor_; asio::ip::tcp::acceptor acceptor_;
std::shared_ptr<COpenAI> worker_{}; std::shared_ptr<COpenAI> worker_;
std::shared_ptr<CJsonOper> json_{}; std::shared_ptr<CJsonOper> json_;
std::mutex ask_mutex_; std::mutex ask_mutex_;
std::mutex cli_mutex_; std::mutex cli_mutex_;
std::unordered_map<std::string, std::thread> clients_; std::unordered_map<std::string, std::thread> clients_;
std::map<std::string, std::shared_ptr<ClientCache>> client_map_; std::map<std::string, std::shared_ptr<ClientCache>> client_map_;
CMutBuffer buffer_{}; CMutBuffer buffer_;
short port_; uint16_t port_;
long tokens_{}; int32_t tokens_{};
long use_tokens_{}; int32_t use_tokens_{};
}; };
#endif #endif

View File

@ -45,6 +45,6 @@ bool COpenAI::post(const std::string& json, std::string& out)
size_t COpenAI::recv_call(void* contents, size_t size, size_t nmemb, std::string* output) size_t COpenAI::recv_call(void* contents, size_t size, size_t nmemb, std::string* output)
{ {
size_t total_size = size * nmemb; size_t total_size = size * nmemb;
output->append(reinterpret_cast<char*>(contents), total_size); output->append(static_cast<char*>(contents), total_size);
return total_size; return total_size;
} }

View File

@ -18,10 +18,10 @@ private:
static size_t recv_call(void* contents, size_t size, size_t nmemb, std::string* output); static size_t recv_call(void* contents, size_t size, size_t nmemb, std::string* output);
private: private:
std::string api_key_{}; std::string api_key_;
std::string api_url_{}; std::string api_url_;
std::string recv_{}; std::string recv_;
CURL* curl_{}; CURL* curl_;
}; };
#endif #endif