From a71e37d86e4b106b27c2911bc52b1baa3fa59ab9 Mon Sep 17 00:00:00 2001 From: An Tao Date: Fri, 1 Nov 2019 19:19:25 +0800 Subject: [PATCH] Modify some type names to meet the Google Style (#291) --- lib/inc/drogon/IOThreadStorage.h | 26 ++++++---- lib/src/HttpRequestParser.cc | 2 +- orm_lib/inc/drogon/orm/Field.h | 6 +-- orm_lib/inc/drogon/orm/Result.h | 48 +++++++++---------- orm_lib/inc/drogon/orm/ResultIterator.h | 17 +++---- orm_lib/inc/drogon/orm/Row.h | 18 +++---- orm_lib/inc/drogon/orm/RowIterator.h | 17 +++---- orm_lib/inc/drogon/orm/SqlBinder.h | 2 +- orm_lib/src/Field.cc | 4 +- orm_lib/src/Result.cc | 32 ++++++------- orm_lib/src/ResultImpl.h | 20 ++++---- orm_lib/src/Row.cc | 10 ++-- orm_lib/src/mysql_impl/MysqlConnection.cc | 2 +- orm_lib/src/mysql_impl/MysqlResultImpl.cc | 18 +++---- orm_lib/src/mysql_impl/MysqlResultImpl.h | 35 +++++++------- .../postgresql_impl/PostgreSQLResultImpl.cc | 26 +++++----- .../postgresql_impl/PostgreSQLResultImpl.h | 22 ++++----- orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.cc | 20 ++++---- orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h | 20 ++++---- trantor | 2 +- 20 files changed, 178 insertions(+), 169 deletions(-) diff --git a/lib/inc/drogon/IOThreadStorage.h b/lib/inc/drogon/IOThreadStorage.h index b08516aa..510f4edb 100644 --- a/lib/inc/drogon/IOThreadStorage.h +++ b/lib/inc/drogon/IOThreadStorage.h @@ -60,7 +60,8 @@ template class IOThreadStorage : public trantor::NonCopyable { public: - using InitCallback = std::function; + using ValueType = C; + using InitCallback = std::function; template IOThreadStorage(Args &&... args) @@ -93,14 +94,14 @@ class IOThreadStorage : public trantor::NonCopyable * * This function may only be called in a request handler */ - inline C &getThreadData() + inline ValueType &getThreadData() { size_t idx = app().getCurrentThreadIndex(); assert(idx < _storage.size()); return _storage[idx]; } - inline const C &getThreadData() const + inline const ValueType &getThreadData() const { size_t idx = app().getCurrentThreadIndex(); assert(idx < _storage.size()); @@ -112,39 +113,46 @@ class IOThreadStorage : public trantor::NonCopyable * * This function may only be called in a request handler */ - inline void setThreadData(const C &newData) + inline void setThreadData(const ValueType &newData) { size_t idx = app().getCurrentThreadIndex(); assert(idx < _storage.size()); _storage[idx] = newData; } - inline void setThreadData(C &&newData) + inline void setThreadData(ValueType &&newData) { size_t idx = app().getCurrentThreadIndex(); assert(idx < _storage.size()); _storage[idx] = std::move(newData); } - inline C *operator->() + inline ValueType *operator->() { size_t idx = app().getCurrentThreadIndex(); assert(idx < _storage.size()); return &_storage[idx]; } - inline C &operator*() + inline ValueType &operator*() { return getThreadData(); } - inline const C &operator*() const + inline const ValueType *operator->() const + { + size_t idx = app().getCurrentThreadIndex(); + assert(idx < _storage.size()); + return &_storage[idx]; + } + + inline const ValueType &operator*() const { return getThreadData(); } private: - std::vector _storage; + std::vector _storage; }; } // namespace drogon diff --git a/lib/src/HttpRequestParser.cc b/lib/src/HttpRequestParser.cc index 0f63160b..c67fed17 100644 --- a/lib/src/HttpRequestParser.cc +++ b/lib/src/HttpRequestParser.cc @@ -121,7 +121,7 @@ void HttpRequestParser::reset() } else { - auto req = _requestsPool.back(); + auto req = std::move(_requestsPool.back()); _requestsPool.pop_back(); _request = std::move(req); _request->setCreationDate(trantor::Date::now()); diff --git a/orm_lib/inc/drogon/orm/Field.h b/orm_lib/inc/drogon/orm/Field.h index b66d65ad..a15b5cf9 100644 --- a/orm_lib/inc/drogon/orm/Field.h +++ b/orm_lib/inc/drogon/orm/Field.h @@ -86,7 +86,7 @@ namespace orm class Field { public: - using size_type = unsigned long; + using SizeType = unsigned long; /// Column name const char *name() const; @@ -189,7 +189,7 @@ class Field } protected: - Result::size_type _row; + Result::SizeType _row; /** * Column number * You'd expect this to be a size_t, but due to the way reverse iterators @@ -197,7 +197,7 @@ class Field */ long _column; friend class Row; - Field(const Row &row, Row::size_type columnNum) noexcept; + Field(const Row &row, Row::SizeType columnNum) noexcept; private: const Result _result; diff --git a/orm_lib/inc/drogon/orm/Result.h b/orm_lib/inc/drogon/orm/Result.h index 8ee1655a..f98cd839 100644 --- a/orm_lib/inc/drogon/orm/Result.h +++ b/orm_lib/inc/drogon/orm/Result.h @@ -19,6 +19,7 @@ #include #include +#include #ifdef _WIN32 #define noexcept _NOEXCEPT #endif @@ -45,10 +46,10 @@ enum class SqlStatus * number: * * @code - * for (result::size_type i=0; i < R.size(); ++i) Process(R[i]); + * for (Result::SizeType i=0; i < R.size(); ++i) Process(R[i]); * @endcode * - * Result sets in libpqxx are lightweight, reference-counted wrapper objects + * Result sets in libpqxx are lightweight, Reference-counted wrapper objects * which are relatively small and cheap to copy. Think of a result object as * a "smart pointer" to an underlying result set. */ @@ -58,19 +59,19 @@ class Result Result(const ResultImplPtr &ptr) : _resultPtr(ptr) { } - using difference_type = long; - using size_type = unsigned long; - using reference = Row; + using DifferenceType = long; + using SizeType = unsigned long; + using Reference = Row; using ConstIterator = ConstResultIterator; using Iterator = ConstIterator; - using row_size_type = unsigned long; - using field_size_type = unsigned long; + using RowSizeType = unsigned long; + using FieldSizeType = unsigned long; using ConstReverseIterator = ConstReverseResultIterator; using ReverseIterator = ConstReverseIterator; - size_type size() const noexcept; - size_type capacity() const noexcept + SizeType size() const noexcept; + SizeType capacity() const noexcept { return size(); } @@ -89,18 +90,18 @@ class Result return size() == 0; } - reference front() const noexcept; - reference back() const noexcept; + Reference front() const noexcept; + Reference back() const noexcept; - reference operator[](size_type index) const; - reference at(size_type index) const; + Reference operator[](SizeType index) const; + Reference at(SizeType index) const; void swap(Result &) noexcept; /// Number of columns in result. - row_size_type columns() const noexcept; + RowSizeType columns() const noexcept; /// Name of column with this number (throws exception if it doesn't exist) - const char *columnName(row_size_type number) const; + const char *columnName(RowSizeType number) const; /// If command was @c INSERT, @c UPDATE, or @c DELETE: number of affected /// rows @@ -108,7 +109,7 @@ class Result * @return Number of affected rows if last command was @c INSERT, @c UPDATE, * or @c DELETE; zero for all other commands. */ - size_type affectedRows() const noexcept; + SizeType affectedRows() const noexcept; /// For Mysql, Sqlite3 databases, return the auto-incrementing primary key /// after inserting @@ -128,18 +129,18 @@ class Result friend class Field; friend class Row; /// Number of given column (throws exception if it doesn't exist). - row_size_type columnNumber(const char colName[]) const; + RowSizeType columnNumber(const char colName[]) const; /// Number of given column (throws exception if it doesn't exist). - row_size_type columnNumber(const std::string &name) const + RowSizeType columnNumber(const std::string &name) const { return columnNumber(name.c_str()); } /// Get the column oid, for postgresql database - int oid(row_size_type column) const noexcept; + int oid(RowSizeType column) const noexcept; - const char *getValue(size_type row, row_size_type column) const; - bool isNull(size_type row, row_size_type column) const; - field_size_type getLength(size_type row, row_size_type column) const; + const char *getValue(SizeType row, RowSizeType column) const; + bool isNull(SizeType row, RowSizeType column) const; + FieldSizeType getLength(SizeType row, RowSizeType column) const; protected: Result() @@ -156,8 +157,7 @@ inline void swap(Result &one, Result &two) noexcept namespace std { template <> -inline void swap(drogon::orm::Result &one, - drogon::orm::Result &two) noexcept +inline void swap(drogon::orm::Result &one, drogon::orm::Result &two) noexcept { one.swap(two); } diff --git a/orm_lib/inc/drogon/orm/ResultIterator.h b/orm_lib/inc/drogon/orm/ResultIterator.h index e9f6dce8..5e46c1b5 100644 --- a/orm_lib/inc/drogon/orm/ResultIterator.h +++ b/orm_lib/inc/drogon/orm/ResultIterator.h @@ -26,16 +26,17 @@ namespace orm class ConstResultIterator : public std::iterator, protected Row { public: using pointer = const Row *; - using reference = Row; - using size_type = Result::size_type; - using difference_type = Result::difference_type; + using reference = const Row &; + using value_type = const Row; + using size_type = Result::SizeType; + using difference_type = Result::DifferenceType; // ConstResultIterator(const Row &t) noexcept : Row(t) {} pointer operator->() @@ -44,7 +45,7 @@ class ConstResultIterator } reference operator*() { - return Row(*this); + return *this; } ConstResultIterator operator++(int); @@ -97,7 +98,7 @@ class ConstResultIterator private: friend class Result; - ConstResultIterator(const Result &r, size_type index) noexcept + ConstResultIterator(const Result &r, SizeType index) noexcept : Row(r, index) { } @@ -111,8 +112,8 @@ class ConstReverseResultIterator : private ConstResultIterator using iterator_type::difference_type; using iterator_type::iterator_category; using iterator_type::pointer; - using value_type = iterator_type::value_type; - using reference = iterator_type::reference; + using iterator_type::value_type; + using iterator_type::reference; ConstReverseResultIterator(const ConstReverseResultIterator &rhs) : ConstResultIterator(rhs) diff --git a/orm_lib/inc/drogon/orm/Row.h b/orm_lib/inc/drogon/orm/Row.h index 91758660..f963ee24 100644 --- a/orm_lib/inc/drogon/orm/Row.h +++ b/orm_lib/inc/drogon/orm/Row.h @@ -44,19 +44,19 @@ class ConstReverseRowIterator; class Row { public: - using size_type = unsigned long; - using reference = Field; + using SizeType = unsigned long; + using Reference = Field; using ConstIterator = ConstRowIterator; using Iterator = ConstIterator; using ConstReverseIterator = ConstReverseRowIterator; - using difference_type = long; + using DifferenceType = long; - reference operator[](size_type index) const; - reference operator[](const char columnName[]) const; - reference operator[](const std::string &columnName) const; - size_type size() const; - size_type capacity() const noexcept + Reference operator[](SizeType index) const; + Reference operator[](const char columnName[]) const; + Reference operator[](const std::string &columnName) const; + SizeType size() const; + SizeType capacity() const noexcept { return size(); } @@ -83,7 +83,7 @@ class Row long _index = 0; size_t _end = 0; friend class Result; - Row(const Result &r, size_type index) noexcept; + Row(const Result &r, SizeType index) noexcept; }; } // namespace orm diff --git a/orm_lib/inc/drogon/orm/RowIterator.h b/orm_lib/inc/drogon/orm/RowIterator.h index 54c2a76b..c278fdcb 100644 --- a/orm_lib/inc/drogon/orm/RowIterator.h +++ b/orm_lib/inc/drogon/orm/RowIterator.h @@ -25,16 +25,17 @@ namespace orm { class ConstRowIterator : public std::iterator, protected Field { public: using pointer = const Field *; - using reference = Field; - using size_type = Row::size_type; - using difference_type = Row::difference_type; + using reference = const Field &; + using value_type = const Field; + using size_type = Row::SizeType; + using difference_type = Row::DifferenceType; // ConstRowIterator(const Field &t) noexcept : Field(t) {} pointer operator->() @@ -43,7 +44,7 @@ class ConstRowIterator : public std::iterator::ItemsType>(); value = - makeValue((*row)[(Row::size_type)sizeof...(Values)]); + makeValue((*row)[(Row::SizeType)sizeof...(Values)]); } run(row, isNull, std::forward(values)..., std::move(value)); diff --git a/orm_lib/src/Field.cc b/orm_lib/src/Field.cc index 7ddfc544..139b45f9 100644 --- a/orm_lib/src/Field.cc +++ b/orm_lib/src/Field.cc @@ -18,8 +18,8 @@ #include using namespace drogon::orm; -Field::Field(const Row &row, Row::size_type columnNum) noexcept - : _row(Result::size_type(row._index)), +Field::Field(const Row &row, Row::SizeType columnNum) noexcept + : _row(Result::SizeType(row._index)), _column(columnNum), _result(row._result) { diff --git a/orm_lib/src/Result.cc b/orm_lib/src/Result.cc index f64cc674..2d404bee 100644 --- a/orm_lib/src/Result.cc +++ b/orm_lib/src/Result.cc @@ -22,7 +22,7 @@ using namespace drogon::orm; Result::ConstIterator Result::begin() const noexcept { - return ConstIterator(*this, (size_type)0); + return ConstIterator(*this, (SizeType)0); } Result::ConstIterator Result::cbegin() const noexcept { @@ -60,22 +60,22 @@ Result::ConstIterator Result::ConstReverseIterator::base() const noexcept return ++tmp; } -Result::reference Result::front() const noexcept +Result::Reference Result::front() const noexcept { return Row(*this, 0); } -Result::reference Result::back() const noexcept +Result::Reference Result::back() const noexcept { return Row(*this, size() - 1); } -Result::reference Result::operator[](size_type index) const +Result::Reference Result::operator[](SizeType index) const { assert(index < size()); return Row(*this, index); } -Result::reference Result::at(size_type index) const +Result::Reference Result::at(SizeType index) const { return operator[](index); } @@ -107,7 +107,7 @@ ConstReverseResultIterator ConstReverseResultIterator::operator--(int) return old; } -Result::size_type Result::size() const noexcept +Result::SizeType Result::size() const noexcept { return _resultPtr->size(); } @@ -115,33 +115,33 @@ void Result::swap(Result &other) noexcept { _resultPtr.swap(other._resultPtr); } -Result::row_size_type Result::columns() const noexcept +Result::RowSizeType Result::columns() const noexcept { return _resultPtr->columns(); } -const char *Result::columnName(Result::row_size_type number) const +const char *Result::columnName(Result::RowSizeType number) const { return _resultPtr->columnName(number); } -Result::size_type Result::affectedRows() const noexcept +Result::SizeType Result::affectedRows() const noexcept { return _resultPtr->affectedRows(); } -Result::row_size_type Result::columnNumber(const char colName[]) const +Result::RowSizeType Result::columnNumber(const char colName[]) const { return _resultPtr->columnNumber(colName); } -const char *Result::getValue(Result::size_type row, - Result::row_size_type column) const +const char *Result::getValue(Result::SizeType row, + Result::RowSizeType column) const { return _resultPtr->getValue(row, column); } -bool Result::isNull(Result::size_type row, Result::row_size_type column) const +bool Result::isNull(Result::SizeType row, Result::RowSizeType column) const { return _resultPtr->isNull(row, column); } -Result::field_size_type Result::getLength(Result::size_type row, - Result::row_size_type column) const +Result::FieldSizeType Result::getLength(Result::SizeType row, + Result::RowSizeType column) const { return _resultPtr->getLength(row, column); } @@ -154,7 +154,7 @@ const std::string &Result::sql() const noexcept return _resultPtr->sql(); } -int Result::oid(row_size_type column) const noexcept +int Result::oid(RowSizeType column) const noexcept { return _resultPtr->oid(column); } \ No newline at end of file diff --git a/orm_lib/src/ResultImpl.h b/orm_lib/src/ResultImpl.h index 81a90cba..55e980f2 100644 --- a/orm_lib/src/ResultImpl.h +++ b/orm_lib/src/ResultImpl.h @@ -26,15 +26,15 @@ class ResultImpl : public trantor::NonCopyable, public Result ResultImpl(const std::string &query) : _query(query) { } - virtual size_type size() const noexcept = 0; - virtual row_size_type columns() const noexcept = 0; - virtual const char *columnName(row_size_type Number) const = 0; - virtual size_type affectedRows() const noexcept = 0; - virtual row_size_type columnNumber(const char colName[]) const = 0; - virtual const char *getValue(size_type row, row_size_type column) const = 0; - virtual bool isNull(size_type row, row_size_type column) const = 0; - virtual field_size_type getLength(size_type row, - row_size_type column) const = 0; + virtual SizeType size() const noexcept = 0; + virtual RowSizeType columns() const noexcept = 0; + virtual const char *columnName(RowSizeType Number) const = 0; + virtual SizeType affectedRows() const noexcept = 0; + virtual RowSizeType columnNumber(const char colName[]) const = 0; + virtual const char *getValue(SizeType row, RowSizeType column) const = 0; + virtual bool isNull(SizeType row, RowSizeType column) const = 0; + virtual FieldSizeType getLength(SizeType row, + RowSizeType column) const = 0; virtual const std::string &sql() const { return _query; @@ -43,7 +43,7 @@ class ResultImpl : public trantor::NonCopyable, public Result { return 0; } - virtual int oid(row_size_type column) const + virtual int oid(RowSizeType column) const { (void)column; return 0; diff --git a/orm_lib/src/Row.cc b/orm_lib/src/Row.cc index fd62517a..25f07ad9 100644 --- a/orm_lib/src/Row.cc +++ b/orm_lib/src/Row.cc @@ -18,28 +18,28 @@ #include using namespace drogon::orm; -Row::Row(const Result &r, size_type index) noexcept +Row::Row(const Result &r, SizeType index) noexcept : _result(r), _index(long(index)), _end(r.columns()) { } -Row::size_type Row::size() const +Row::SizeType Row::size() const { return _end; } -Row::reference Row::operator[](size_type index) const +Row::Reference Row::operator[](SizeType index) const { if (index >= _end) throw RangeError("The indwx out of range"); return Field(*this, index); } -Row::reference Row::operator[](const char columnName[]) const +Row::Reference Row::operator[](const char columnName[]) const { auto N = _result.columnNumber(columnName); return Field(*this, N); } -Row::reference Row::operator[](const std::string &columnName) const +Row::Reference Row::operator[](const std::string &columnName) const { return operator[](columnName.c_str()); } diff --git a/orm_lib/src/mysql_impl/MysqlConnection.cc b/orm_lib/src/mysql_impl/MysqlConnection.cc index 8b273820..0e510eda 100644 --- a/orm_lib/src/mysql_impl/MysqlConnection.cc +++ b/orm_lib/src/mysql_impl/MysqlConnection.cc @@ -27,7 +27,7 @@ namespace orm Result makeResult( const std::shared_ptr &r = std::shared_ptr(nullptr), const std::string &query = "", - Result::size_type affectedRows = 0, + Result::SizeType affectedRows = 0, unsigned long long insertId = 0) { return Result(std::shared_ptr( diff --git a/orm_lib/src/mysql_impl/MysqlResultImpl.cc b/orm_lib/src/mysql_impl/MysqlResultImpl.cc index 6a39dcc4..4e1d611e 100644 --- a/orm_lib/src/mysql_impl/MysqlResultImpl.cc +++ b/orm_lib/src/mysql_impl/MysqlResultImpl.cc @@ -18,26 +18,26 @@ using namespace drogon::orm; -Result::size_type MysqlResultImpl::size() const noexcept +Result::SizeType MysqlResultImpl::size() const noexcept { return _rowsNum; } -Result::row_size_type MysqlResultImpl::columns() const noexcept +Result::RowSizeType MysqlResultImpl::columns() const noexcept { return _fieldNum; } -const char *MysqlResultImpl::columnName(row_size_type number) const +const char *MysqlResultImpl::columnName(RowSizeType number) const { assert(number < _fieldNum); if (_fieldArray) return _fieldArray[number].name; return ""; } -Result::size_type MysqlResultImpl::affectedRows() const noexcept +Result::SizeType MysqlResultImpl::affectedRows() const noexcept { return _affectedRows; } -Result::row_size_type MysqlResultImpl::columnNumber(const char colName[]) const +Result::RowSizeType MysqlResultImpl::columnNumber(const char colName[]) const { if (!_fieldMapPtr) return -1; @@ -47,7 +47,7 @@ Result::row_size_type MysqlResultImpl::columnNumber(const char colName[]) const return (*_fieldMapPtr)[col]; return -1; } -const char *MysqlResultImpl::getValue(size_type row, row_size_type column) const +const char *MysqlResultImpl::getValue(SizeType row, RowSizeType column) const { if (_rowsNum == 0 || _fieldNum == 0) return NULL; @@ -55,12 +55,12 @@ const char *MysqlResultImpl::getValue(size_type row, row_size_type column) const assert(column < _fieldNum); return (*_rowsPtr)[row].first[column]; } -bool MysqlResultImpl::isNull(size_type row, row_size_type column) const +bool MysqlResultImpl::isNull(SizeType row, RowSizeType column) const { return getValue(row, column) == NULL; } -Result::field_size_type MysqlResultImpl::getLength(size_type row, - row_size_type column) const +Result::FieldSizeType MysqlResultImpl::getLength(SizeType row, + RowSizeType column) const { if (_rowsNum == 0 || _fieldNum == 0) return 0; diff --git a/orm_lib/src/mysql_impl/MysqlResultImpl.h b/orm_lib/src/mysql_impl/MysqlResultImpl.h index 8c8c7f40..dd807a2c 100644 --- a/orm_lib/src/mysql_impl/MysqlResultImpl.h +++ b/orm_lib/src/mysql_impl/MysqlResultImpl.h @@ -31,7 +31,7 @@ class MysqlResultImpl : public ResultImpl public: MysqlResultImpl(const std::shared_ptr &r, const std::string &query, - size_type affectedRows, + SizeType affectedRows, unsigned long long insertId) noexcept : ResultImpl(query), _result(r), @@ -44,8 +44,8 @@ class MysqlResultImpl : public ResultImpl if (_fieldNum > 0) { _fieldMapPtr = std::make_shared< - std::unordered_map>(); - for (row_size_type i = 0; i < _fieldNum; i++) + std::unordered_map>(); + for (RowSizeType i = 0; i < _fieldNum; i++) { std::string fieldName = _fieldArray[i].name; std::transform(fieldName.begin(), @@ -72,27 +72,26 @@ class MysqlResultImpl : public ResultImpl } } } - virtual size_type size() const noexcept override; - virtual row_size_type columns() const noexcept override; - virtual const char *columnName(row_size_type number) const override; - virtual size_type affectedRows() const noexcept override; - virtual row_size_type columnNumber(const char colName[]) const override; - virtual const char *getValue(size_type row, - row_size_type column) const override; - virtual bool isNull(size_type row, row_size_type column) const override; - virtual field_size_type getLength(size_type row, - row_size_type column) const override; + virtual SizeType size() const noexcept override; + virtual RowSizeType columns() const noexcept override; + virtual const char *columnName(RowSizeType number) const override; + virtual SizeType affectedRows() const noexcept override; + virtual RowSizeType columnNumber(const char colName[]) const override; + virtual const char *getValue(SizeType row, + RowSizeType column) const override; + virtual bool isNull(SizeType row, RowSizeType column) const override; + virtual FieldSizeType getLength(SizeType row, + RowSizeType column) const override; virtual unsigned long long insertId() const noexcept override; private: const std::shared_ptr _result; - const Result::size_type _rowsNum; + const Result::SizeType _rowsNum; const MYSQL_FIELD *_fieldArray; - const Result::row_size_type _fieldNum; - const size_type _affectedRows; + const Result::RowSizeType _fieldNum; + const SizeType _affectedRows; const unsigned long long _insertId; - std::shared_ptr> - _fieldMapPtr; + std::shared_ptr> _fieldMapPtr; std::shared_ptr>>> _rowsPtr; }; diff --git a/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.cc b/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.cc index 9844dcf1..5833ce34 100644 --- a/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.cc +++ b/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.cc @@ -17,16 +17,16 @@ using namespace drogon::orm; -Result::size_type PostgreSQLResultImpl::size() const noexcept +Result::SizeType PostgreSQLResultImpl::size() const noexcept { return _result ? PQntuples(_result.get()) : 0; } -Result::row_size_type PostgreSQLResultImpl::columns() const noexcept +Result::RowSizeType PostgreSQLResultImpl::columns() const noexcept { auto ptr = const_cast(_result.get()); - return ptr ? Result::row_size_type(PQnfields(ptr)) : 0; + return ptr ? Result::RowSizeType(PQnfields(ptr)) : 0; } -const char *PostgreSQLResultImpl::columnName(row_size_type number) const +const char *PostgreSQLResultImpl::columnName(RowSizeType number) const { auto ptr = const_cast(_result.get()); if (ptr) @@ -37,14 +37,14 @@ const char *PostgreSQLResultImpl::columnName(row_size_type number) const } throw "nullptr result"; // The program will never execute here } -Result::size_type PostgreSQLResultImpl::affectedRows() const noexcept +Result::SizeType PostgreSQLResultImpl::affectedRows() const noexcept { char *str = PQcmdTuples(_result.get()); if (str == nullptr || str[0] == '\0') return 0; return atol(str); } -Result::row_size_type PostgreSQLResultImpl::columnNumber( +Result::RowSizeType PostgreSQLResultImpl::columnNumber( const char colName[]) const { auto ptr = const_cast(_result.get()); @@ -58,22 +58,22 @@ Result::row_size_type PostgreSQLResultImpl::columnNumber( } throw "nullptr result"; // The program will never execute here } -const char *PostgreSQLResultImpl::getValue(size_type row, - row_size_type column) const +const char *PostgreSQLResultImpl::getValue(SizeType row, + RowSizeType column) const { return PQgetvalue(_result.get(), int(row), int(column)); } -bool PostgreSQLResultImpl::isNull(size_type row, row_size_type column) const +bool PostgreSQLResultImpl::isNull(SizeType row, RowSizeType column) const { return PQgetisnull(_result.get(), int(row), int(column)) != 0; } -Result::field_size_type PostgreSQLResultImpl::getLength( - size_type row, - row_size_type column) const +Result::FieldSizeType PostgreSQLResultImpl::getLength( + SizeType row, + RowSizeType column) const { return PQgetlength(_result.get(), int(row), int(column)); } -int PostgreSQLResultImpl::oid(row_size_type column) const +int PostgreSQLResultImpl::oid(RowSizeType column) const { return PQftype(_result.get(), (int)column); } diff --git a/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.h b/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.h index 5c17e1bb..001f18b2 100644 --- a/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.h +++ b/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.h @@ -32,17 +32,17 @@ class PostgreSQLResultImpl : public ResultImpl : ResultImpl(query), _result(r) { } - virtual size_type size() const noexcept override; - virtual row_size_type columns() const noexcept override; - virtual const char *columnName(row_size_type number) const override; - virtual size_type affectedRows() const noexcept override; - virtual row_size_type columnNumber(const char colName[]) const override; - virtual const char *getValue(size_type row, - row_size_type column) const override; - virtual bool isNull(size_type row, row_size_type column) const override; - virtual field_size_type getLength(size_type row, - row_size_type column) const override; - virtual int oid(row_size_type column) const override; + virtual SizeType size() const noexcept override; + virtual RowSizeType columns() const noexcept override; + virtual const char *columnName(RowSizeType number) const override; + virtual SizeType affectedRows() const noexcept override; + virtual RowSizeType columnNumber(const char colName[]) const override; + virtual const char *getValue(SizeType row, + RowSizeType column) const override; + virtual bool isNull(SizeType row, RowSizeType column) const override; + virtual FieldSizeType getLength(SizeType row, + RowSizeType column) const override; + virtual int oid(RowSizeType column) const override; private: std::shared_ptr _result; diff --git a/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.cc b/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.cc index afce4262..a088f40e 100644 --- a/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.cc +++ b/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.cc @@ -18,24 +18,24 @@ using namespace drogon::orm; -Result::size_type Sqlite3ResultImpl::size() const noexcept +Result::SizeType Sqlite3ResultImpl::size() const noexcept { return _result.size(); } -Result::row_size_type Sqlite3ResultImpl::columns() const noexcept +Result::RowSizeType Sqlite3ResultImpl::columns() const noexcept { return _result.empty() ? 0 : _result[0].size(); } -const char *Sqlite3ResultImpl::columnName(row_size_type number) const +const char *Sqlite3ResultImpl::columnName(RowSizeType number) const { assert(number < _columnNames.size()); return _columnNames[number].c_str(); } -Result::size_type Sqlite3ResultImpl::affectedRows() const noexcept +Result::SizeType Sqlite3ResultImpl::affectedRows() const noexcept { return _affectedRows; } -Result::row_size_type Sqlite3ResultImpl::columnNumber( +Result::RowSizeType Sqlite3ResultImpl::columnNumber( const char colName[]) const { auto name = std::string(colName); @@ -47,18 +47,18 @@ Result::row_size_type Sqlite3ResultImpl::columnNumber( } throw std::string("there is no column named ") + colName; } -const char *Sqlite3ResultImpl::getValue(size_type row, - row_size_type column) const +const char *Sqlite3ResultImpl::getValue(SizeType row, + RowSizeType column) const { auto col = _result[row][column]; return col ? col->c_str() : nullptr; } -bool Sqlite3ResultImpl::isNull(size_type row, row_size_type column) const +bool Sqlite3ResultImpl::isNull(SizeType row, RowSizeType column) const { return !_result[row][column]; } -Result::field_size_type Sqlite3ResultImpl::getLength(size_type row, - row_size_type column) const +Result::FieldSizeType Sqlite3ResultImpl::getLength(SizeType row, + RowSizeType column) const { auto col = _result[row][column]; return col ? col->length() : 0; diff --git a/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h b/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h index 193dad1b..683548d5 100644 --- a/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h +++ b/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h @@ -33,16 +33,16 @@ class Sqlite3ResultImpl : public ResultImpl : ResultImpl(query) { } - virtual size_type size() const noexcept override; - virtual row_size_type columns() const noexcept override; - virtual const char *columnName(row_size_type number) const override; - virtual size_type affectedRows() const noexcept override; - virtual row_size_type columnNumber(const char colName[]) const override; - virtual const char *getValue(size_type row, - row_size_type column) const override; - virtual bool isNull(size_type row, row_size_type column) const override; - virtual field_size_type getLength(size_type row, - row_size_type column) const override; + virtual SizeType size() const noexcept override; + virtual RowSizeType columns() const noexcept override; + virtual const char *columnName(RowSizeType number) const override; + virtual SizeType affectedRows() const noexcept override; + virtual RowSizeType columnNumber(const char colName[]) const override; + virtual const char *getValue(SizeType row, + RowSizeType column) const override; + virtual bool isNull(SizeType row, RowSizeType column) const override; + virtual FieldSizeType getLength(SizeType row, + RowSizeType column) const override; virtual unsigned long long insertId() const noexcept override; private: diff --git a/trantor b/trantor index 01d39264..07771f6c 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit 01d39264350bb972c8c91df6f7055a27b2e8050f +Subproject commit 07771f6c19a7baba33d069cd8c9b1a65281faac4