nlib
WordFilter.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_SUCCINCT_WORDFILTER_H_
4 #define INCLUDE_NN_NLIB_SUCCINCT_WORDFILTER_H_
5 
7 
8 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
9 #undef NLIB_VIS_PUBLIC
10 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
11 #endif
12 
13 NLIB_NAMESPACE_BEGIN
14 namespace succinct {
15 
17  public:
18  typedef bool (*MatchCallback)(const char* first, const char* last, uint32_t nodeid,
19  void* user_obj);
20  WordFilter() NLIB_NOEXCEPT : prv_(NULL) {}
24  WordFilter().swap(*this);
25  this->swap(rhs);
26  return *this;
27  }
28 #ifdef NLIB_CXX11_RVALUE_REFERENCES
29  NLIB_MOVE_MEMBER_HELPER_X_COMMON(WordFilter)
30  WordFilter(WordFilter&& rhs) NLIB_NOEXCEPT; // NOLINT
31 #endif
33  WordFilterPrivate* tmp = rhs.prv_;
34  rhs.prv_ = prv_;
35  this->prv_ = tmp;
36  }
37  bool Init() NLIB_NOEXCEPT;
38  void Match(const char* doc, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT {
39  this->Match(doc, nlib_strlen(doc), callback, user_obj);
40  }
41  void Match(const char* doc, MatchCallback callback) NLIB_NOEXCEPT {
42  this->Match(doc, callback, NULL);
43  }
44  void Match(const char* data, size_t n, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT;
45  void Match(const char* data, size_t n, MatchCallback callback) NLIB_NOEXCEPT {
46  this->Match(data, n, callback, NULL);
47  }
48  void Reset() NLIB_NOEXCEPT;
49  bool Export(BinaryWriter* w) const NLIB_NOEXCEPT;
50  bool Import(BinaryReader* r) NLIB_NOEXCEPT;
51 
52  private:
53  class WordFilterPrivate;
54  WordFilterPrivate* prv_;
55  friend class WordFilterBuilder;
57 };
58 
60  public:
61  WordFilterBuilder() NLIB_NOEXCEPT : prv_(NULL) {}
63  bool Init() NLIB_NOEXCEPT;
64  WordFilter* Build() NLIB_NOEXCEPT;
65  bool AddWord(const char* str) NLIB_NOEXCEPT;
66  bool AddWords(const char* str, size_t len) NLIB_NOEXCEPT;
67  bool AddWords(const char* str) NLIB_NOEXCEPT {
68  return AddWords(str, nlib_strlen(str));
69  }
70  bool AddExcludeWord(const char* str) NLIB_NOEXCEPT;
71  bool AddExcludeWords(const char* str, size_t len) NLIB_NOEXCEPT;
72  bool AddExcludeWords(const char* str) NLIB_NOEXCEPT {
73  return AddExcludeWords(str, nlib_strlen(str));
74  }
75 
76  private:
77  struct WordFilterBuilderPrivate;
78  WordFilterBuilderPrivate* prv_;
80 };
81 
82 } // namespace succinct
83 NLIB_NAMESPACE_END
84 
85 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
86 #undef NLIB_VIS_PUBLIC
87 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
88 #endif
89 
90 #endif // INCLUDE_NN_NLIB_SUCCINCT_WORDFILTER_H_
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:145
void swap(WordFilter &rhs) noexcept
Swaps the contents of an object.
Definition: WordFilter.h:32
void Match(const char *doc, MatchCallback callback, void *user_obj) noexcept
Inspects the string to detect the registered string.
Definition: WordFilter.h:38
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:61
Class that checks whether text contains the predefined set of words.
Definition: WordFilter.h:16
An empty structure indicating that an argument to a function needs to be moved.
Definition: Config.h:231
Defines the class for searching text strings using the Aho-Corasick string-matching algorithm...
WordFilter() noexcept
Instantiates the object.
Definition: WordFilter.h:20
WordFilter & assign(WordFilter &rhs, move_tag) noexcept
Assigns the object by using swap for a move.
Definition: WordFilter.h:23
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:86
bool AddExcludeWords(const char *str) noexcept
Adds a string from an array containing a set of excluded terms. The strings must be delimited by newl...
Definition: WordFilter.h:72
size_t nlib_strlen(const char *s)
Internally calls strlen(). In some cases, it may operate as an independent implementation.
Class to create a WordFilter object that corresponds to a term and excluded terms.
Definition: WordFilter.h:59
The class for writing binary to streams (to OutputStream).
Definition: BinaryWriter.h:13
bool AddWords(const char *str) noexcept
Adds a string from an array containing a set of target strings. The strings must be delimited by newl...
Definition: WordFilter.h:67
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:211
The class for reading binary from streams (from InputStream).
Definition: BinaryReader.h:13
WordFilterBuilder() noexcept
Instantiates the object.
Definition: WordFilter.h:61