Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb_re2::RE2::Set Class Reference
Collaboration diagram for duckdb_re2::RE2::Set:

Classes

struct  ErrorInfo

Public Types

enum  ErrorKind { kNoError = 0 , kNotCompiled , kOutOfMemory , kInconsistent }

Public Member Functions

 Set (const RE2::Options &options, RE2::Anchor anchor)
 Set (const Set &)=delete
Set & operator= (const Set &)=delete
 Set (Set &&other)
Set & operator= (Set &&other)
int Add (const StringPiece &pattern, std::string *error)
bool Compile ()
bool Match (const StringPiece &text, std::vector< int > *v) const
bool Match (const StringPiece &text, std::vector< int > *v, ErrorInfo *error_info) const

Private Types

typedef std::pair< std::string, duckdb_re2::Regexp * > Elem

Private Attributes

RE2::Options options_
RE2::Anchor anchor_
std::vector< Elem > elem_
bool compiled_
int size_
duckdb_base_std::unique_ptr< duckdb_re2::Prog > prog_

Member Enumeration Documentation

◆ ErrorKind

enum duckdb_re2::RE2::Set::ErrorKind
473990 {
473991 kNoError = 0,
473992 kNotCompiled, // The set is not compiled.
473993 kOutOfMemory, // The DFA ran out of memory.
473994 kInconsistent, // The result is inconsistent. This should never happen.
473995 };

Constructor & Destructor Documentation

◆ Set() [1/2]

duckdb_re2::RE2::Set::Set ( const RE2::Options & options,
RE2::Anchor anchor )
474071 : options_(options),
474072 anchor_(anchor),
474073 compiled_(false),
474074 size_(0) {
474075 options_.set_never_capture(true); // might unblock some optimisations
474076}

◆ ~Set()

duckdb_re2::RE2::Set::~Set ( )
474078 {
474079 for (size_t i = 0; i < elem_.size(); i++)
474080 elem_[i].second->Decref();
474081}

◆ Set() [2/2]

duckdb_re2::RE2::Set::Set ( Set && other)
474084 : options_(other.options_),
474085 anchor_(other.anchor_),
474086 elem_(std::move(other.elem_)),
474087 compiled_(other.compiled_),
474088 size_(other.size_),
474089 prog_(std::move(other.prog_)) {
474090 other.elem_.clear();
474091 other.elem_.shrink_to_fit();
474092 other.compiled_ = false;
474093 other.size_ = 0;
474094 other.prog_.reset();
474095}

Member Function Documentation

◆ operator=()

RE2::Set & duckdb_re2::RE2::Set::operator= ( Set && other)
474097 {
474098 this->~Set();
474099 (void) new (this) Set(std::move(other));
474100 return *this;
474101}

◆ Add()

int duckdb_re2::RE2::Set::Add ( const StringPiece & pattern,
std::string * error )
474103 {
474104 if (compiled_) {
474105 LOG(DFATAL) << "RE2::Set::Add() called after compiling";
474106 return -1;
474107 }
474108
474109 Regexp::ParseFlags pf = static_cast<Regexp::ParseFlags>(
474110 options_.ParseFlags());
474111 RegexpStatus status;
474112 duckdb_re2::Regexp* re = Regexp::Parse(pattern, pf, &status);
474113 if (re == NULL) {
474114 if (error != NULL)
474115 *error = status.Text();
474116 if (options_.log_errors())
474117 LOG(ERROR) << "Error parsing '" << pattern << "': " << status.Text();
474118 return -1;
474119 }
474120
474121 // Concatenate with match index and push on vector.
474122 int n = static_cast<int>(elem_.size());
474123 duckdb_re2::Regexp* m = duckdb_re2::Regexp::HaveMatch(n, pf);
474124 if (re->op() == kRegexpConcat) {
474125 int nsub = re->nsub();
474126 PODArray<duckdb_re2::Regexp*> sub(nsub + 1);
474127 for (int i = 0; i < nsub; i++)
474128 sub[i] = re->sub()[i]->Incref();
474129 sub[nsub] = m;
474130 re->Decref();
474131 re = duckdb_re2::Regexp::Concat(sub.data(), nsub + 1, pf);
474132 } else {
474133 duckdb_re2::Regexp* sub[2];
474134 sub[0] = re;
474135 sub[1] = m;
474136 re = duckdb_re2::Regexp::Concat(sub, 2, pf);
474137 }
474138 elem_.emplace_back(std::string(pattern), re);
474139 return n;
474140}
GMat sub(const GMat &src1, const GMat &src2, int ddepth=-1)

◆ Compile()

bool duckdb_re2::RE2::Set::Compile ( )
474142 {
474143 if (compiled_) {
474144 LOG(DFATAL) << "RE2::Set::Compile() called more than once";
474145 return false;
474146 }
474147 compiled_ = true;
474148 size_ = static_cast<int>(elem_.size());
474149
474150 // Sort the elements by their patterns. This is good enough for now
474151 // until we have a Regexp comparison function. (Maybe someday...)
474152 std::sort(elem_.begin(), elem_.end(),
474153 [](const Elem& a, const Elem& b) -> bool {
474154 return a.first < b.first;
474155 });
474156
474157 PODArray<duckdb_re2::Regexp*> sub(size_);
474158 for (int i = 0; i < size_; i++)
474159 sub[i] = elem_[i].second;
474160 elem_.clear();
474161 elem_.shrink_to_fit();
474162
474163 Regexp::ParseFlags pf = static_cast<Regexp::ParseFlags>(
474164 options_.ParseFlags());
474165 duckdb_re2::Regexp* re = duckdb_re2::Regexp::Alternate(sub.data(), size_, pf);
474166
474167 prog_.reset(Prog::CompileSet(re, anchor_, options_.max_mem()));
474168 re->Decref();
474169 return prog_ != nullptr;
474170}

◆ Match() [1/2]

bool duckdb_re2::RE2::Set::Match ( const StringPiece & text,
std::vector< int > * v ) const
474172 {
474173 return Match(text, v, NULL);
474174}
uint32_t v

◆ Match() [2/2]

bool duckdb_re2::RE2::Set::Match ( const StringPiece & text,
std::vector< int > * v,
ErrorInfo * error_info ) const
474177 {
474178 if (!compiled_) {
474179 if (error_info != NULL)
474180 error_info->kind = kNotCompiled;
474181 LOG(DFATAL) << "RE2::Set::Match() called before compiling";
474182 return false;
474183 }
474184#ifdef RE2_HAVE_THREAD_LOCAL
474185 hooks::context = NULL;
474186#endif
474187 bool dfa_failed = false;
474188 duckdb_base_std::unique_ptr<SparseSet> matches;
474189 if (v != NULL) {
474190 matches.reset(new SparseSet(size_));
474191 v->clear();
474192 }
474193 bool ret = prog_->SearchDFA(text, text, Prog::kAnchored, Prog::kManyMatch,
474194 NULL, &dfa_failed, matches.get());
474195 if (dfa_failed) {
474196 if (options_.log_errors())
474197 LOG(ERROR) << "DFA out of memory: "
474198 << "program size " << prog_->size() << ", "
474199 << "list count " << prog_->list_count() << ", "
474200 << "bytemap range " << prog_->bytemap_range();
474201 if (error_info != NULL)
474202 error_info->kind = kOutOfMemory;
474203 return false;
474204 }
474205 if (ret == false) {
474206 if (error_info != NULL)
474207 error_info->kind = kNoError;
474208 return false;
474209 }
474210 if (v != NULL) {
474211 if (matches->empty()) {
474212 if (error_info != NULL)
474213 error_info->kind = kInconsistent;
474214 LOG(DFATAL) << "RE2::Set::Match() matched, but no matches returned?!";
474215 return false;
474216 }
474217 v->assign(matches->begin(), matches->end());
474218 }
474219 if (error_info != NULL)
474220 error_info->kind = kNoError;
474221 return true;
474222}

The documentation for this class was generated from the following file: