You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by am...@apache.org on 2022/05/06 14:12:21 UTC

[nifi-minifi-cpp] 02/03: MINIFICPP-1818 - Change searcher Closes #1323

This is an automated email from the ASF dual-hosted git repository.

amarkovics pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 92fb6e9ed69d7034788786f1f8948cd9d10ff56d
Author: Adam Debreceni <ad...@apache.org>
AuthorDate: Tue May 3 14:40:55 2022 +0200

    MINIFICPP-1818 - Change searcher
    Closes #1323
    
    Signed-off-by: Adam Markovics <nu...@gmail.com>
---
 .../standard-processors/processors/RouteText.cpp   | 16 +----
 libminifi/include/utils/Searcher.h                 | 73 ++++++++++++++++++++++
 2 files changed, 76 insertions(+), 13 deletions(-)

diff --git a/extensions/standard-processors/processors/RouteText.cpp b/extensions/standard-processors/processors/RouteText.cpp
index c14632ede..5892f650a 100644
--- a/extensions/standard-processors/processors/RouteText.cpp
+++ b/extensions/standard-processors/processors/RouteText.cpp
@@ -23,16 +23,6 @@
 #include <algorithm>
 #include <set>
 
-#if __cpp_lib_boyer_moore_searcher < 201603L
-#include <experimental/functional>
-template<typename It, typename Hash, typename Eq>
-using boyer_moore_searcher = std::experimental::boyer_moore_searcher<It, Hash, Eq>;
-#else
-#include <functional>
-template<typename It, typename Hash, typename Eq>
-using boyer_moore_searcher = std::boyer_moore_searcher<It, Hash, Eq>;
-#endif
-
 #include "core/ProcessSession.h"
 #include "core/Resource.h"
 #include "io/StreamPipe.h"
@@ -44,6 +34,7 @@ using boyer_moore_searcher = std::boyer_moore_searcher<It, Hash, Eq>;
 #include "range/v3/view/cache1.hpp"
 #include "utils/ProcessorConfigUtils.h"
 #include "utils/OptionalUtils.h"
+#include "utils/Searcher.h"
 
 namespace org::apache::nifi::minifi::processors {
 
@@ -219,7 +210,6 @@ class RouteText::MatchingContext {
    private:
     CasePolicy policy_;
   };
-  using Searcher = boyer_moore_searcher<std::string::const_iterator, CaseAwareHash, CaseAwareEq>;
 
  public:
   MatchingContext(core::ProcessContext& process_context, std::shared_ptr<core::FlowFile> flow_file, CasePolicy case_policy)
@@ -255,7 +245,7 @@ class RouteText::MatchingContext {
     return (string_values_[prop.getName()] = value);
   }
 
-  const Searcher& getSearcher(const core::Property& prop) {
+  const auto& getSearcher(const core::Property& prop) {
     auto it = searcher_values_.find(prop.getName());
     if (it != searcher_values_.end()) {
       return it->second.searcher_;
@@ -286,7 +276,7 @@ class RouteText::MatchingContext {
     OwningSearcher& operator=(OwningSearcher&&) = delete;
 
     std::string str_;
-    Searcher searcher_;
+    utils::Searcher<std::string::const_iterator, CaseAwareHash, CaseAwareEq> searcher_;
   };
 
   std::map<std::string, OwningSearcher> searcher_values_;
diff --git a/libminifi/include/utils/Searcher.h b/libminifi/include/utils/Searcher.h
new file mode 100644
index 000000000..91183a0d0
--- /dev/null
+++ b/libminifi/include/utils/Searcher.h
@@ -0,0 +1,73 @@
+/**
+ * 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 regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#pragma once
+
+#include <version>
+#include <utility>
+#include <iterator>
+
+#ifdef _LIBCPP_VERSION
+#include <functional>
+#elif __cpp_lib_boyer_moore_searcher < 201603L
+#include <experimental/functional>
+#else
+#include <functional>
+#endif
+
+namespace org::apache::nifi::minifi::utils {
+
+// platform dependent workaround for boyer_moore_searcher
+template<typename It, typename Hash = std::hash<typename std::iterator_traits<It>::value_type>, typename BinaryPredicate = std::equal_to<>>
+class Searcher {
+ public:
+  template<typename It2>
+  std::pair<It2, It2> operator()(It2 begin, It2 end) const {
+    return impl_(std::move(begin), std::move(end));
+  }
+
+#ifdef _LIBCPP_VERSION
+
+ public:
+  Searcher(It begin, It end, Hash /*hash*/ = {}, BinaryPredicate pred = {})
+      : impl_(std::move(begin), std::move(end), std::move(pred)) {}
+
+ private:
+  // fallback to default_searcher due to libcxx bug
+  std::default_searcher<It, BinaryPredicate> impl_;
+
+#elif __cpp_lib_boyer_moore_searcher < 201603L
+
+ public:
+  Searcher(It begin, It end, Hash hash = {}, BinaryPredicate pred = {})
+      : impl_(std::move(begin), std::move(end), std::move(hash), std::move(pred)) {}
+
+ private:
+  std::experimental::boyer_moore_searcher<It, Hash, BinaryPredicate> impl_;
+
+#else
+
+ public:
+  Searcher(It begin, It end, Hash hash = {}, BinaryPredicate pred = {})
+      : impl_(std::move(begin), std::move(end), std::move(hash), std::move(pred)) {}
+
+ private:
+  std::boyer_moore_searcher<It, Hash, BinaryPredicate> impl_;
+#endif
+};
+
+}  // namespace org::apache::nifi::minifi::utils