Debian Codegraph @

src/util/UserphraseSet.cpp

raw symbols SCIP
1 /*
2 * chewing-editor: Chewing userphrase editor
3 * Copyright (C) 2014 Chewing Development Team
4
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "UserphraseSet.h"
21
22 #include <QDebug>
23
24 bool UserphraseSet::insert(Userphrase&& userphrase)
25 {
26 auto ret = dedup_.insert(userphrase.display_);
27 if (!ret.second) {
28 // Duplicate item shall not be stored.
29 qDebug() << "Duplicate phrase:" << userphrase.phrase_
30 << "bopomofo:" << userphrase.bopomofo_;
31 return false;
32 }
33
34 userphrase_.push_back(std::move(userphrase));
35 return true;
36 }
37
38 void UserphraseSet::erase(iterator it)
39 {
40 dedup_.erase(it->display_);
41 userphrase_.erase(it);
42 }
43
44 UserphraseSet::iterator UserphraseSet::begin()
45 {
46 return userphrase_.begin();
47 }
48
49 UserphraseSet::iterator UserphraseSet::end()
50 {
51 return userphrase_.end();
52 }
53
54 UserphraseSet::const_iterator UserphraseSet::begin() const
55 {
56 return userphrase_.begin();
57 }
58
59 UserphraseSet::const_iterator UserphraseSet::end() const
60 {
61 return userphrase_.end();
62 }
63
64 size_t UserphraseSet::size() const
65 {
66 return userphrase_.size();
67 }
68
69 const Userphrase& UserphraseSet::operator[](size_t index) const
70 {
71 return userphrase_[index];
72 }
73
74 void UserphraseSet::swap(UserphraseSet& set) noexcept
75 {
76 userphrase_.swap(set.userphrase_);
77 dedup_.swap(set.dedup_);
78 }