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);
38  using std::swap;
39  swap(prv_, rhs.prv_);
40  }
41  bool Init() NLIB_NOEXCEPT;
42  void Match(const char* doc, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT {
43  this->Match(doc, nlib_strlen(doc), callback, user_obj);
44  }
45  void Match(const char* doc, MatchCallback callback) NLIB_NOEXCEPT {
46  this->Match(doc, callback, nullptr);
47  }
48  void Match(const char* data, size_t n, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT;
49  void Match(const char* data, size_t n, MatchCallback callback) NLIB_NOEXCEPT {
50  this->Match(data, n, callback, nullptr);
51  }
52  void Reset() NLIB_NOEXCEPT;
53  bool Export(BinaryWriter* w) const NLIB_NOEXCEPT;
54  bool Import(BinaryReader* r) NLIB_NOEXCEPT;
55 
56  private:
57  class WordFilterPrivate;
58  WordFilterPrivate* prv_;
59  friend class WordFilterBuilder;
61 };
62 
64  public:
67  NLIB_DEFMOVE_PIMPL(WordFilterBuilder);
69  using std::swap;
70  swap(prv_, rhs.prv_);
71  }
72  void Reset() NLIB_NOEXCEPT;
73  bool Init() NLIB_NOEXCEPT;
74  WordFilter* Build() NLIB_NOEXCEPT;
75  bool AddWord(const char* str) NLIB_NOEXCEPT;
76  bool AddWords(const char* str, size_t len) NLIB_NOEXCEPT;
77  bool AddWords(const char* str) NLIB_NOEXCEPT {
78  return AddWords(str, nlib_strlen(str));
79  }
80  bool AddExcludeWord(const char* str) NLIB_NOEXCEPT;
81  bool AddExcludeWords(const char* str, size_t len) NLIB_NOEXCEPT;
82  bool AddExcludeWords(const char* str) NLIB_NOEXCEPT {
83  return AddExcludeWords(str, nlib_strlen(str));
84  }
85 
86  private:
87  struct WordFilterBuilderPrivate;
88  WordFilterBuilderPrivate* prv_;
90 };
91 
92 } // namespace succinct
93 NLIB_NAMESPACE_END
94 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::WordFilter)
95 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::WordFilterBuilder)
96 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
97 #undef NLIB_VIS_PUBLIC
98 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
99 #endif
100 
101 #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:179
void swap(WordFilter &rhs) noexcept
Swaps the contents of an object.
Definition: WordFilter.h:37
void Match(const char *doc, MatchCallback callback, void *user_obj) noexcept
Inspects the string to detect the registered string.
Definition: WordFilter.h:42
#define NLIB_DEPRECATED
Indicates that a function or something has been deprecated.
Definition: Config.h:109
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
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.
Definition: WordFilter.h:34
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:105
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:82
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:107
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:63
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:77
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:245
The class for reading binary from streams (from InputStream).
Definition: BinaryReader.h:26
constexpr WordFilterBuilder() noexcept
Instantiates the object.
Definition: WordFilter.h:65
~WordFilterBuilder() noexcept
Destructor.
Definition: WordFilter.h:66