nlib
WordFilter.h
Go to the documentation of this file.
1 
2 /*---------------------------------------------------------------------------*
3 
4  Project: CrossRoad
5  Copyright (C)2012-2016 Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12 
13  *---------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_SUCCINCT_WORDFILTER_H_
17 #define INCLUDE_NN_NLIB_SUCCINCT_WORDFILTER_H_
18 
20 
21 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
22 #undef NLIB_VIS_PUBLIC
23 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
24 #endif
25 
26 NLIB_NAMESPACE_BEGIN
27 namespace succinct {
28 
30  public:
31  typedef bool (*MatchCallback)(const char* first, const char* last, uint32_t nodeid,
32  void* user_obj);
33  WordFilter() NLIB_NOEXCEPT : prv_(NULL) {}
37  WordFilter().swap(*this);
38  this->swap(rhs);
39  return *this;
40  }
41 #ifdef NLIB_CXX11_RVALUE_REFERENCES
42  NLIB_MOVE_MEMBER_HELPER_X_COMMON(WordFilter)
43  WordFilter(WordFilter&& rhs) NLIB_NOEXCEPT; // NOLINT
44 #endif
46  WordFilterPrivate* tmp = rhs.prv_;
47  rhs.prv_ = prv_;
48  this->prv_ = tmp;
49  }
50  bool Init() NLIB_NOEXCEPT;
51  void Match(const char* doc, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT {
52  this->Match(doc, nlib_strlen(doc), callback, user_obj);
53  }
54  void Match(const char* doc, MatchCallback callback) NLIB_NOEXCEPT {
55  this->Match(doc, callback, NULL);
56  }
57  void Match(const char* data, size_t n, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT;
58  void Match(const char* data, size_t n, MatchCallback callback) NLIB_NOEXCEPT {
59  this->Match(data, n, callback, NULL);
60  }
61  void Reset() NLIB_NOEXCEPT;
62  bool Export(BinaryWriter* w) const NLIB_NOEXCEPT;
63  bool Import(BinaryReader* r) NLIB_NOEXCEPT;
64 
65  private:
66  class WordFilterPrivate;
67  WordFilterPrivate* prv_;
68  friend class WordFilterBuilder;
70 };
71 
73  public:
74  WordFilterBuilder() NLIB_NOEXCEPT : prv_(NULL) {}
76  bool Init() NLIB_NOEXCEPT;
77  WordFilter* Build() NLIB_NOEXCEPT;
78  bool AddWord(const char* str) NLIB_NOEXCEPT;
79  bool AddWords(const char* str, size_t len) NLIB_NOEXCEPT;
80  bool AddWords(const char* str) NLIB_NOEXCEPT {
81  return AddWords(str, nlib_strlen(str));
82  }
83  bool AddExcludeWord(const char* str) NLIB_NOEXCEPT;
84  bool AddExcludeWords(const char* str, size_t len) NLIB_NOEXCEPT;
85  bool AddExcludeWords(const char* str) NLIB_NOEXCEPT {
86  return AddExcludeWords(str, nlib_strlen(str));
87  }
88 
89  private:
90  struct WordFilterBuilderPrivate;
91  WordFilterBuilderPrivate* prv_;
93 };
94 
95 } // namespace succinct
96 NLIB_NAMESPACE_END
97 
98 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
99 #undef NLIB_VIS_PUBLIC
100 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
101 #endif
102 
103 #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:158
void swap(WordFilter &rhs) noexcept
Swaps the contents of an object.
Definition: WordFilter.h:45
void Match(const char *doc, MatchCallback callback, void *user_obj) noexcept
Inspects the string to detect the registered string.
Definition: WordFilter.h:51
#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:29
An empty structure indicating that an argument to a function needs to be moved.
Definition: Config.h:244
Defines the class for searching text strings using the Aho-Corasick string-matching algorithm...
WordFilter() noexcept
Instantiates the object.
Definition: WordFilter.h:33
WordFilter & assign(WordFilter &rhs, move_tag) noexcept
Assigns the object by using swap for a move.
Definition: WordFilter.h:36
#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:85
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:72
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:80
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:224
The class for reading binary from streams (from InputStream).
Definition: BinaryReader.h:26
WordFilterBuilder() noexcept
Instantiates the object.
Definition: WordFilter.h:74