From a7c8a37938a6dfcbcef12ea6575dedef096b27ee Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 25 Nov 2015 11:05:31 +0100 Subject: [PATCH] use range-based for loop --- arangod/Actions/actions.cpp | 13 +-- .../ApplicationServer/ApplicationServer.cpp | 5 +- .../HttpServer/ApplicationEndpointServer.cpp | 5 +- lib/Basics/delete_object.h | 89 ------------------- 4 files changed, 14 insertions(+), 98 deletions(-) delete mode 100644 lib/Basics/delete_object.h diff --git a/arangod/Actions/actions.cpp b/arangod/Actions/actions.cpp index 356270b1c0..cc3d1294b0 100644 --- a/arangod/Actions/actions.cpp +++ b/arangod/Actions/actions.cpp @@ -33,7 +33,6 @@ #include "Basics/ReadWriteLock.h" #include "Basics/StringUtils.h" #include "Basics/WriteLocker.h" -#include "Basics/delete_object.h" #include "Basics/logging.h" #include "Rest/HttpRequest.h" @@ -48,13 +47,13 @@ using namespace triagens::basics; /// @brief actions //////////////////////////////////////////////////////////////////////////////// -static map Actions; +static std::map Actions; //////////////////////////////////////////////////////////////////////////////// /// @brief prefix actions //////////////////////////////////////////////////////////////////////////////// -static map PrefixActions; +static std::map PrefixActions; //////////////////////////////////////////////////////////////////////////////// /// @brief actions lock @@ -180,10 +179,14 @@ TRI_action_t* TRI_LookupActionVocBase (triagens::rest::HttpRequest* request) { //////////////////////////////////////////////////////////////////////////////// void TRI_CleanupActions () { - for_each(Actions.begin(), Actions.end(), DeleteObjectValue()); + for (auto& it: Actions) { + delete it.second; + } Actions.clear(); - for_each(PrefixActions.begin(), PrefixActions.end(), DeleteObjectValue()); + for (auto& it: PrefixActions) { + delete it.second; + } PrefixActions.clear(); } diff --git a/arangod/ApplicationServer/ApplicationServer.cpp b/arangod/ApplicationServer/ApplicationServer.cpp index 9739ea87b9..efa46c4a78 100644 --- a/arangod/ApplicationServer/ApplicationServer.cpp +++ b/arangod/ApplicationServer/ApplicationServer.cpp @@ -44,7 +44,6 @@ #include "Basics/FileUtils.h" #include "Basics/RandomGenerator.h" #include "Basics/StringUtils.h" -#include "Basics/delete_object.h" #include "Basics/conversions.h" #include "Basics/logging.h" #include "Basics/files.h" @@ -129,7 +128,9 @@ ApplicationServer::ApplicationServer (std::string const& name, std::string const ApplicationServer::~ApplicationServer () { Random::shutdown(); - for_each(_features.begin(), _features.end(), DeleteObjectAny()); + for (auto& it : _features) { + delete it; + } } // ----------------------------------------------------------------------------- diff --git a/arangod/HttpServer/ApplicationEndpointServer.cpp b/arangod/HttpServer/ApplicationEndpointServer.cpp index 688a4954e6..865c6b59c5 100644 --- a/arangod/HttpServer/ApplicationEndpointServer.cpp +++ b/arangod/HttpServer/ApplicationEndpointServer.cpp @@ -35,7 +35,6 @@ #include "Basics/RandomGenerator.h" #include "Basics/ReadLocker.h" #include "Basics/WriteLocker.h" -#include "Basics/delete_object.h" #include "Basics/json.h" #include "Basics/logging.h" #include "Basics/ssl-helper.h" @@ -134,7 +133,9 @@ ApplicationEndpointServer::~ApplicationEndpointServer () { // overloaded class operator is a little unwieldy. // .......................................................................... - for_each(_servers.begin(), _servers.end(), triagens::basics::DeleteObjectAny()); + for (auto& it : _servers) { + delete it; + } _servers.clear(); if (_handlerFactory != nullptr) { diff --git a/lib/Basics/delete_object.h b/lib/Basics/delete_object.h deleted file mode 100644 index a69074efec..0000000000 --- a/lib/Basics/delete_object.h +++ /dev/null @@ -1,89 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// @brief delete object helper -/// -/// @file -/// -/// DISCLAIMER -/// -/// Copyright 2014 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Dr. Frank Celler -/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany -/// @author Copyright 2006-2013, triAGENS GmbH, Cologne, Germany -//////////////////////////////////////////////////////////////////////////////// - -#ifndef ARANGODB_BASICS_DELETE__OBJECT_H -#define ARANGODB_BASICS_DELETE__OBJECT_H 1 - -#include "Basics/Common.h" - -namespace triagens { - namespace basics { - -// ----------------------------------------------------------------------------- -// --SECTION-- public types -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @brief delete object helper -//////////////////////////////////////////////////////////////////////////////// - - struct DeleteObjectAny { - template void operator () (const T* ptr) const { - if (ptr != 0) { - delete ptr; - } - } - }; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief delete object helper for maps -//////////////////////////////////////////////////////////////////////////////// - - struct DeleteObjectKey { - template void operator () (std::pair& ptr) const { - if (ptr.first != 0) { - delete ptr.first; - } - } - }; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief delete object helper for maps -//////////////////////////////////////////////////////////////////////////////// - - struct DeleteObjectValue { - template void operator () (std::pair& ptr) const { - if (ptr.second != 0) { - delete ptr.second; - } - } - }; - } -} - -#endif - -// ----------------------------------------------------------------------------- -// --SECTION-- END-OF-FILE -// ----------------------------------------------------------------------------- - -// Local Variables: -// mode: outline-minor -// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}" -// End: