OSDN Git Service

データベースの検討開始。
[wordring-tm/wordring-tm.git] / proxy / tmtext.h
1 #ifndef TMTEXT_H
2 #define TMTEXT_H
3
4 #include "text.h"
5
6 #include <QString>
7 #include <QList>
8
9 #include <QJsonDocument>
10 #include <QJsonObject>
11 #include <QJsonArray>
12
13 #include <memory>
14
15 namespace TM
16 {
17
18 /*!
19  * \brief 単語間のリンクを表現するクラスです。
20  *
21  * 原単語と訳単語の多対多のリンクを表現します。
22  */
23 class WordLink
24 {
25 public:
26         typedef std::shared_ptr<WordLink> pointer;
27         typedef QList<Text::pointer> storage_type;
28
29 public:
30         enum : int { Source, Target, };
31
32 private:
33         WordLink();
34         WordLink(int place, Text::pointer word);
35
36 public:
37         void clear();
38         void append(int place, Text::pointer word);
39         void remove(int place, Text::pointer word);
40
41         bool is_valid() const;
42         bool is_empty() const;
43         bool contains(int place, Text::pointer word);
44         int size(int place) const;
45
46         storage_type* sources();
47         storage_type* targets();
48
49         QString debug_dump() const;
50
51         static pointer create();
52         static pointer create(int place, Text::pointer word);
53
54 private:
55         storage_type m_sources;
56         storage_type m_targets;
57 };
58
59 /*!
60  * \brief 単語間のリンクを作成・保持するクラスです。
61  *
62  * 複数の単語間リンクを保持するコンテナとしての機能を持ちます。
63  * 現在編集中の単語間リンクを明示する機能があります。
64  *
65  * ある特定の単語間リンクを編集するには、start()を呼び出し編集を開始し、
66  * append()呼び出しによってリンクへ単語を追加し、
67  * commit()呼び出しによって編集を終了します。
68  */
69 class WordLinker
70 {
71 public:
72         typedef QList<WordLink::pointer> storage_type;
73         typedef storage_type::iterator iterator;
74         typedef storage_type::const_iterator const_iterator;
75
76 public:
77         void clear();
78
79         void start();
80         void commit();
81         void append(int place, Text::pointer word);
82         void remove(int place, Text::pointer word);
83         void toggle(int place, Text::pointer word);
84
85         WordLink::pointer current();
86
87         WordLink::pointer find(Text::pointer word);
88         WordLink::pointer find(int place, Text::pointer word);
89
90         int index_of(WordLink::pointer link) const;
91
92         iterator begin();
93         iterator end();
94
95         QString debug_dump() const;
96
97 private:
98         WordLink::pointer m_current_link;
99         storage_type m_links;
100 };
101
102 } // namespace TM
103
104 #endif // TMTEXT_H