• R/O
  • HTTP
  • SSH
  • HTTPS

libcore: Commit

GikoMonaのソフトウェアの基幹部分を集めて1つのライブラリに集約したものです。gikomona/pnutsのコンパイルにはこのライブラリが必須です。


Commit MetaInfo

Revision3b72ad2c2805ecbd4b349ed39fc319bac6a0ffe4 (tree)
Time2014-08-10 01:34:10
Authorcaprice <caprice@user...>
Commitercaprice

Log Message

mail_containerをiteratableにしたが、、、もはやcommunication/*は肥大化しすぎている

Change Summary

Incremental Difference

--- a/include/communication/mail.hpp
+++ b/include/communication/mail.hpp
@@ -2,8 +2,10 @@
22 #ifndef GIKOMONA_CORE_COMMUNICATION_MAIL_HPP
33 #define GIKOMONA_CORE_COMMUNICATION_MAIL_HPP
44
5-#include <vector>
5+#include <queue>
66 #include <memory>
7+#include <mutex>
8+#include <algorithm>
79
810 #include "message.hpp"
911
@@ -19,19 +21,112 @@ struct mail {
1921 message msg;
2022 };
2123
24+typedef std::vector<mail> mail_container_;
25+
2226 typedef std::shared_ptr<std::vector<mail>> mailbox;
2327
2428 class mail_container {
29+public:
2530 mail_container();
2631 ~mail_container();
2732
28- bool post(const mail&);
29- mail recieve();
33+ typedef mail_container self_type;
34+ typedef mail value_type;
35+ typedef std::queue<mail> mail_queue;
36+
37+ self_type& operator=(const self_type& other) {}
38+ self_type& operator=(self_type&& other) {}
39+
40+ struct posted_mail_list_viewer {
41+ friend class mail_container;
42+ posted_mail_list_viewer(const mail_queue& m) {}
43+ public:
44+ ~posted_mail_list_viewer();
45+ iterator begin() { return mail_list.begin(); }
46+ const_iterator cbegin() { return mail_list.cbegin(); }
47+
48+ iterator end() { return mail_list.end() }
49+ const_iterator cend() { return mail_list.cend(); }
50+ };
51+
52+ struct received_mail_list_viewer {
53+ friend class mail_container {}
54+ received_mail_list_viewer(const mail_queue& m);
55+ public:
56+ ~received_mail_list_viewer();
57+ };
58+
59+ posted_mail_list_viewer posted_mail_list() {
60+ std::lock_guard<std::mutex> do_lock(pmq_mutex);
61+ return posted_mail_list_viewer(posted_mail_queue);
62+ }
63+
64+ received_mail_list_viewer received_mail_list() {
65+ std::lock_guard<std::mutex> do_lock(rmq_mutex);
66+ return received_mail_list_viewer(received_mail_queue);
67+ }
68+
69+ void post(const mail& m) {
70+ std::lock_guard<std::mutex> do_lock(pmq_mutex);
71+ posted_mail_queue.push(m);
72+ }
3073
31- bool empty();
32- std::size_t size();
74+ mail recieve() {
75+ std::lock_guard<std::mutex> do_lock(rmq_mutex);
76+
77+ if(!received_mail_queue.empty()) {
78+ mail m = received_mail_queue.front();
79+ receieved_mail_queue.pop();
80+ }
81+
82+ return std::move(m);
83+ }
84+
85+ template <template <class...> class Container>
86+ Container<mail> collect() {
87+ std::lock_guard<std::mutex> do_lock(pmq_mutex);
88+
89+ Container<mail> cont(posted_mail_queue.size());
90+ while(!posted_mail_queue.empty()) {
91+ cont.push_back(posted_mail_queue.front());
92+ posted_mail_queue.pop();
93+ }
94+
95+ return std::move(cont);
96+ }
97+
98+ void deliver();
99+private:
100+ std::mutex pmq_mutex;
101+ std::mutex rmq_mutex;
102+ mail_queue posted_mail_queue;
103+ mail_queue received_mail_queue;
33104 };
34105
106+bool operator==(const mail_container& lhs, const mail_container& rhs) {
107+ if(lhs.size() == rhs.size()) {}
108+
109+ return false;
110+}
111+
112+bool operator!=(const mail_container& lhs, const mail_container& rhs) {
113+ return !(lhs == rhs);
114+}
115+bool operator<(const mail_container& lhs, const mail_container& rhs) {
116+ return (lhs.size() < rhs.size());
117+}
118+
119+bool operator>(const mail_container& lhs, const mail_container& rhs) {
120+ return (lhs.size() < rhs.size());
121+}
122+
123+bool operator<=(const mail_container& lhs, const mail_container& rhs) {
124+ return (lhs == rhs ? true : lhs < rhs);
125+}
126+bool operator>=(const mail_container& lhs, const mail_container& rhs) {
127+ return (lhs == rhs ? true : lhs < rhs);
128+}
129+
35130 mailbox create_mailbox();
36131 void destroy_mailbox(mailbox&& mb);
37132
Show on old repository browser