Browse Source

Tests: Pitytest - Model creates ProcessNodes

master
heck 4 years ago
parent
commit
4f8e339752
  1. 23
      src/PityModel.cc
  2. 14
      src/PityModel.hh
  3. 33
      src/PityNode.cc
  4. 8
      src/PityNode.hh
  5. 21
      test/test_model.cc

23
src/PityModel.cc

@ -6,13 +6,12 @@ namespace pEp {
namespace PityTest11 { namespace PityTest11 {
bool PityModel::debug_log_enabled = true; bool PityModel::debug_log_enabled = true;
PityModel::PityModel(const std::string& name, int nodesCount) : PityModel::PityModel(const std::string& name, int nodeCount) :
_name{ name }, _nodes_count{ nodesCount }, _root_unit{ nullptr, name, nullptr, this } _name{ name }, _root_unit{ nullptr, name, nullptr, this }
{ {
for (int i = 0; i < nodeCount; i++) {
for (int i = 0; i < nodesCount; i++) { auto tmp = std::make_shared<PityNode>(*this, i);
_nodes.emplace_back(PityNode(*this, i)); _nodes.emplace_back(tmp);
// _nodes.emplace_back(*this, i);
} }
} }
@ -21,7 +20,12 @@ namespace pEp {
return _name; return _name;
} }
std::vector<PityNode> PityModel::getNodes() const void PityModel::setName(std::string name)
{
_name = name;
}
std::vector<std::shared_ptr<PityNode>> PityModel::getNodes() const
{ {
return _nodes; return _nodes;
} }
@ -31,5 +35,10 @@ namespace pEp {
return _root_unit; return _root_unit;
} }
PityUnit<PityModel>* PityModel::getNodeUnit(int nr) const
{
return getNodes().at(nr)->getProcessUnit().get();
}
} // namespace PityTest11 } // namespace PityTest11
} // namespace pEp } // namespace pEp

14
src/PityModel.hh

@ -7,26 +7,30 @@
#include "../../../src/pEpLog.hh" #include "../../../src/pEpLog.hh"
#include "PityNode.hh" #include "PityNode.hh"
#include "PityUnit.hh" #include "PityUnit.hh"
#include <vector>
#include <memory>
namespace pEp { namespace pEp {
namespace PityTest11 { namespace PityTest11 {
class PityModel { class PityModel {
public: public:
PityModel() = delete; PityModel() = delete;
PityModel(const std::string& name, int nodesCount); PityModel(const std::string& name, int nodeCount);
std::string getName() const; std::string getName() const;
std::vector<PityNode> getNodes() const; void setName(std::string name) ;
std::vector<std::shared_ptr<PityNode>> getNodes() const;
PityUnit<PityModel>& rootUnit(); PityUnit<PityModel>& rootUnit();
PityUnit<PityModel>* getNodeUnit(int nr) const;
PityNode* own_node = nullptr;
//internal logging //internal logging
static bool debug_log_enabled; static bool debug_log_enabled;
Adapter::pEpLog::pEpLogger logger_debug{ "PityModel", debug_log_enabled }; Adapter::pEpLog::pEpLogger logger_debug{ "PityModel", debug_log_enabled };
private: private:
const int _nodes_count;
PityUnit<PityModel> _root_unit; PityUnit<PityModel> _root_unit;
std::vector<PityNode> _nodes; std::vector<std::shared_ptr<PityNode>> _nodes;
const std::string _name; std::string _name;
//internal logging //internal logging
Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug; Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug;

33
src/PityNode.cc

@ -3,21 +3,36 @@
#include "PityUnit.hh" #include "PityUnit.hh"
#include "iostream" #include "iostream"
#include <memory> #include <memory>
#include <functional>
#include <sstream>
namespace pEp { namespace pEp {
namespace PityTest11 { namespace PityTest11 {
bool PityNode::debug_log_enabled = false; bool PityNode::debug_log_enabled = false;
PityNode::PityNode(PityModel& model, int nodeNr) : PityNode::PityNode(PityModel& model, int nodeNr) : _node_nr{ nodeNr }
_model{ model }, _node_nr{ nodeNr }, _process_unit{ {
std::make_shared<PityUnit<PityModel>>( logger_debug.set_instancename(getName());
&(_model.rootUnit()), std::stringstream ss{};
getName(), ss << this;
nullptr, pEpLogClass(std::string("called with: " + std::to_string(_node_nr) + "AT: " +ss.str()));
nullptr,
PityUnit<PityModel>::ExecutionMode::PROCESS_PARALLEL) _process_unit = std::make_shared<PityUnit<PityModel>>(
} &(model.rootUnit()),
getName(),
std::bind(&PityNode::_init,this, std::placeholders::_1),
&model,
PityUnit<PityModel>::ExecutionMode::PROCESS_PARALLEL);
}
void PityNode::_init(const PityUnit<PityModel>& unit)
{ {
unit.log("INIT - " + getName());
unit.getModel()->own_node = this;
unit.getModel()->setName("Copy for:" + getName());
unit.log("INIT DONE");
} }
std::string PityNode::getName() const std::string PityNode::getName() const

8
src/PityNode.hh

@ -17,19 +17,17 @@ namespace pEp {
explicit PityNode(PityModel& model, int nodeNr); explicit PityNode(PityModel& model, int nodeNr);
std::string getName() const; std::string getName() const;
std::string to_string() const; std::string to_string() const;
const std::shared_ptr<PityUnit<PityModel>>& getProcessUnit() const;
//internal logging //internal logging
static bool debug_log_enabled; static bool debug_log_enabled;
Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled }; Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled };
private: private:
void _init(const PityUnit<PityModel>& unit);
const int _node_nr; const int _node_nr;
PityModel& _model;
std::shared_ptr<PityUnit<PityModel>> _process_unit; std::shared_ptr<PityUnit<PityModel>> _process_unit;
public:
const std::shared_ptr<PityUnit<PityModel>>& getProcessUnit() const;
private:
//internal logging //internal logging
Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug; Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug;
}; };

21
test/test_model.cc

@ -6,30 +6,33 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <algorithm> #include <algorithm>
#include <sstream>
using namespace std; using namespace std;
using namespace pEp::Adapter; using namespace pEp::Adapter;
using namespace pEp::PityTest11; using namespace pEp::PityTest11;
void test_node1(const PityUnit<PityModel>& unit) { void test_node1(const PityUnit<PityModel>& unit)
{
unit.log(unit.getModel()->getName());
unit.log(unit.getModel()->own_node->);
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
pEpLog::log("FSDFSD");
PityModel::debug_log_enabled = false; PityModel::debug_log_enabled = false;
PityNode::debug_log_enabled = false; PityNode::debug_log_enabled = true;
PityModel model{ "test_Model", 3 }; PityModel model{ "test_model", 3 };
for (PityNode n : model.getNodes()) { for (auto n : model.getNodes()) {
pEpLog::log(n.to_string()); pEpLog::log(n->getName());
} }
auto node1_unit = model.getNodes().at(0).getProcessUnit(); PityUnit<PityModel> node1_test1 = PityUnit<PityModel>{ model.getNodeUnit(0), "test1", &test_node1 };
PityUnit<PityModel> node1_test1 = PityUnit<PityModel>{ node1_unit.get(), "test1", nullptr }; PityUnit<PityModel> node2_test1 = PityUnit<PityModel>{ model.getNodeUnit(1), "test2", &test_node1 };
// model.getPerspective(0); PityUnit<PityModel> node3_test1 = PityUnit<PityModel>{ model.getNodeUnit(2), "test3", &test_node1 };
model.rootUnit().run(); model.rootUnit().run();
// pEpLog::log(model.rootUnit().to_string()); // pEpLog::log(model.rootUnit().to_string());

Loading…
Cancel
Save