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  WordFilter() NLIB_NOEXCEPT : prv_(NULL) {}
36  NLIB_MOVE_MEMBER_HELPER_1(WordFilter, prv_);
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, NULL);
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, NULL);
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:
65  WordFilterBuilder() NLIB_NOEXCEPT : prv_(NULL) {}
67  NLIB_MOVE_MEMBER_HELPER_1(WordFilterBuilder, prv_);
68  bool Init() NLIB_NOEXCEPT;
69  WordFilter* Build() NLIB_NOEXCEPT;
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 {
73  return AddWords(str, nlib_strlen(str));
74  }
75  bool AddExcludeWord(const char* str) NLIB_NOEXCEPT;
76  bool AddExcludeWords(const char* str, size_t len) NLIB_NOEXCEPT;
77  bool AddExcludeWords(const char* str) NLIB_NOEXCEPT {
78  return AddExcludeWords(str, nlib_strlen(str));
79  }
80  void swap(WordFilterBuilder& rhs) NLIB_NOEXCEPT {
81  using std::swap;
82  swap(prv_, rhs.prv_);
83  }
84 
85  private:
86  struct WordFilterBuilderPrivate;
87  WordFilterBuilderPrivate* prv_;
89 };
90 
91 } // namespace succinct
92 NLIB_NAMESPACE_END
93 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::WordFilter)
94 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::WordFilterBuilder)
95 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
96 #undef NLIB_VIS_PUBLIC
97 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
98 #endif
99 
100 #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:163
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_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
Defines the class for searching text strings using the Aho-Corasick string-matching algorithm...
WordFilter() noexcept
Instantiates the object.
Definition: WordFilter.h:34
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
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:77
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:72
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
The class for reading binary from streams (from InputStream).
Definition: BinaryReader.h:26
WordFilterBuilder() noexcept
Instantiates the object.
Definition: WordFilter.h:65