This is an automated email from the ASF dual-hosted git repository.
lordgamez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new 556da71 MINIFICPP-1289 add range-v3 and examples
556da71 is described below
commit 556da71fc25fd516fbbe59aa977f308ce787969a
Author: Marton Szasz <[email protected]>
AuthorDate: Thu Jul 29 16:35:42 2021 +0200
MINIFICPP-1289 add range-v3 and examples
Signed-off-by: Gabor Gyimesi <[email protected]>
This closes #1147
---
LICENSE | 171 +++++++++++++++++++++
NOTICE | 31 ++++
.../CMakeLists.txt => cmake/RangeV3.cmake | 23 +--
extensions/standard-processors/CMakeLists.txt | 3 +-
.../standard-processors/processors/TailFile.cpp | 8 +-
libminifi/CMakeLists.txt | 3 +-
libminifi/include/utils/StringUtils.h | 3 +-
libminifi/src/utils/StringUtils.cpp | 13 +-
8 files changed, 231 insertions(+), 24 deletions(-)
diff --git a/LICENSE b/LICENSE
index 6eec454..f7a89a9 100644
--- a/LICENSE
+++ b/LICENSE
@@ -2972,3 +2972,174 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+
+--------------------------------------------------------------------------
+
+This project bundles 'range-v3' which is available under the Boost Software
License.
+It includes code from a number of other projects, all of which have their own
BSD-like
+or MIT licenses.
+
+llvm libc++: University of Illinois BSD-Like or MIT at the choice of the user
+Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
+http://llvm.org/svn/llvm-project/libcxx/trunk/CREDITS.TXT
+
+Stepanov and McJones 2009: MIT License
+Copyright (c) 2009 Alexander Stepanov and Paul McJones
+
+SGI C++ STL: MIT
+Copyright (c) 1994 Hewlett-Packard Company
+Copyright (c) 1996 Silicon Graphics Computer Systems, Inc.
+
+========================================================
+Boost Software License - Version 1.0 - August 17th, 2003
+========================================================
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+==============================================================================
+libc++ License
+==============================================================================
+
+The libc++ library is dual licensed under both the University of Illinois
+"BSD-Like" license and the MIT license. As a user of this code you may choose
+to use it under either license. As a contributor, you agree to allow your code
+to be used under both.
+
+Full text of the relevant licenses is included below.
+
+==============================================================================
+
+University of Illinois/NCSA
+Open Source License
+
+Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
+http://llvm.org/svn/llvm-project/libcxx/trunk/CREDITS.TXT
+
+All rights reserved.
+
+Developed by:
+
+ LLVM Team
+
+ University of Illinois at Urbana-Champaign
+
+ http://llvm.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal with
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimers.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimers in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the names of the LLVM Team, University of Illinois at
+ Urbana-Champaign, nor the names of its contributors may be used to
+ endorse or promote products derived from this Software without specific
+ prior written permission.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+SOFTWARE.
+
+==============================================================================
+
+Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
+ http://llvm.org/svn/llvm-project/libcxx/trunk/CREDITS.TXT
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+==============================================================================
+Stepanov and McJones, "Elements of Programming" license
+==============================================================================
+
+// Copyright (c) 2009 Alexander Stepanov and Paul McJones
+//
+// Permission to use, copy, modify, distribute and sell this software
+// and its documentation for any purpose is hereby granted without
+// fee, provided that the above copyright notice appear in all copies
+// and that both that copyright notice and this permission notice
+// appear in supporting documentation. The authors make no
+// representations about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied
+// warranty.
+//
+// Algorithms from
+// Elements of Programming
+// by Alexander Stepanov and Paul McJones
+// Addison-Wesley Professional, 2009
+
+==============================================================================
+SGI C++ Standard Template Library license
+==============================================================================
+
+// Copyright (c) 1994
+// Hewlett-Packard Company
+//
+// Permission to use, copy, modify, distribute and sell this software
+// and its documentation for any purpose is hereby granted without fee,
+// provided that the above copyright notice appear in all copies and
+// that both that copyright notice and this permission notice appear
+// in supporting documentation. Hewlett-Packard Company makes no
+// representations about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied warranty.
+//
+// Copyright (c) 1996
+// Silicon Graphics Computer Systems, Inc.
+//
+// Permission to use, copy, modify, distribute and sell this software
+// and its documentation for any purpose is hereby granted without fee,
+// provided that the above copyright notice appear in all copies and
+// that both that copyright notice and this permission notice appear
+// in supporting documentation. Silicon Graphics makes no
+// representations about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied warranty.
+//
+
+--------------------------------------------------------------------------
diff --git a/NOTICE b/NOTICE
index 33322ac..0a875f6 100644
--- a/NOTICE
+++ b/NOTICE
@@ -58,6 +58,7 @@ This software includes third party software subject to the
following copyrights:
- IANA timezone database - public domain
- date (HowardHinnant/date) - notices below
- JSON for Modern C++ (nlohmann/json) - Copyright (c) 2013-2021 Niels Lohmann
+- range-v3 - Eric Niebler and other contributors
The licenses for these third party components are included in LICENSE.txt
@@ -73,3 +74,33 @@ Copyright notices of the date project:
// Copyright (c) 2017 Paul Thompson
// Copyright (c) 2017, 2018, 2019 Tomasz KamiĆski
// Copyright (c) 2019 Asad. Gharighi
+
+range-v3:
+(C) Copyright Kevlin Henney and Dave Abrahams 1999.
+Copyright 2005 - 2007 Adobe Systems Incorporated
+Copyright 2019-present Christopher Di Bella
+Copyright Andrew Sutton 2014
+Copyright Andrey Diduh 2019
+Copyright Barry Revzin 2019-present
+Copyright (c) 1994 Hewlett-Packard Company
+Copyright (c) 1996 Silicon Graphics Computer Systems, Inc.
+Copyright (c) 2009 Alexander Stepanov and Paul McJones
+Copyright (c) 2013 GitHub, Inc.
+Copyright (c) 2015 Microsoft Corporation. All rights reserved.
+Copyright (c) 2018-present, Facebook, Inc.
+Copyright (c) 2020-present, Google LLC.
+Copyright Casey Carter 2015-present
+Copyright Eric Niebler 2004,2013-present
+Copyright Filip Matner 2015,2017
+Copyright Gonzalo Brito Gadeschi 2014-2017
+Copyright Google LLC 2020-present
+Copyright Jeff Garland 2017
+Copyright Johel Guerrero 2019
+Copyright Louis Dionne 2013-2017
+Copyright Luis Martinez de Bartolome Izquierdo 2016
+Copyright Michel Morin 2014
+Copyright MikeGitb 2018-present
+Copyright Mitsutaka Takeda 2018-present
+Copyright Rostislav Khlebnikov 2017
+Copyright Tobias Mayer 2016
+Copyright Tomislav Ivek 2015-2016
diff --git a/extensions/standard-processors/CMakeLists.txt b/cmake/RangeV3.cmake
similarity index 60%
copy from extensions/standard-processors/CMakeLists.txt
copy to cmake/RangeV3.cmake
index f4ca71d..800ebcc 100644
--- a/extensions/standard-processors/CMakeLists.txt
+++ b/cmake/RangeV3.cmake
@@ -1,4 +1,3 @@
-#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -15,20 +14,14 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-#
-
-
-include(${CMAKE_SOURCE_DIR}/extensions/ExtensionHeader.txt)
-
-file(GLOB SOURCES "processors/*.cpp" "controllers/*.cpp" )
-
-add_library(minifi-standard-processors STATIC ${SOURCES})
-set_property(TARGET minifi-standard-processors PROPERTY
POSITION_INDEPENDENT_CODE ON)
-
-target_link_libraries(minifi-standard-processors ${LIBMINIFI} Threads::Threads)
-SET (STANDARD-PROCESSORS minifi-standard-processors PARENT_SCOPE)
-register_extension(minifi-standard-processors)
+include(FetchContent)
+FetchContent_Declare(range-v3_src
+ GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
+ GIT_TAG 0487cca29e352e8f16bbd91fda38e76e39a0ed28
+)
+FetchContent_MakeAvailable(range-v3_src)
-register_extension_linter(minifi-standard-processors-linter)
+# for better error messages
+target_compile_options(range-v3 INTERFACE
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-fconcepts>)
diff --git a/extensions/standard-processors/CMakeLists.txt
b/extensions/standard-processors/CMakeLists.txt
index f4ca71d..df3e8e8 100644
--- a/extensions/standard-processors/CMakeLists.txt
+++ b/extensions/standard-processors/CMakeLists.txt
@@ -25,7 +25,8 @@ file(GLOB SOURCES "processors/*.cpp" "controllers/*.cpp" )
add_library(minifi-standard-processors STATIC ${SOURCES})
set_property(TARGET minifi-standard-processors PROPERTY
POSITION_INDEPENDENT_CODE ON)
-target_link_libraries(minifi-standard-processors ${LIBMINIFI} Threads::Threads)
+include(RangeV3)
+target_link_libraries(minifi-standard-processors ${LIBMINIFI} Threads::Threads
range-v3)
SET (STANDARD-PROCESSORS minifi-standard-processors PARENT_SCOPE)
register_extension(minifi-standard-processors)
diff --git a/extensions/standard-processors/processors/TailFile.cpp
b/extensions/standard-processors/processors/TailFile.cpp
index 6d4bf78..79e05bf 100644
--- a/extensions/standard-processors/processors/TailFile.cpp
+++ b/extensions/standard-processors/processors/TailFile.cpp
@@ -31,6 +31,9 @@
#include <utility>
#include <vector>
+#include "range/v3/action/sort.hpp"
+#include "range/v3/algorithm/transform.hpp"
+
#include "io/CRCStream.h"
#include "utils/file/FileUtils.h"
#include "utils/file/PathUtils.h"
@@ -639,10 +642,11 @@ std::vector<TailState>
TailFile::findRotatedFilesAfterLastReadTime(const TailSta
}
std::vector<TailState> TailFile::sortAndSkipMainFilePrefix(const TailState
&state, std::vector<TailStateWithMtime>& matched_files_with_mtime) const {
- std::sort(matched_files_with_mtime.begin(), matched_files_with_mtime.end(),
[](const TailStateWithMtime &left, const TailStateWithMtime &right) {
+ const auto first_by_mtime_then_by_name = [](const auto& left, const auto&
right) {
return std::tie(left.mtime_, left.tail_state_.file_name_) <
std::tie(right.mtime_, right.tail_state_.file_name_);
- });
+ };
+ matched_files_with_mtime |=
ranges::actions::sort(first_by_mtime_then_by_name);
if (!matched_files_with_mtime.empty() && state.position_ > 0) {
TailState &first_rotated_file = matched_files_with_mtime[0].tail_state_;
diff --git a/libminifi/CMakeLists.txt b/libminifi/CMakeLists.txt
index dc061bd..5432a8e 100644
--- a/libminifi/CMakeLists.txt
+++ b/libminifi/CMakeLists.txt
@@ -90,7 +90,8 @@ if(NOT EXCLUDE_BOOST)
endif()
endif()
-list(APPEND LIBMINIFI_LIBRARIES yaml-cpp ZLIB::ZLIB concurrentqueue RapidJSON
spdlog cron Threads::Threads gsl-lite libsodium)
+include(RangeV3)
+list(APPEND LIBMINIFI_LIBRARIES yaml-cpp ZLIB::ZLIB concurrentqueue RapidJSON
spdlog cron Threads::Threads gsl-lite libsodium range-v3)
if(NOT WIN32)
list(APPEND LIBMINIFI_LIBRARIES OSSP::libuuid++)
endif()
diff --git a/libminifi/include/utils/StringUtils.h
b/libminifi/include/utils/StringUtils.h
index b33006e..b6148c6 100644
--- a/libminifi/include/utils/StringUtils.h
+++ b/libminifi/include/utils/StringUtils.h
@@ -25,6 +25,7 @@
#include <optional>
#include <sstream>
#include <string>
+#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
@@ -72,7 +73,7 @@ class StringUtils {
*/
static std::optional<bool> toBool(const std::string& input);
- static std::string toLower(std::string str);
+ static std::string toLower(std::string_view str);
// Trim String utils
diff --git a/libminifi/src/utils/StringUtils.cpp
b/libminifi/src/utils/StringUtils.cpp
index 8909ec5..3d5e4d6 100644
--- a/libminifi/src/utils/StringUtils.cpp
+++ b/libminifi/src/utils/StringUtils.cpp
@@ -17,9 +17,12 @@
#include <limits>
+#include "range/v3/view/transform.hpp"
+#include "range/v3/range/conversion.hpp"
+
+#include "utils/Environment.h"
#include "utils/GeneralUtils.h"
#include "utils/StringUtils.h"
-#include "utils/Environment.h"
namespace org {
namespace apache {
@@ -27,6 +30,8 @@ namespace nifi {
namespace minifi {
namespace utils {
+namespace views = ranges::views;
+
std::optional<bool> StringUtils::toBool(const std::string& str) {
std::string trimmed = trim(str);
if (equalsIgnoreCase(trimmed, "true")) {
@@ -38,9 +43,9 @@ std::optional<bool> StringUtils::toBool(const std::string&
str) {
return std::nullopt;
}
-std::string StringUtils::toLower(std::string str) {
- std::transform(str.begin(), str.end(), str.begin(), [] (unsigned char c)
{return std::tolower(c);});
- return str;
+std::string StringUtils::toLower(std::string_view str) {
+ const auto tolower = [](auto c) { return std::tolower(static_cast<unsigned
char>(c)); };
+ return str | views::transform(tolower) | ranges::to<std::string>();
}
std::string StringUtils::trim(const std::string& s) {