Samchon Framework for CPP  1.0.0
ExternalServerArray.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/templates/external/ExternalSystemArray.hpp>
5 # include <samchon/templates/external/ExternalServer.hpp>
6 
7 #include <thread>
8 
9 namespace samchon
10 {
11 namespace templates
12 {
13 namespace external
14 {
28  template <class System = ExternalServer>
30  : public virtual ExternalSystemArray<System>
31  {
32  public:
37  : ExternalSystemArray<System>()
38  {
39  };
40  virtual ~ExternalServerArray() = default;
41 
47  virtual void connect()
48  {
49  std::vector<std::thread> thread_array;
50 
51  for (size_t i = 0; i < size(); i++)
52  {
53  auto external_server = std::dynamic_pointer_cast<ExternalServer>(this->at(i));
54  if (external_server == nullptr)
55  continue;
56 
57  thread_array.emplace_back(&ExternalServer::connect, external_server.get());
58  }
59 
60  for (size_t i = 0; i < thread_array.size(); i++)
61  thread_array[i].join();
62  };
63  };
64 };
65 };
66 };