Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Dec 13, 2017
1 parent c38c6dc commit a9e0248
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 116 deletions.
6 changes: 0 additions & 6 deletions hpx/performance_counters/registry.hpp
Expand Up @@ -166,12 +166,6 @@ namespace hpx { namespace performance_counters
private:
counter_type_map_type countertypes_;
};

namespace detail
{
HPX_EXPORT std::string regex_from_pattern(std::string const& pattern,
error_code& ec);
}
}}

#endif
Expand Down
20 changes: 20 additions & 0 deletions hpx/util/regex_from_pattern.hpp
@@ -0,0 +1,20 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(HPX_UTIL_REGEX_FROM_PATTERN_DEC_13_2017_1016AM)
#define HPX_UTIL_REGEX_FROM_PATTERN_DEC_13_2017_1016AM

#include <hpx/config.hpp>
#include <hpx/error_code.hpp>

#include <string>

namespace hpx { namespace util
{
HPX_EXPORT std::string regex_from_pattern(std::string const& pattern,
error_code& ec = throws);
}}

#endif
5 changes: 2 additions & 3 deletions plugins/parcel/coalescing/coalescing_counter_registry.cpp
Expand Up @@ -8,6 +8,7 @@
#if defined(HPX_HAVE_PARCEL_COALESCING)
#include <hpx/performance_counters/registry.hpp>
#include <hpx/util/format.hpp>
#include <hpx/util/regex_from_pattern.hpp>

#include <hpx/plugins/parcel/coalescing_counter_registry.hpp>

Expand Down Expand Up @@ -256,9 +257,7 @@ namespace hpx { namespace plugins { namespace parcel

if (parameters.find_first_of("*?[]") != std::string::npos)
{
std::string str_rx(
performance_counters::detail::regex_from_pattern(
parameters, ec));
std::string str_rx(util::regex_from_pattern(parameters, ec));
if (ec) return false;

bool found_one = false;
Expand Down
95 changes: 7 additions & 88 deletions src/performance_counters/registry.cpp
Expand Up @@ -5,20 +5,21 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/config.hpp>
#include <hpx/runtime/agas/interface.hpp>
#include <hpx/runtime/components/server/create_component.hpp>
#include <hpx/performance_counters/counters.hpp>
#include <hpx/performance_counters/registry.hpp>
#include <hpx/performance_counters/server/arithmetics_counter.hpp>
#include <hpx/performance_counters/server/arithmetics_counter_extended.hpp>
#include <hpx/performance_counters/server/elapsed_time_counter.hpp>
#include <hpx/performance_counters/server/raw_counter.hpp>
#include <hpx/performance_counters/server/raw_values_counter.hpp>
#include <hpx/performance_counters/server/elapsed_time_counter.hpp>
#include <hpx/performance_counters/server/statistics_counter.hpp>
#include <hpx/performance_counters/server/arithmetics_counter.hpp>
#include <hpx/performance_counters/server/arithmetics_counter_extended.hpp>
#include <hpx/runtime/agas/interface.hpp>
#include <hpx/runtime/components/server/create_component.hpp>
#include <hpx/util/bind.hpp>
#include <hpx/util/format.hpp>
#include <hpx/util/function.hpp>
#include <hpx/util/logging.hpp>
#include <hpx/util/regex_from_pattern.hpp>
#include <hpx/util/rolling_max.hpp>
#include <hpx/util/rolling_min.hpp>

Expand Down Expand Up @@ -110,88 +111,6 @@ namespace hpx { namespace performance_counters
return status_valid_data;
}

namespace detail
{
///////////////////////////////////////////////////////////////////////
inline std::string
regex_from_character_set(std::string::const_iterator& it,
std::string::const_iterator end, error_code& ec)
{
std::string::const_iterator start = it;
std::string result(1, *it); // copy '['
if (*++it == '!') {
result.append(1, '^'); // negated character set
}
else if (*it == ']') {
HPX_THROWS_IF(ec, bad_parameter, "regex_from_character_set",
"Invalid pattern (empty character set) at: " +
std::string(start, end));
return "";
}
else {
result.append(1, *it); // append this character
}

// copy while in character set
while (++it != end) {
result.append(1, *it);
if (*it == ']')
break;
}

if (it == end || *it != ']') {
HPX_THROWS_IF(ec, bad_parameter, "regex_from_character_set",
"Invalid pattern (missing closing ']') at: " +
std::string(start, end));
return "";
}

return result;
}

std::string regex_from_pattern(std::string const& pattern, error_code& ec)
{
std::string result;
std::string::const_iterator end = pattern.end();
for (std::string::const_iterator it = pattern.begin(); it != end; ++it)
{
char c = *it;
switch (c) {
case '*':
result.append(".*");
break;

case '?':
result.append(1, '.');
break;

case '[':
{
std::string r = regex_from_character_set(it, end, ec);
if (ec) return "";
result.append(r);
}
break;

case '\\':
if (++it == end) {
HPX_THROWS_IF(ec, bad_parameter,
"regex_from_pattern",
"Invalid escape sequence at: " + pattern);
return "";
}
result.append(1, *it);
break;

default:
result.append(1, c);
break;
}
}
return result;
}
}

/// \brief Call the supplied function for the given registered counter type.
counter_status registry::discover_counter_type(
std::string const& fullname,
Expand Down Expand Up @@ -242,7 +161,7 @@ namespace hpx { namespace performance_counters
}
else
{
std::string str_rx(detail::regex_from_pattern(type_name, ec));
std::string str_rx(util::regex_from_pattern(type_name, ec));
if (ec) return status_invalid_data;

if (mode == discover_counters_full)
Expand Down
5 changes: 2 additions & 3 deletions src/runtime/actions/detail/invocation_count_registry.cpp
Expand Up @@ -9,6 +9,7 @@
#include <hpx/performance_counters/counters.hpp>
#include <hpx/performance_counters/registry.hpp>
#include <hpx/util/format.hpp>
#include <hpx/util/regex_from_pattern.hpp>

#include <string>

Expand Down Expand Up @@ -100,9 +101,7 @@ namespace hpx { namespace actions { namespace detail

if (p.parameters_.find_first_of("*?[]") != std::string::npos)
{
std::string str_rx(
performance_counters::detail::regex_from_pattern(
p.parameters_, ec));
std::string str_rx(util::regex_from_pattern(p.parameters_, ec));
if (ec) return false;

bool found_one = false;
Expand Down
23 changes: 10 additions & 13 deletions src/runtime/agas/server/symbol_namespace_server.cpp
Expand Up @@ -23,6 +23,7 @@
#include <hpx/util/format.hpp>
#include <hpx/util/get_and_reset_value.hpp>
#include <hpx/util/insert_checked.hpp>
#include <hpx/util/regex_from_pattern.hpp>
#include <hpx/util/scoped_timer.hpp>
#include <hpx/util/unlock_guard.hpp>

Expand All @@ -38,13 +39,6 @@

#include <boost/regex.hpp>

// Reuse functionaliy from perf-counters
namespace hpx { namespace performance_counters { namespace detail
{
HPX_EXPORT std::string regex_from_pattern(std::string const& pattern,
error_code& ec);
}}}

namespace hpx { namespace agas
{

Expand Down Expand Up @@ -388,8 +382,7 @@ symbol_namespace::iterate_names_return_type symbol_namespace::iterate(

if (pattern.find_first_of("*?[]") != std::string::npos)
{
std::string str_rx(
performance_counters::detail::regex_from_pattern(pattern, throws));
std::string str_rx(util::regex_from_pattern(pattern, throws));
boost::regex rx(str_rx, boost::regex::perl);

std::unique_lock<mutex_type> l(mutex_);
Expand All @@ -398,8 +391,7 @@ symbol_namespace::iterate_names_return_type symbol_namespace::iterate(
{
if (!boost::regex_match(it->first, rx))
continue;
found[it->first] =
naming::detail::split_gid_if_needed(*(it->second)).get();
found[it->first] = *(it->second);
}
}
else
Expand All @@ -410,11 +402,16 @@ symbol_namespace::iterate_names_return_type symbol_namespace::iterate(
{
if (!pattern.empty() && pattern != it->first)
continue;
found[it->first] =
naming::detail::split_gid_if_needed(*(it->second)).get();
found[it->first] = *(it->second);
}
}

// now, split gids, if needed
for (auto& e : found)
{
e.second = naming::detail::split_gid_if_needed(e.second).get();
}

LAGAS_(info) << "symbol_namespace::iterate";

return found;
Expand Down
Expand Up @@ -12,6 +12,7 @@
#include <hpx/performance_counters/registry.hpp>
#include <hpx/util/bind_front.hpp>
#include <hpx/util/format.hpp>
#include <hpx/util/regex_from_pattern.hpp>

#include <cstdint>
#include <string>
Expand Down Expand Up @@ -94,9 +95,7 @@ namespace hpx { namespace parcelset { namespace detail

if (p.parameters_.find_first_of("*?[]") != std::string::npos)
{
std::string str_rx(
performance_counters::detail::regex_from_pattern(
p.parameters_, ec));
std::string str_rx(util::regex_from_pattern(p.parameters_, ec));
if (ec) return false;

bool found_one = false;
Expand Down
98 changes: 98 additions & 0 deletions src/util/regex_from_pattern.cpp
@@ -0,0 +1,98 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/config.hpp>
#include <hpx/error_code.hpp>
#include <hpx/util/regex_from_pattern.hpp>

#include <string>

#include <boost/regex.hpp>

namespace hpx { namespace util
{
namespace detail
{
///////////////////////////////////////////////////////////////////////
inline std::string
regex_from_character_set(std::string::const_iterator& it,
std::string::const_iterator end, error_code& ec)
{
std::string::const_iterator start = it;
std::string result(1, *it); // copy '['
if (*++it == '!') {
result.append(1, '^'); // negated character set
}
else if (*it == ']') {
HPX_THROWS_IF(ec, bad_parameter, "regex_from_character_set",
"Invalid pattern (empty character set) at: " +
std::string(start, end));
return "";
}
else {
result.append(1, *it); // append this character
}

// copy while in character set
while (++it != end) {
result.append(1, *it);
if (*it == ']')
break;
}

if (it == end || *it != ']') {
HPX_THROWS_IF(ec, bad_parameter, "regex_from_character_set",
"Invalid pattern (missing closing ']') at: " +
std::string(start, end));
return "";
}

return result;
}
}

std::string regex_from_pattern(std::string const& pattern, error_code& ec)
{
std::string result;
std::string::const_iterator end = pattern.end();
for (std::string::const_iterator it = pattern.begin(); it != end; ++it)
{
char c = *it;
switch (c) {
case '*':
result.append(".*");
break;

case '?':
result.append(1, '.');
break;

case '[':
{
std::string r =
detail::regex_from_character_set(it, end, ec);
if (ec) return "";
result.append(r);
}
break;

case '\\':
if (++it == end) {
HPX_THROWS_IF(ec, bad_parameter,
"regex_from_pattern",
"Invalid escape sequence at: " + pattern);
return "";
}
result.append(1, *it);
break;

default:
result.append(1, c);
break;
}
}
return result;
}
}}

0 comments on commit a9e0248

Please sign in to comment.