Compare commits

..

No commits in common. "674137e89d70e2ccd1a3a4a5a212aac3b872375a" and "baea2dce47172e7aaab67b20e6a4887a1f6464cf" have entirely different histories.

15 changed files with 85 additions and 165 deletions

View File

@ -17,25 +17,5 @@ jobs:
- name: Install dos2unix - name: Install dos2unix
run: sudo apt-get install -y dos2unix run: sudo apt-get install -y dos2unix
- name: Install clang-format-17
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 17
sudo apt-get install -y clang-format-17
- name: Check formatting - name: Check formatting
run: ./format.sh && git diff --exit-code run: ./format.sh && git diff --exit-code
env:
CLANG_FORMAT: clang-format-17
cpplint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install cpplint
run: pip install cpplint
- name: Run lint
run: cpplint --recursive .

View File

@ -1,41 +0,0 @@
# Stop searching for additional config files.
set noparent
exclude_files=trantor
exclude_files=build
# Use non-const reference rather than a pointer.
filter=-runtime/references
# CHECK macros are from Drogon, not Google Test.
filter=-readability/check
# Don't warn about the use of C++11 features.
filter=-build/c++11
filter=-build/include_subdir
# We prioritize clang-format for now.
filter=-whitespace
# We don't require a username in TODO comments.
filter=-readability/todo
# TODO: Fix these.
filter=-legal/copyright
filter=-build/storage_class
filter=-build/namespaces
filter=-build/include
filter=-build/header_guard
filter=-build/include_what_you_use
filter=-build/include_order
filter=-build/explicit_make_pair
filter=-runtime/explicit
filter=-runtime/string
filter=-runtime/int
filter=-readability/multiline_string
filter=-readability/inheritance
filter=-readability/casting
filter=-readability/braces
filter=-readability/fn_size
filter=-runtime/threadsafe_fn

View File

@ -308,18 +308,16 @@ void create_model::createModelClassFromPG(
data["hasPrimaryKey"] = (int)pkNumber; data["hasPrimaryKey"] = (int)pkNumber;
if (pkNumber == 1) if (pkNumber == 1)
{ {
*client << "SELECT " *client << "SELECT \
"pg_attribute.attname AS colname," pg_attribute.attname AS colname,\
"pg_type.typname AS typename," pg_type.typname AS typename,\
"pg_constraint.contype AS contype " pg_constraint.contype AS contype \
"FROM pg_constraint " FROM pg_constraint \
"INNER JOIN pg_class ON pg_constraint.conrelid = " INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
"pg_class.oid " INNER JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid \
"INNER JOIN pg_attribute ON pg_attribute.attrelid = " AND pg_attribute.attnum = pg_constraint.conkey [ 1 ] \
"pg_class.oid " INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid \
"AND pg_attribute.attnum = pg_constraint.conkey [ 1 ] " WHERE pg_class.relname = $1 and pg_constraint.contype='p'"
"INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid "
"WHERE pg_class.relname = $1 and pg_constraint.contype='p'"
<< tableName << Mode::Blocking >> << tableName << Mode::Blocking >>
[&](bool isNull, [&](bool isNull,
const std::string &colName, const std::string &colName,
@ -347,20 +345,16 @@ void create_model::createModelClassFromPG(
std::vector<std::string> pkNames, pkTypes, pkValNames; std::vector<std::string> pkNames, pkTypes, pkValNames;
for (size_t i = 1; i <= pkNumber; ++i) for (size_t i = 1; i <= pkNumber; ++i)
{ {
*client << "SELECT " *client << "SELECT \
"pg_attribute.attname AS colname," pg_attribute.attname AS colname,\
"pg_type.typname AS typename," pg_type.typname AS typename,\
"pg_constraint.contype AS contype " pg_constraint.contype AS contype \
"FROM pg_constraint " FROM pg_constraint \
"INNER JOIN pg_class ON pg_constraint.conrelid = " INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
"pg_class.oid " INNER JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid \
"INNER JOIN pg_attribute ON pg_attribute.attrelid = " AND pg_attribute.attnum = pg_constraint.conkey [ $1 ] \
"pg_class.oid " INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid \
"AND pg_attribute.attnum = pg_constraint.conkey [ $1 ] " WHERE pg_class.relname = $2 and pg_constraint.contype='p'"
"INNER JOIN pg_type ON pg_type.oid = "
"pg_attribute.atttypid "
"WHERE pg_class.relname = $2 and "
"pg_constraint.contype='p'"
<< (int)i << tableName << Mode::Blocking >> << (int)i << tableName << Mode::Blocking >>
[&](bool isNull, std::string colName, const std::string &type) { [&](bool isNull, std::string colName, const std::string &type) {
if (isNull) if (isNull)

View File

@ -3,10 +3,10 @@
# You can customize the clang-format path by setting the CLANG_FORMAT environment variable # You can customize the clang-format path by setting the CLANG_FORMAT environment variable
CLANG_FORMAT=${CLANG_FORMAT:-clang-format} CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
# Check if clang-format version is 17 to avoid inconsistent formatting # Check if clang-format version is 14 to avoid inconsistent formatting
$CLANG_FORMAT --version $CLANG_FORMAT --version
if [[ ! $($CLANG_FORMAT --version) =~ "version 17" ]]; then if [[ ! $($CLANG_FORMAT --version) =~ "version 14" ]]; then
echo "Error: clang-format version must be 17" echo "Error: clang-format version must be 14"
exit 1 exit 1
fi fi

View File

@ -138,7 +138,7 @@ class DROGON_EXPORT DrClassMap
protected: protected:
static std::unordered_map<std::string, static std::unordered_map<std::string,
std::pair<DrAllocFunc, DrSharedAllocFunc>> & std::pair<DrAllocFunc, DrSharedAllocFunc>>
getMap(); &getMap();
}; };
} // namespace drogon } // namespace drogon

View File

@ -194,8 +194,8 @@ class DROGON_EXPORT HttpAppFramework : public trantor::NonCopyable
* returned. * returned.
*/ */
virtual const std::function<HttpResponsePtr(HttpStatusCode, virtual const std::function<HttpResponsePtr(HttpStatusCode,
const HttpRequestPtr &req)> & const HttpRequestPtr &req)>
getCustomErrorHandler() const = 0; &getCustomErrorHandler() const = 0;
/// Get the plugin object registered in the framework /// Get the plugin object registered in the framework
/** /**
@ -1421,8 +1421,8 @@ class DROGON_EXPORT HttpAppFramework : public trantor::NonCopyable
* *
* @return std::pair<size_t, std::string> * @return std::pair<size_t, std::string>
*/ */
virtual const std::pair<unsigned int, std::string> & virtual const std::pair<unsigned int, std::string>
getFloatPrecisionInJson() const noexcept = 0; &getFloatPrecisionInJson() const noexcept = 0;
/// Create a database client /// Create a database client
/** /**
* @param dbType The database type is one of * @param dbType The database type is one of

View File

@ -162,31 +162,27 @@ class DROGON_EXPORT HttpRequest
virtual const std::string &getCookie(const std::string &field) const = 0; virtual const std::string &getCookie(const std::string &field) const = 0;
/// Get all headers of the request /// Get all headers of the request
virtual const std::unordered_map<std::string, virtual const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &headers() const = 0;
headers() const = 0;
/// Get all headers of the request /// Get all headers of the request
const std::unordered_map<std::string, const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &getHeaders() const
getHeaders() const
{ {
return headers(); return headers();
} }
/// Get all cookies of the request /// Get all cookies of the request
virtual const std::unordered_map<std::string, virtual const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &cookies() const = 0;
cookies() const = 0;
/// Get all cookies of the request /// Get all cookies of the request
const std::unordered_map<std::string, const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &getCookies() const
getCookies() const
{ {
return cookies(); return cookies();
} }
@ -304,16 +300,14 @@ class DROGON_EXPORT HttpRequest
} }
/// Get parameters of the request. /// Get parameters of the request.
virtual const std::unordered_map<std::string, virtual const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &parameters() const = 0;
parameters() const = 0;
/// Get parameters of the request. /// Get parameters of the request.
const std::unordered_map<std::string, const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &getParameters() const
getParameters() const
{ {
return parameters(); return parameters();
} }

View File

@ -244,16 +244,14 @@ class DROGON_EXPORT HttpResponse
virtual void removeHeader(std::string key) = 0; virtual void removeHeader(std::string key) = 0;
/// Get all headers of the response /// Get all headers of the response
virtual const std::unordered_map<std::string, virtual const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &headers() const = 0;
headers() const = 0;
/// Get all headers of the response /// Get all headers of the response
const std::unordered_map<std::string, const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &getHeaders() const
getHeaders() const
{ {
return headers(); return headers();
} }
@ -282,13 +280,13 @@ class DROGON_EXPORT HttpResponse
/// Get all cookies. /// Get all cookies.
virtual const std:: virtual const std::
unordered_map<std::string, Cookie, utils::internal::SafeStringHash> & unordered_map<std::string, Cookie, utils::internal::SafeStringHash>
cookies() const = 0; &cookies() const = 0;
/// Get all cookies. /// Get all cookies.
const std:: const std::
unordered_map<std::string, Cookie, utils::internal::SafeStringHash> & unordered_map<std::string, Cookie, utils::internal::SafeStringHash>
getCookies() const &getCookies() const
{ {
return cookies(); return cookies();
} }
@ -582,8 +580,8 @@ class DROGON_EXPORT HttpResponse
* newStreamResponse) returns the callback function. Otherwise a * newStreamResponse) returns the callback function. Otherwise a
* null function. * null function.
*/ */
virtual const std::function<std::size_t(char *, std::size_t)> & virtual const std::function<std::size_t(char *, std::size_t)>
streamCallback() const = 0; &streamCallback() const = 0;
/** /**
* @brief If the response is a async stream response (i.e. created by * @brief If the response is a async stream response (i.e. created by

View File

@ -22,8 +22,8 @@ namespace drogon
{ {
namespace internal namespace internal
{ {
static std::unordered_map<std::string, std::shared_ptr<DrObjectBase>> & static std::unordered_map<std::string, std::shared_ptr<DrObjectBase>>
getObjsMap() &getObjsMap()
{ {
static std::unordered_map<std::string, std::shared_ptr<DrObjectBase>> static std::unordered_map<std::string, std::shared_ptr<DrObjectBase>>
singleInstanceMap; singleInstanceMap;
@ -112,8 +112,8 @@ std::vector<std::string> DrClassMap::getAllClassName()
return ret; return ret;
} }
std::unordered_map<std::string, std::pair<DrAllocFunc, DrSharedAllocFunc>> & std::unordered_map<std::string, std::pair<DrAllocFunc, DrSharedAllocFunc>>
DrClassMap::getMap() &DrClassMap::getMap()
{ {
static std::unordered_map<std::string, static std::unordered_map<std::string,
std::pair<DrAllocFunc, DrSharedAllocFunc>> std::pair<DrAllocFunc, DrSharedAllocFunc>>

View File

@ -1039,9 +1039,8 @@ HttpAppFramework &HttpAppFrameworkImpl::setCustomErrorHandler(
return *this; return *this;
} }
const std::function<HttpResponsePtr(HttpStatusCode, const std::function<HttpResponsePtr(HttpStatusCode, const HttpRequestPtr &req)>
const HttpRequestPtr &req)> & &HttpAppFrameworkImpl::getCustomErrorHandler() const
HttpAppFrameworkImpl::getCustomErrorHandler() const
{ {
return customErrorHandler_; return customErrorHandler_;
} }

View File

@ -586,8 +586,8 @@ class HttpAppFrameworkImpl final : public HttpAppFramework
bool areAllDbClientsAvailable() const noexcept override; bool areAllDbClientsAvailable() const noexcept override;
const std::function<HttpResponsePtr(HttpStatusCode, const std::function<HttpResponsePtr(HttpStatusCode,
const HttpRequestPtr &req)> & const HttpRequestPtr &req)>
getCustomErrorHandler() const override; &getCustomErrorHandler() const override;
bool isUsingCustomErrorHandler() const bool isUsingCustomErrorHandler() const
{ {

View File

@ -169,10 +169,9 @@ class HttpRequestImpl : public HttpRequest
pathEncode_ = pathEncode; pathEncode_ = pathEncode;
} }
const std::unordered_map<std::string, const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &parameters() const override
parameters() const override
{ {
parseParametersOnce(); parseParametersOnce();
return parameters_; return parameters_;
@ -342,18 +341,16 @@ class HttpRequestImpl : public HttpRequest
return defaultVal; return defaultVal;
} }
const std::unordered_map<std::string, const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &headers() const override
headers() const override
{ {
return headers_; return headers_;
} }
const std::unordered_map<std::string, const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &cookies() const override
cookies() const override
{ {
return cookies_; return cookies_;
} }

View File

@ -133,10 +133,9 @@ class DROGON_EXPORT HttpResponseImpl : public HttpResponse
removeHeaderBy(key); removeHeaderBy(key);
} }
const std::unordered_map<std::string, const std::
std::string, unordered_map<std::string, std::string, utils::internal::SafeStringHash>
utils::internal::SafeStringHash> & &headers() const override
headers() const override
{ {
return headers_; return headers_;
} }
@ -207,8 +206,8 @@ class DROGON_EXPORT HttpResponseImpl : public HttpResponse
} }
const std:: const std::
unordered_map<std::string, Cookie, utils::internal::SafeStringHash> & unordered_map<std::string, Cookie, utils::internal::SafeStringHash>
cookies() const override &cookies() const override
{ {
return cookies_; return cookies_;
} }