nlib
WordFilter.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_SUCCINCT_WORDFILTER_H_
17 #define INCLUDE_NN_NLIB_SUCCINCT_WORDFILTER_H_
18 
19 #include "nn/nlib/Swap.h"
21 
22 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
23 #undef NLIB_VIS_PUBLIC
24 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
25 #endif
26 
27 NLIB_NAMESPACE_BEGIN
28 namespace succinct {
29 
31  public:
32  typedef bool (*MatchCallback)(const char* first, const char* last, uint32_t nodeid,
33  void* user_obj);
34  NLIB_CEXPR WordFilter() NLIB_NOEXCEPT : prv_(nullptr) {}
35  ~WordFilter() NLIB_NOEXCEPT { Reset(); }
36  NLIB_DEFMOVE_PIMPL(WordFilter);
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, nullptr);
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, nullptr);
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:
63  NLIB_DEFMOVE_PIMPL(WordFilterBuilder);
64  void Reset() NLIB_NOEXCEPT;
65  bool Init() NLIB_NOEXCEPT;
66  WordFilter* Build() NLIB_NOEXCEPT;
67 #ifdef __cpp_rvalue_references
68  std::unique_ptr<WordFilter> Build2() NLIB_NOEXCEPT { return decltype(Build2())(Build()); }
69 #endif
70  bool AddWord(const char* str) NLIB_NOEXCEPT;
71  bool AddWords(const char* str, size_t len) NLIB_NOEXCEPT;
72  bool AddWords(const char* str) NLIB_NOEXCEPT { return AddWords(str, nlib_strlen(str)); }
73  bool AddExcludeWord(const char* str) NLIB_NOEXCEPT;
74  bool AddExcludeWords(const char* str, size_t len) NLIB_NOEXCEPT;
75  bool AddExcludeWords(const char* str) NLIB_NOEXCEPT {
76  return AddExcludeWords(str, nlib_strlen(str));
77  }
78 
79  private:
80  struct WordFilterBuilderPrivate;
81  WordFilterBuilderPrivate* prv_;
83 };
84 
85 } // namespace succinct
86 NLIB_NAMESPACE_END
87 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::WordFilter)
88 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::WordFilterBuilder)
89 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
90 #undef NLIB_VIS_PUBLIC
91 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
92 #endif
93 
94 #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:183
std::unique_ptr< WordFilter > Build2() noexcept
Creates a WordFilter object.
Definition: WordFilter.h:68
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
Class that checks whether text contains the predefined set of words.
Definition: WordFilter.h:30
~WordFilter() noexcept
Destructor.
Definition: WordFilter.h:35
Defines the class for searching text strings using the Aho-Corasick string-matching algorithm...
constexpr WordFilter() noexcept
Instantiates the object with default parameters (default constructor). Requires initialization with I...
Definition: WordFilter.h:34
void Match(const char *data, size_t n, MatchCallback callback) noexcept
A parameter omitted version of the above function which passes nullptr as a parameter.
Definition: WordFilter.h:45
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:109
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:75
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:111
void Match(const char *doc, MatchCallback callback) noexcept
A parameter omitted version of the above function which passes nullptr as a parameter.
Definition: WordFilter.h:41
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:26
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:72
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:250
The class for reading binary from streams (from InputStream).
Definition: BinaryReader.h:26
constexpr WordFilterBuilder() noexcept
Instantiates the object with default parameters (default constructor). Requires initialization with I...
Definition: WordFilter.h:61
~WordFilterBuilder() noexcept
Destructor.
Definition: WordFilter.h:62