OmniSciDB  c07336695a
RegexSupport.h File Reference
#include "boost/regex.hpp"
+ Include dependency graph for RegexSupport.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename COMMAND_LIST_TYPE , typename CONTEXT_TYPE , typename REGEX_PRESENT_LAMBDA >
bool on_valid_regex_present (COMMAND_LIST_TYPE const &command_list, CONTEXT_TYPE &client_context, REGEX_PRESENT_LAMBDA on_present_op, std::ostream &output_stream=std::cout)
 
std::function< bool(std::string const &)> yield_default_filter_function (boost::regex &filter_expression)
 
template<ThriftService SERVICE_TYPE, typename CLIENT_CONTEXT_TYPE , typename DETAIL_PROCESSOR >
void for_all_return_names (CLIENT_CONTEXT_TYPE &context, DETAIL_PROCESSOR detail_processor)
 
template<ThriftService THRIFT_SERVICE, typename COMMAND_LIST_TYPE , typename CONTEXT_TYPE >
void returned_list_regex (COMMAND_LIST_TYPE const &command_list, CONTEXT_TYPE &context, std::ostream &output_stream=std::cout)
 

Function Documentation

◆ for_all_return_names()

template<ThriftService SERVICE_TYPE, typename CLIENT_CONTEXT_TYPE , typename DETAIL_PROCESSOR >
void for_all_return_names ( CLIENT_CONTEXT_TYPE &  context,
DETAIL_PROCESSOR  detail_processor 
)

Definition at line 42 of file RegexSupport.h.

43  {
44  thrift_op<SERVICE_TYPE>(context, [&](CLIENT_CONTEXT_TYPE& lambda_context) {
45  for (auto name_val : lambda_context.names_return) {
46  detail_processor(name_val, lambda_context);
47  }
48  });
49 }

◆ on_valid_regex_present()

template<typename COMMAND_LIST_TYPE , typename CONTEXT_TYPE , typename REGEX_PRESENT_LAMBDA >
bool on_valid_regex_present ( COMMAND_LIST_TYPE const &  command_list,
CONTEXT_TYPE &  client_context,
REGEX_PRESENT_LAMBDA  on_present_op,
std::ostream &  output_stream = std::cout 
)

Definition at line 9 of file RegexSupport.h.

Referenced by returned_list_regex().

12  {
13  try {
14  if (command_list.size() > 1) {
15  boost::regex filter_expression(command_list[1], boost::regex_constants::no_except);
16  if (filter_expression.status() == 0) { // On successful regex
17  on_present_op(filter_expression, client_context);
18  return true;
19  } else {
20  output_stream << "Malformed regular expression: " << command_list[1] << std::endl;
21  }
22  }
23  } catch (std::runtime_error& re) { // Handles cases outlined in boost regex bad
24  // expressions test case, to avoid blow ups
25  output_stream << "Invalid regular expression: " << command_list[1] << std::endl;
26  }
27 
28  return false;
29 }
+ Here is the caller graph for this function:

◆ returned_list_regex()

template<ThriftService THRIFT_SERVICE, typename COMMAND_LIST_TYPE , typename CONTEXT_TYPE >
void returned_list_regex ( COMMAND_LIST_TYPE const &  command_list,
CONTEXT_TYPE &  context,
std::ostream &  output_stream = std::cout 
)

Definition at line 52 of file RegexSupport.h.

References on_valid_regex_present(), and yield_default_filter_function().

54  {
55  // clang-format off
56  auto did_execute = on_valid_regex_present(command_list, context, [&output_stream](boost::regex& filter_expression, CONTEXT_TYPE& context_param) {
57  auto filter_function = yield_default_filter_function(filter_expression);
58  auto result_processor = [filter_function, &output_stream](std::string const& element_name, CONTEXT_TYPE& context_param) {
59  if (!filter_function(element_name)) {
60  output_stream << element_name << '\n';
61  }
62  };
63 
64  for_all_return_names<THRIFT_SERVICE>(context_param, result_processor);
65  });
66  // clang-format on
67 
68  if (!did_execute) { // Run classic mode instead
69  for_all_return_names<THRIFT_SERVICE>(
70  context,
71  [&output_stream](std::string const& element_name, CONTEXT_TYPE& context_param) {
72  output_stream << element_name << '\n';
73  });
74  }
75 
76  output_stream.flush();
77 }
bool on_valid_regex_present(COMMAND_LIST_TYPE const &command_list, CONTEXT_TYPE &client_context, REGEX_PRESENT_LAMBDA on_present_op, std::ostream &output_stream=std::cout)
Definition: RegexSupport.h:9
std::function< bool(std::string const &)> yield_default_filter_function(boost::regex &filter_expression)
Definition: RegexSupport.h:31
+ Here is the call graph for this function:

◆ yield_default_filter_function()

std::function<bool(std::string const&)> yield_default_filter_function ( boost::regex &  filter_expression)

Definition at line 31 of file RegexSupport.h.

Referenced by returned_list_regex().

32  {
33  return [&filter_expression](std::string const& input) -> bool {
34  boost::smatch results;
35  return !boost::regex_match(input, results, filter_expression);
36  };
37 }
+ Here is the caller graph for this function: