Tests: Pitytest - Model creates ProcessNodes

LIB-11
heck 2 years ago
parent 972bf654d8
commit 0e270102a3

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

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

@ -3,21 +3,36 @@
#include "PityUnit.hh"
#include "iostream"
#include <memory>
#include <functional>
#include <sstream>
namespace pEp {
namespace PityTest11 {
bool PityNode::debug_log_enabled = false;
PityNode::PityNode(PityModel& model, int nodeNr) :
_model{ model }, _node_nr{ nodeNr }, _process_unit{
std::make_shared<PityUnit<PityModel>>(
&(_model.rootUnit()),
getName(),
nullptr,
nullptr,
PityUnit<PityModel>::ExecutionMode::PROCESS_PARALLEL)
}
PityNode::PityNode(PityModel& model, int nodeNr) : _node_nr{ nodeNr }
{
logger_debug.set_instancename(getName());
std::stringstream ss{};
ss << this;
pEpLogClass(std::string("called with: " + std::to_string(_node_nr) + "AT: " +ss.str()));
_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

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

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

Loading…
Cancel
Save