diff --git a/src/machine.cpp b/src/machine.cpp index e69de29..5dec998 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -0,0 +1,16 @@ +#include "machine.hpp" + +Machine::Machine(const std::string& ip,unsigned int connectionsMax): ip{ip}, connections{0},connectionsMax{connectionsMax} +{} + +void Machine::addConnection(){ + connections+=1; +} + +unsigned int Machine::getNbConnections() const{ + return connections; +} + +unsigned int Machine::getNbConnectionsMax() const{ + return connectionsMax; +} \ No newline at end of file diff --git a/src/machine.hpp b/src/machine.hpp index 4fb3434..3ee31ba 100644 --- a/src/machine.hpp +++ b/src/machine.hpp @@ -1,8 +1,20 @@ #pragma once +#include class Machine{ - unsigned int connection; - unsigned int connectionMax; + std::string ip; -} \ No newline at end of file + unsigned int connections; + unsigned int connectionsMax; + + public: + Machine(const std::string& ip,unsigned int connectionsMax); + void addConnection(); + unsigned int getNbConnections() const; + unsigned int getNbConnectionsMax() const; + + bool operator<(const Machine& other) const { + return (connectionsMax-connections) < other.getNbConnectionsMax() - other.getNbConnections(); + } +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index d8febc1..38d90fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,35 @@ #include #include #include "programme.hpp" +#include "machine.hpp" #include int main() { - Programme prog1({"file1.txt","file2.txt","file3.txt"}, "image1"); - std::queue file; - file.push(prog1); - + //Programme prog1({"file1.txt","file2.txt","file3.txt"}, "image1"); + //std::queue file; + //file.push(prog1); //while true{ //} + + Machine m1("101.00.00.00",11); + Machine m2("102.00.00.00",12); + Machine m3("103.00.00.00",13); + Machine m4("104.00.00.00",10); + Machine m5("105.00.00.00",9); + + std::priority_queue machines; + machines.push(m1); + machines.push(m2); + machines.push(m3); + machines.push(m4); + machines.push(m5); + + while (!machines.empty()) { + Machine top = machines.top(); + machines.pop(); + std::cout << "Connections: " << top.getNbConnectionsMax() << std::endl; + } } \ No newline at end of file