-
Notifications
You must be signed in to change notification settings - Fork 0
Alex net #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Alex net #6
Changes from all commits
ddcb12d
f1563a2
187c1c3
22174fa
b9b8902
9c1e54b
eb73346
d231b11
d8f1197
b4efdc7
8a4b535
cf0a0d3
dcf1268
7769dde
8db4d63
8560767
0c7b8a7
4d7ea3a
3f7c9d8
8ce52a2
384b94d
dc77c93
1ad84c9
4c18d46
ae03588
96199d2
b472cb3
0c32f8e
f7d4075
782e5b3
d001dbb
68bbb4b
b6ae22b
28e8aaa
5b899b3
f484869
0498cfc
cc0ba47
a294c18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| version: 2 | ||
|
|
||
| jobs: | ||
| build: | ||
| docker: | ||
| - image: "serega753/cpp_project:actual" | ||
| working_directory: /app/TP_CPP_PROJECT | ||
| steps: | ||
| - checkout | ||
| - setup_remote_docker: | ||
| docker_layer_caching: true | ||
| - run: | ||
| name: cd | ||
| command: 'cd /app/TP_CPP_PROJECT' | ||
| - run: | ||
| name: cp cmake | ||
| command: 'cp /app/net_cmake/CMakeLists.txt /app/TP_CPP_PROJECT/Net/' | ||
| - run: | ||
| name: Creating Build Files | ||
| command: 'cmake Net/CMakeLists.txt && cd Net/ && make' | ||
| - run: | ||
| name: testing | ||
| command: '/app/TP_CPP_PROJECT/Net/net_tests' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,6 @@ | |
| *.exe | ||
| *.out | ||
| *.app | ||
| Net/CMakeLists.txt | ||
| Net/cmake-build-debug* | ||
| Net/.idea* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // | ||
| // Created by alex on 17.12.18. | ||
| // | ||
|
|
||
| #ifndef NET_ABSTRACTCLIENTNETOBJECT_H | ||
| #define NET_ABSTRACTCLIENTNETOBJECT_H | ||
|
|
||
| #include "AbstractNetObject.h" | ||
|
|
||
| class AbstractClientNetObject : public AbstractNetObject | ||
| { | ||
|
|
||
| }; | ||
|
|
||
|
|
||
| #endif //NET_ABSTRACTCLIENTNETOBJECT_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // | ||
| // Created by alex on 17.12.18. | ||
| // | ||
|
|
||
| #ifndef NET_ABSTRACTNETOBJECT_H | ||
| #define NET_ABSTRACTNETOBJECT_H | ||
|
|
||
| #include "Serializable.h" | ||
|
|
||
| class AbstractNetObject | ||
| { | ||
| public: | ||
| virtual void send(Serializable* serializable) = 0; | ||
| virtual std::vector<std::shared_ptr<Serializable>> receive() = 0; | ||
| virtual void work() = 0; | ||
| }; | ||
|
|
||
|
|
||
| #endif //NET_ABSTRACTNETOBJECT_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // | ||
| // Created by alex on 17.12.18. | ||
| // | ||
|
|
||
| #ifndef NET_ABSTRACTSERVERNETOBJECT_H | ||
| #define NET_ABSTRACTSERVERNETOBJECT_H | ||
|
|
||
|
|
||
| #include "AbstractNetObject.h" | ||
|
|
||
| class AbstractServerNetObject :public AbstractNetObject | ||
| { | ||
| public: | ||
| virtual void send(Serializable* serializable, int player_number) = 0; | ||
| }; | ||
|
|
||
|
|
||
| #endif //NET_ABSTRACTSERVERNETOBJECT_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // | ||
| // Created by alex on 17.12.18. | ||
| // | ||
|
|
||
| #ifndef NET_CLIENTNETOBJECT_H | ||
| #define NET_CLIENTNETOBJECT_H | ||
|
|
||
| #include <map> | ||
| #include "AbstractClientNetObject.h" | ||
| #include "DefaultAbstractFactory.h" | ||
| #include "noncopyable.h" | ||
|
|
||
| class ClientNetObjectImpl; | ||
|
|
||
| class ClientNetObject : public AbstractClientNetObject, public noncopyable | ||
| { | ||
| public: | ||
| ClientNetObject(std::string ip, uint port, std::map<std::string, DefaultAbstractFactory*> _map, | ||
| std::string startobj_string, | ||
| std::string endobj_string, | ||
| size_t type_length, int wait_time); | ||
| ~ClientNetObject(); | ||
|
|
||
| void send(Serializable *serializable) override; | ||
| std::vector<std::shared_ptr<Serializable>> receive() override; | ||
| void work() override; | ||
|
|
||
| private: | ||
| ClientNetObjectImpl *impl; | ||
| }; | ||
|
|
||
|
|
||
| #endif //NET_CLIENTNETOBJECT_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // | ||
| // Created by alex on 23.11.18. | ||
| // | ||
|
|
||
| #ifndef NET_DEFAULTABSTRACTFACTORY_H | ||
| #define NET_DEFAULTABSTRACTFACTORY_H | ||
|
|
||
| #include "Serializable.h" | ||
|
|
||
| class DefaultAbstractFactory | ||
| { | ||
| public: | ||
| virtual std::shared_ptr<Serializable> create() = 0; | ||
| virtual ~DefaultAbstractFactory() = default; | ||
| }; | ||
|
|
||
|
|
||
| #endif //NET_DEFAULTABSTRACTFACTORY_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // | ||
| // Created by alex on 12.11.18. | ||
| // | ||
|
|
||
| #ifndef NET_SERIALIZABLE_H | ||
| #define NET_SERIALIZABLE_H | ||
|
|
||
| #include <string> | ||
| #include <boost/archive/text_iarchive.hpp> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. нехорошо, что в общем интерфейсе Serializable задействован Boost |
||
| #include <boost/archive/text_oarchive.hpp> | ||
|
|
||
| struct Serializable | ||
| { | ||
| public: | ||
| virtual void serialize(boost::archive::text_oarchive& ar) = 0; | ||
|
|
||
| virtual void deserialize(boost::archive::text_iarchive& ar) = 0; | ||
| // virtual void serialize(boost::archive::text_iarchive& ar, const unsigned int version) = 0; | ||
| // virtual void serialize(boost::archive::text_oarchive& ar, const unsigned int version) = 0; | ||
| virtual ~Serializable() = default; | ||
| }; | ||
|
|
||
|
|
||
| #endif //NET_SERIALIZABLE_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // | ||
| // Created by alex on 17.12.18. | ||
| // | ||
|
|
||
| #ifndef NET_SERVERNETOBJECT_H | ||
| #define NET_SERVERNETOBJECT_H | ||
|
|
||
|
|
||
| #include <map> | ||
| #include "AbstractServerNetObject.h" | ||
| #include "DefaultAbstractFactory.h" | ||
| #include "noncopyable.h" | ||
|
|
||
| class ServerNetObjectImpl; | ||
|
|
||
| class ServerNetObject : public AbstractServerNetObject, public noncopyable | ||
| { | ||
| public: | ||
| ServerNetObject(std::string ip, uint port, int player_num, std::map<std::string, DefaultAbstractFactory*> _map, | ||
| std::string startobj_string, | ||
| std::string endobj_string, | ||
| size_t type_length, int wait_time); | ||
| ~ServerNetObject(); | ||
|
|
||
| void send(Serializable *serializable) override; | ||
| std::vector<std::shared_ptr<Serializable>> receive() override; | ||
| void work() override; | ||
| void send(Serializable *serializable, int player_number) override; | ||
| private: | ||
| ServerNetObjectImpl* impl; | ||
| }; | ||
|
|
||
|
|
||
| #endif //NET_SERVERNETOBJECT_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // | ||
| // Created by alex on 17.12.18. | ||
| // | ||
|
|
||
| #ifndef NET_NONCOPYABLE_H | ||
| #define NET_NONCOPYABLE_H | ||
|
|
||
|
|
||
| class noncopyable | ||
| { | ||
| protected: | ||
| noncopyable() = default; | ||
| ~noncopyable() = default; | ||
| public: | ||
| noncopyable(noncopyable&) = delete; | ||
| noncopyable(noncopyable&&) = delete; | ||
| noncopyable& operator=(noncopyable&) = delete; | ||
| noncopyable&& operator=(noncopyable&&) = delete; | ||
| }; | ||
|
|
||
|
|
||
| #endif //NET_NONCOPYABLE_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // | ||
| // Created by alex on 23.12.18. | ||
| // | ||
|
|
||
| #ifndef NET_SERIALIZATIONOPERATION_H | ||
| #define NET_SERIALIZATIONOPERATION_H | ||
|
|
||
| #include <string> | ||
| #include <map> | ||
| #include <iostream> | ||
|
|
||
| #include "DefaultAbstractFactory.h" | ||
|
|
||
| class SerializationOperation | ||
| { | ||
| public: | ||
| SerializationOperation(std::map<std::string, DefaultAbstractFactory*> _map, | ||
| std::string startobj_string, | ||
| std::string endobj_string, | ||
| size_t type_length); | ||
|
|
||
| std::string serialize(Serializable* serializable) const; | ||
| std::shared_ptr<Serializable> deserialize(std::string& wrong_data_recv_buf, std::string& temp_recv_buf) const; | ||
| std::string get_endobj() const; | ||
|
|
||
| private: | ||
| std::map<std::string, DefaultAbstractFactory*> map; | ||
| const std::string STARTOBJ; | ||
| const std::string ENDOBJ; | ||
| const size_t TYPE_LENGTH; | ||
| }; | ||
|
|
||
|
|
||
| #endif //NET_SERIALIZATIONOPERATION_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // | ||
| // Created by alex on 17.12.18. | ||
| // | ||
|
|
||
| #include "../include/ClientNetObject.h" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. недоработали с Cmake... |
||
| #include "ClientNetObjectImpl.cpp" | ||
|
|
||
| ClientNetObject::ClientNetObject( | ||
| std::string ip, | ||
| uint port, | ||
| std::map<std::string, DefaultAbstractFactory*> _map, | ||
| std::string startobj_string = "STARTOBJ", | ||
| std::string endobj_string = "ENDOBJ", | ||
| size_t type_length = 3, int wait_time = 1) | ||
| { | ||
| impl = new ClientNetObjectImpl(ip, port, _map, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. почему не умный указатель? |
||
| startobj_string, | ||
| endobj_string, | ||
| type_length, wait_time); | ||
| } | ||
|
|
||
| ClientNetObject::~ClientNetObject() | ||
| { | ||
| delete impl; | ||
| } | ||
|
|
||
| void ClientNetObject::send(Serializable *serializable) | ||
| { | ||
| impl->send(serializable); | ||
| } | ||
|
|
||
| std::vector<std::shared_ptr<Serializable>> ClientNetObject::receive() | ||
| { | ||
| return impl->receive(); | ||
| } | ||
|
|
||
| void ClientNetObject::work() | ||
| { | ||
| impl->work(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше было бы не использовать map, а инкапсулировать эту структуру данных в отдельном классе