Merge pull request #35 from an-tao/dev
Use references instead of values in range-based for loop
This commit is contained in:
commit
b17263c182
|
@ -253,7 +253,7 @@ void create_controller::createController(std::vector<std::string> &httpClasses,
|
|||
return;
|
||||
}
|
||||
}
|
||||
for (auto className : httpClasses)
|
||||
for (auto const &className : httpClasses)
|
||||
{
|
||||
createController(className, type);
|
||||
}
|
||||
|
|
|
@ -386,7 +386,7 @@ void create_model::createModelClassFromMysql(const std::string &path, const DbCl
|
|||
exit(1);
|
||||
};
|
||||
std::vector<std::string> pkNames, pkTypes;
|
||||
for (auto col : cols)
|
||||
for (auto const &col : cols)
|
||||
{
|
||||
if (col._isPrimaryKey)
|
||||
{
|
||||
|
@ -508,7 +508,7 @@ void create_model::createModelClassFromSqlite3(const std::string &path, const Db
|
|||
}
|
||||
|
||||
std::vector<std::string> pkNames, pkTypes;
|
||||
for (auto col : cols)
|
||||
for (auto const &col : cols)
|
||||
{
|
||||
if (col._isPrimaryKey)
|
||||
{
|
||||
|
@ -764,7 +764,7 @@ void create_model::handleCommand(std::vector<std::string> ¶meters)
|
|||
{
|
||||
std::cerr << "Missing Model path name!" << std::endl;
|
||||
}
|
||||
for (auto path : parameters)
|
||||
for (auto const &path : parameters)
|
||||
{
|
||||
createModel(path);
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ void create_view::handleCommand(std::vector<std::string> ¶meters)
|
|||
void create_view::createViewFiles(std::vector<std::string> &cspFileNames)
|
||||
{
|
||||
|
||||
for (auto file : cspFileNames)
|
||||
for (auto const &file : cspFileNames)
|
||||
{
|
||||
std::cout << "create view:" << file << std::endl;
|
||||
createViewFile(file);
|
||||
|
|
|
@ -23,7 +23,7 @@ void help::handleCommand(std::vector<std::string> ¶meters)
|
|||
{
|
||||
std::cout << "usage: drogon_ctl <command> [<args>]" << std::endl;
|
||||
std::cout << "commands list:" << std::endl;
|
||||
for (auto className : drogon::DrClassMap::getAllClassName())
|
||||
for (auto &className : drogon::DrClassMap::getAllClassName())
|
||||
{
|
||||
auto classPtr = std::shared_ptr<DrObjectBase>(drogon::DrClassMap::newObject(className));
|
||||
if (classPtr)
|
||||
|
|
|
@ -20,7 +20,7 @@ int main()
|
|||
count++;
|
||||
std::cout << response->getBody() << std::endl;
|
||||
auto cookies = response->cookies();
|
||||
for (auto &cookie : cookies)
|
||||
for (auto const &cookie : cookies)
|
||||
{
|
||||
std::cout << cookie.first << "=" << cookie.second.value() << ":domain=" << cookie.second.domain() << std::endl;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ void Attachment::upload(const HttpRequestPtr &req,
|
|||
FileUpload fileUpload;
|
||||
fileUpload.parse(req);
|
||||
auto files = fileUpload.getFiles();
|
||||
for (auto file : files)
|
||||
for (auto const &file : files)
|
||||
{
|
||||
LOG_DEBUG << "file:"
|
||||
<< file.getFileName()
|
||||
|
|
|
@ -127,7 +127,7 @@ class HttpAppFramework : public trantor::NonCopyable
|
|||
|
||||
std::vector<HttpMethod> validMethods;
|
||||
std::vector<std::string> filters;
|
||||
for (auto &filterOrMethod : filtersAndMethods)
|
||||
for (auto const &filterOrMethod : filtersAndMethods)
|
||||
{
|
||||
if (filterOrMethod.type() == typeid(std::string))
|
||||
{
|
||||
|
|
|
@ -61,9 +61,10 @@ class HttpSimpleController : public DrObject<T>, public HttpSimpleControllerBase
|
|||
}
|
||||
|
||||
protected:
|
||||
///FIXME!!!
|
||||
void _register(const std::string &className, const std::vector<std::string> &paths)
|
||||
{
|
||||
for (auto reqPath : paths)
|
||||
for (auto const &reqPath : paths)
|
||||
{
|
||||
std::cout << "register controller class " << className << " on path " << reqPath << std::endl;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ class WebSocketController : public DrObject<T>, public WebSocketControllerBase
|
|||
{
|
||||
auto vPaths = T::paths();
|
||||
|
||||
for (auto path : vPaths)
|
||||
for (auto const &path : vPaths)
|
||||
{
|
||||
LOG_TRACE << "register websocket controller (" << WebSocketController<T>::classTypeName() << ") on path:" << path.first;
|
||||
HttpAppFramework::instance().registerWebSocketController(path.first,
|
||||
|
@ -80,7 +80,7 @@ class WebSocketController : public DrObject<T>, public WebSocketControllerBase
|
|||
protected:
|
||||
void _register(const std::string &className, const std::vector<std::string> &paths)
|
||||
{
|
||||
for (auto reqPath : paths)
|
||||
for (auto const &reqPath : paths)
|
||||
{
|
||||
std::cout << "register controller class " << className << " on path " << reqPath << std::endl;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ static void loadControllers(const Json::Value &controllers)
|
|||
{
|
||||
if (!controllers)
|
||||
return;
|
||||
for (auto controller : controllers)
|
||||
for (auto const &controller : controllers)
|
||||
{
|
||||
auto path = controller.get("path", "").asString();
|
||||
auto ctrlName = controller.get("controller", "").asString();
|
||||
|
@ -96,7 +96,7 @@ static void loadControllers(const Json::Value &controllers)
|
|||
std::vector<any> constraints;
|
||||
if (!controller["http_methods"].isNull())
|
||||
{
|
||||
for (auto method : controller["http_methods"])
|
||||
for (auto const &method : controller["http_methods"])
|
||||
{
|
||||
auto strMethod = method.asString();
|
||||
std::transform(strMethod.begin(), strMethod.end(), strMethod.begin(), tolower);
|
||||
|
@ -124,7 +124,7 @@ static void loadControllers(const Json::Value &controllers)
|
|||
}
|
||||
if (!controller["filters"].isNull())
|
||||
{
|
||||
for (auto filter : controller["filters"])
|
||||
for (auto const &filter : controller["filters"])
|
||||
{
|
||||
constraints.push_back(filter.asString());
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ static void loadApp(const Json::Value &app)
|
|||
if (fileTypes.isArray() && !fileTypes.empty())
|
||||
{
|
||||
std::vector<std::string> types;
|
||||
for (auto fileType : fileTypes)
|
||||
for (auto const &fileType : fileTypes)
|
||||
{
|
||||
types.push_back(fileType.asString());
|
||||
LOG_TRACE << "file type:" << types.back();
|
||||
|
@ -196,7 +196,7 @@ static void loadApp(const Json::Value &app)
|
|||
if (viewsPaths.isArray() && viewsPaths.size() > 0)
|
||||
{
|
||||
std::vector<std::string> paths;
|
||||
for (auto viewsPath : viewsPaths)
|
||||
for (auto const &viewsPath : viewsPaths)
|
||||
{
|
||||
paths.push_back(viewsPath.asString());
|
||||
LOG_TRACE << "views path:" << paths.back();
|
||||
|
@ -234,7 +234,7 @@ static void loadDbClients(const Json::Value &dbClients)
|
|||
if (!dbClients)
|
||||
return;
|
||||
#if USE_ORM
|
||||
for (auto &client : dbClients)
|
||||
for (auto const &client : dbClients)
|
||||
{
|
||||
auto type = client.get("rdbms", "postgresql").asString();
|
||||
auto host = client.get("host", "127.0.0.1").asString();
|
||||
|
@ -262,7 +262,7 @@ static void loadListeners(const Json::Value &listeners)
|
|||
if (!listeners)
|
||||
return;
|
||||
LOG_TRACE << "Has " << listeners.size() << " listeners";
|
||||
for (auto listener : listeners)
|
||||
for (auto const &listener : listeners)
|
||||
{
|
||||
auto addr = listener.get("address", "0.0.0.0").asString();
|
||||
auto port = (uint16_t)listener.get("port", 0).asUInt();
|
||||
|
|
|
@ -36,7 +36,7 @@ DrObjectBase *DrClassMap::newObject(const std::string &className)
|
|||
std::vector<std::string> DrClassMap::getAllClassName()
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
for (auto iter : getMap())
|
||||
for (auto const &iter : getMap())
|
||||
{
|
||||
ret.push_back(iter.first);
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ void HttpAppFrameworkImpl::enableDynamicViewsLoading(const std::vector<std::stri
|
|||
{
|
||||
assert(!_running);
|
||||
|
||||
for (auto &libpath : libPaths)
|
||||
for (auto const &libpath : libPaths)
|
||||
{
|
||||
if (libpath[0] == '/' ||
|
||||
(libpath.length() >= 2 && libpath[0] == '.' && libpath[1] == '/') ||
|
||||
|
@ -100,7 +100,7 @@ void HttpAppFrameworkImpl::enableDynamicViewsLoading(const std::vector<std::stri
|
|||
}
|
||||
void HttpAppFrameworkImpl::setFileTypes(const std::vector<std::string> &types)
|
||||
{
|
||||
for (auto type : types)
|
||||
for (auto const &type : types)
|
||||
{
|
||||
_fileTypeSet.insert(type);
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ void HttpAppFrameworkImpl::run()
|
|||
_running = true;
|
||||
|
||||
//Create db clients
|
||||
for (auto &fun : _dbFuncs)
|
||||
for (auto const &fun : _dbFuncs)
|
||||
{
|
||||
fun();
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ void HttpAppFrameworkImpl::run()
|
|||
std::vector<std::shared_ptr<HttpServer>> servers;
|
||||
std::vector<std::shared_ptr<EventLoopThread>> loopThreads;
|
||||
_httpCtrlsRouter.init();
|
||||
for (auto listener : _listeners)
|
||||
for (auto const &listener : _listeners)
|
||||
{
|
||||
LOG_TRACE << "thread num=" << _threadNum;
|
||||
#ifdef __linux__
|
||||
|
@ -414,7 +414,7 @@ void HttpAppFrameworkImpl::doFilters(const std::vector<std::string> &filters,
|
|||
if (!filters.empty())
|
||||
{
|
||||
filterPtrs = std::make_shared<std::queue<std::shared_ptr<HttpFilterBase>>>();
|
||||
for (auto &filter : filters)
|
||||
for (auto const &filter : filters)
|
||||
{
|
||||
auto _object = std::shared_ptr<DrObjectBase>(DrClassMap::newObject(filter));
|
||||
auto _filter = std::dynamic_pointer_cast<HttpFilterBase>(_object);
|
||||
|
|
|
@ -102,7 +102,7 @@ void HttpControllersRouter::addHttpPath(const std::string &path,
|
|||
{
|
||||
if (validMethods.size() > 0)
|
||||
{
|
||||
for (auto method : validMethods)
|
||||
for (auto const &method : validMethods)
|
||||
{
|
||||
router._binders[method] = binderInfo;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ void HttpControllersRouter::addHttpPath(const std::string &path,
|
|||
router.pathParameterPattern = pathParameterPattern;
|
||||
if (validMethods.size() > 0)
|
||||
{
|
||||
for (auto method : validMethods)
|
||||
for (auto const &method : validMethods)
|
||||
{
|
||||
router._binders[method] = binderInfo;
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ void HttpControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlBinderP
|
|||
if (ctrlBinderPtr->queryParametersPlaces.size() > 0)
|
||||
{
|
||||
auto qureyPara = req->getParameters();
|
||||
for (auto parameter : qureyPara)
|
||||
for (auto const ¶meter : qureyPara)
|
||||
{
|
||||
if (ctrlBinderPtr->queryParametersPlaces.find(parameter.first) !=
|
||||
ctrlBinderPtr->queryParametersPlaces.end())
|
||||
|
@ -264,7 +264,7 @@ void HttpControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlBinderP
|
|||
}
|
||||
}
|
||||
std::list<std::string> paraList;
|
||||
for (auto p : params)
|
||||
for (auto &p : params)///Use reference
|
||||
{
|
||||
LOG_TRACE << p;
|
||||
paraList.push_back(std::move(p));
|
||||
|
|
|
@ -125,7 +125,7 @@ void HttpRequestImpl::appendToBuffer(MsgBuffer *output) const
|
|||
if (_parameters.size() != 0)
|
||||
{
|
||||
output->append("?");
|
||||
for (auto p : _parameters)
|
||||
for (auto const &p : _parameters)
|
||||
{
|
||||
output->append(p.first);
|
||||
output->append("=");
|
||||
|
|
|
@ -345,9 +345,7 @@ void HttpResponseImpl::makeHeaderString(const std::shared_ptr<std::string> &head
|
|||
}
|
||||
}
|
||||
|
||||
for (auto it = _headers.begin();
|
||||
it != _headers.end();
|
||||
++it)
|
||||
for (auto it = _headers.begin(); it != _headers.end(); ++it)
|
||||
{
|
||||
headerStringPtr->append(it->first);
|
||||
headerStringPtr->append(": ");
|
||||
|
|
|
@ -29,7 +29,7 @@ void HttpSimpleControllersRouter::registerHttpSimpleController(const std::string
|
|||
std::lock_guard<std::mutex> guard(_simpCtrlMutex);
|
||||
std::vector<HttpMethod> validMethods;
|
||||
std::vector<std::string> filters;
|
||||
for (auto &filterOrMethod : filtersAndMethods)
|
||||
for (auto const &filterOrMethod : filtersAndMethods)
|
||||
{
|
||||
if (filterOrMethod.type() == typeid(std::string))
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ void HttpSimpleControllersRouter::registerHttpSimpleController(const std::string
|
|||
if (validMethods.size() > 0)
|
||||
{
|
||||
iterm._validMethodsFlags.resize(Invalid, 0);
|
||||
for (auto method : validMethods)
|
||||
for (auto const &method : validMethods)
|
||||
{
|
||||
iterm._validMethodsFlags[method] = 1;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ SharedLibManager::~SharedLibManager()
|
|||
}
|
||||
void SharedLibManager::managerLibs()
|
||||
{
|
||||
for (auto libPath : _libPaths)
|
||||
for (auto const &libPath : _libPaths)
|
||||
{
|
||||
forEachFileIn(libPath, [=](const std::string &filename, const struct stat &st) {
|
||||
auto pos = filename.rfind(".");
|
||||
|
|
|
@ -42,7 +42,7 @@ static inline bool is_base64(unsigned char c)
|
|||
|
||||
bool isInteger(const std::string &str)
|
||||
{
|
||||
for (auto c : str)
|
||||
for (auto const &c : str)
|
||||
{
|
||||
if (c > '9' || c < '0')
|
||||
return false;
|
||||
|
|
|
@ -468,7 +468,7 @@ inline std::vector<T> Mapper<T>::findBy(const Criteria &criteria) noexcept(false
|
|||
binder.exec(); //exec may be throw exception;
|
||||
}
|
||||
std::vector<T> ret;
|
||||
for (auto row : r)
|
||||
for (auto const &row : r)
|
||||
{
|
||||
ret.push_back(T(row));
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ inline void Mapper<T>::findBy(const Criteria &criteria,
|
|||
criteria.outputArgs(binder);
|
||||
binder >> [=](const Result &r) {
|
||||
std::vector<T> ret;
|
||||
for (auto row : r)
|
||||
for (auto const &row : r)
|
||||
{
|
||||
ret.push_back(T(row));
|
||||
}
|
||||
|
@ -530,7 +530,7 @@ inline std::future<std::vector<T>> Mapper<T>::findFutureBy(const Criteria &crite
|
|||
std::shared_ptr<std::promise<std::vector<T>>> prom = std::make_shared<std::promise<std::vector<T>>>();
|
||||
binder >> [=](const Result &r) {
|
||||
std::vector<T> ret;
|
||||
for (auto row : r)
|
||||
for (auto const &row : r)
|
||||
{
|
||||
ret.push_back(T(row));
|
||||
}
|
||||
|
@ -641,7 +641,7 @@ inline void Mapper<T>::insert(T &obj) noexcept(false)
|
|||
std::string sql = "insert into ";
|
||||
sql += T::tableName;
|
||||
sql += " (";
|
||||
for (auto colName : T::insertColumns())
|
||||
for (auto const &colName : T::insertColumns())
|
||||
{
|
||||
sql += colName;
|
||||
sql += ",";
|
||||
|
@ -688,7 +688,7 @@ inline void Mapper<T>::insert(const T &obj,
|
|||
std::string sql = "insert into ";
|
||||
sql += T::tableName;
|
||||
sql += " (";
|
||||
for (auto colName : T::insertColumns())
|
||||
for (auto const &colName : T::insertColumns())
|
||||
{
|
||||
sql += colName;
|
||||
sql += ",";
|
||||
|
@ -731,7 +731,7 @@ inline std::future<T> Mapper<T>::insertFuture(const T &obj) noexcept
|
|||
std::string sql = "insert into ";
|
||||
sql += T::tableName;
|
||||
sql += " (";
|
||||
for (auto colName : T::insertColumns())
|
||||
for (auto const &colName : T::insertColumns())
|
||||
{
|
||||
sql += colName;
|
||||
sql += ",";
|
||||
|
@ -781,7 +781,7 @@ inline size_t Mapper<T>::update(const T &obj) noexcept(false)
|
|||
std::string sql = "update ";
|
||||
sql += T::tableName;
|
||||
sql += " set ";
|
||||
for (auto colName : obj.updateColumns())
|
||||
for (auto const &colName : obj.updateColumns())
|
||||
{
|
||||
sql += colName;
|
||||
sql += " = $?,";
|
||||
|
@ -814,7 +814,7 @@ inline void Mapper<T>::update(const T &obj,
|
|||
std::string sql = "update ";
|
||||
sql += T::tableName;
|
||||
sql += " set ";
|
||||
for (auto colName : obj.updateColumns())
|
||||
for (auto const &colName : obj.updateColumns())
|
||||
{
|
||||
sql += colName;
|
||||
sql += " = $?,";
|
||||
|
@ -840,7 +840,7 @@ inline std::future<size_t> Mapper<T>::updateFuture(const T &obj) noexcept
|
|||
std::string sql = "update ";
|
||||
sql += T::tableName;
|
||||
sql += " set ";
|
||||
for (auto colName : obj.updateColumns())
|
||||
for (auto const &colName : obj.updateColumns())
|
||||
{
|
||||
sql += colName;
|
||||
sql += " = $?,";
|
||||
|
|
|
@ -160,7 +160,7 @@ class CallbackHolder : public CallbackHolderBase
|
|||
run(nullptr, true);
|
||||
return;
|
||||
}
|
||||
for (auto row : result)
|
||||
for (auto const &row : result)
|
||||
{
|
||||
run(&row, false);
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ DbClientImpl::DbClientImpl(const std::string &connInfo, const size_t connNum, Cl
|
|||
DbClientImpl::~DbClientImpl() noexcept
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_connectionsMutex);
|
||||
for (auto &conn : _connections)
|
||||
for (auto const &conn : _connections)
|
||||
{
|
||||
conn->disconnect();
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ void TransactionImpl::execNewTask()
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
for (auto &cmd : _sqlCmdBuffer)
|
||||
for (auto const &cmd : _sqlCmdBuffer)
|
||||
{
|
||||
if (cmd._exceptCb)
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ MysqlConnection::MysqlConnection(trantor::EventLoop *loop, const std::string &co
|
|||
auto tmpStr = std::regex_replace(connInfo, r, "=");
|
||||
std::string host, user, passwd, dbname, port;
|
||||
auto keyValues = splitString(tmpStr, " ");
|
||||
for (auto &kvs : keyValues)
|
||||
for (auto const &kvs : keyValues)
|
||||
{
|
||||
auto kv = splitString(kvs, "=");
|
||||
assert(kv.size() == 2);
|
||||
|
|
|
@ -26,8 +26,8 @@ int main()
|
|||
*clientPtr << "select * from users where id!=139 order by id" << Mode::Blocking >> [](const Result &r) {
|
||||
std::cout << "rows:" << r.size() << std::endl;
|
||||
std::cout << "column num:" << r.columns() << std::endl;
|
||||
|
||||
for (auto row : r)
|
||||
|
||||
for (auto const &row : r)
|
||||
{
|
||||
std::cout << "id=" << row["id"].as<int>() << std::endl;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ int main()
|
|||
[](const Result &r) {
|
||||
std::cout << "rows:" << r.size() << std::endl;
|
||||
std::cout << "column num:" << r.columns() << std::endl;
|
||||
for (auto row : r)
|
||||
for (auto const &row : r)
|
||||
{
|
||||
std::cout << "user_id=" << row["user_id"].as<std::string>() << " id=" << row["id"].as<std::string>();
|
||||
std::cout << " time=" << row["time"].as<std::string>() << std::endl;
|
||||
|
|
|
@ -23,9 +23,9 @@ int main()
|
|||
try
|
||||
{
|
||||
auto r = clientPtr->execSqlSync("select * from users where user_uuid=$1;", 1);
|
||||
for (auto row : r)
|
||||
for (auto const &row : r)
|
||||
{
|
||||
for (auto f : row)
|
||||
for (auto const &f : row)
|
||||
{
|
||||
std::cout << f.name() << " : " << f.as<int>() << std::endl;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ int main()
|
|||
try
|
||||
{
|
||||
auto r = f.get();
|
||||
for (auto row : r)
|
||||
for (auto const &row : r)
|
||||
{
|
||||
std::cout << "user_id:" << row["user_id"].as<std::string>() << std::endl;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ Sqlite3Connection::Sqlite3Connection(trantor::EventLoop *loop, const std::string
|
|||
std::string host, user, passwd, dbname, port;
|
||||
auto keyValues = splitString(tmpStr, " ");
|
||||
std::string filename;
|
||||
for (auto &kvs : keyValues)
|
||||
for (auto const &kvs : keyValues)
|
||||
{
|
||||
auto kv = splitString(kvs, "=");
|
||||
assert(kv.size() == 2);
|
||||
|
|
|
@ -49,7 +49,7 @@ int main()
|
|||
LOG_DEBUG << "affected rows:" << r.affectedRows();
|
||||
LOG_DEBUG << "select " << r.size() << " rows";
|
||||
LOG_DEBUG << "id:" << r.insertId();
|
||||
for (auto row : r)
|
||||
for (auto const &row : r)
|
||||
{
|
||||
LOG_DEBUG << "group_id:" << row["group_id"].as<size_t>();
|
||||
}
|
||||
|
|
2
trantor
2
trantor
|
@ -1 +1 @@
|
|||
Subproject commit 4ba9e71d070b6c6498b4f0c9fd8e66bdde97ed97
|
||||
Subproject commit 52753c24ba8b94a6ca1978905c5cdb2675576b07
|
Loading…
Reference in New Issue