1 // Copyright 2010-2018, Google Inc. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are 6 // met: 7 // 8 // * Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // * Redistributions in binary form must reproduce the above 11 // copyright notice, this list of conditions and the following disclaimer 12 // in the documentation and/or other materials provided with the 13 // distribution. 14 // * Neither the name of Google Inc. nor the names of its 15 // contributors may be used to endorse or promote products derived from 16 // this software without specific prior written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 #ifndef MOZC_DICTIONARY_SUPPRESSION_DICTIONARY_H_ 31 #define MOZC_DICTIONARY_SUPPRESSION_DICTIONARY_H_ 32 33 #include <set> 34 #include <string> 35 36 #include "base/mutex.h" 37 #include "base/port.h" 38 39 namespace mozc { 40 namespace dictionary { 41 42 class SuppressionDictionary { 43 public: 44 SuppressionDictionary(); 45 virtual ~SuppressionDictionary(); 46 47 // Locks dictionary. 48 // Need to lock before calling AddEntry() or Clear(). 49 // When the dictionary is locked, Supress() return false. 50 // 51 // NOTE: 52 // Lock() and SupressWord() must be called synchronously. 53 void Lock(); 54 55 // Unlocks dictionary. 56 void UnLock(); 57 58 // Returns true if the dictionary is locked. IsLocked()59 bool IsLocked() const { 60 return locked_; 61 } 62 63 // Note: this method is thread unsafe. 64 bool AddEntry(const string &key, const string &value); 65 66 // Note: this method is thread unsafe. 67 void Clear(); 68 69 // Returns true if SuppressionDictionary doesn't have any entries. 70 bool IsEmpty() const; 71 72 // Returns true if |word| should be suppressed. If the current dictionay is 73 // "locked" via Lock() method, this function always return false. Lock() and 74 // SuppressWord() must be called synchronously. 75 bool SuppressEntry(const string &key, const string &value) const; 76 77 private: 78 std::set<string> dic_; 79 bool locked_; 80 bool has_key_empty_; 81 bool has_value_empty_; 82 Mutex mutex_; 83 84 DISALLOW_COPY_AND_ASSIGN(SuppressionDictionary); 85 }; 86 87 } // namespace dictionary 88 } // namespace mozc 89 90 #endif // MOZC_DICTIONARY_SUPPRESSION_DICTIONARY_H_ 91