Commit dca2c2f1 authored by Alexis Lebis's avatar Alexis Lebis

Profession def ok

parent 5765d89b
......@@ -7,6 +7,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
ADD_EXECUTABLE(ceao main.cpp)
ADD_EXECUTABLE(ceao_competency ceao_competency.cpp)
ADD_EXECUTABLE(ceao_course ceao_course.cpp)
ADD_EXECUTABLE(ceao_profession ceao_profession.cpp)
ADD_EXECUTABLE(tryInit tryInit.cpp)
ADD_EXECUTABLE(tryMutation tryMutation.cpp)
......@@ -16,6 +17,7 @@ ADD_EXECUTABLE(tryEval tryEval.cpp)
ADD_DEPENDENCIES(ceao lQueen lModel)
ADD_DEPENDENCIES(ceao_competency lQueen lModel)
ADD_DEPENDENCIES(ceao_course lQueen lModel)
ADD_DEPENDENCIES(ceao_profession lQueen lModel)
ADD_DEPENDENCIES(tryInit lQueen)
ADD_DEPENDENCIES(tryMutation lQueen)
......@@ -27,6 +29,7 @@ ADD_DEPENDENCIES(tryEval lQueen)
TARGET_LINK_LIBRARIES(ceao ${PARADISEO_LIBRARIES} lQueen lModel)
TARGET_LINK_LIBRARIES(ceao_competency ${PARADISEO_LIBRARIES} lQueen lModel)
TARGET_LINK_LIBRARIES(ceao_course ${PARADISEO_LIBRARIES} lQueen lModel)
TARGET_LINK_LIBRARIES(ceao_profession ${PARADISEO_LIBRARIES} lQueen lModel)
TARGET_LINK_LIBRARIES(tryInit ${PARADISEO_LIBRARIES} lQueen)
TARGET_LINK_LIBRARIES(tryMutation ${PARADISEO_LIBRARIES} lQueen)
......
#include <eo>
#include <iostream>
#include <string>
#include <cassert>
#include <utility>
#include <vector>
#include "model/profession.h"
#include "model/competency.h"
int main(int argc, char* argv[])
{
Competency c1 = Competency::build(0.5);
Competency c2 = Competency::build(0.7);
Competency c3 = Competency::build(0.21);
Profession p1;
Profession p2("NameTest");
std::vector<Competency> vC;
vC.push_back(c1); vC.push_back(c2);
Profession p3(vC);
assert(p1.prerequisites().size() == 0);
assert(p1.name().compare("Profession#1") == 0);
assert(p2.name().compare("NameTest") == 0);
assert(p3.prerequisites().size() == 2);
assert(p3.prerequisites().at(0) == c1);
std::cout << "Profession constructors OK" << std::endl;
p2.setPrerequisites(vC);
assert(p2.prerequisites().size() == 2);
assert(p2.prerequisites().at(0) == c1);
bool state;
state=p2.addPrerequisite(c3);
assert(state);
assert(p2.prerequisites().size() == 3);
assert(p2.prerequisites().at(2) == c3);
state=p2.addPrerequisite(c3);
assert(!state);
assert(p2.prerequisites().size() == 3);
assert(p2.prerequisites().at(2) == c3);
std::cout << p2 << std::endl;
std::cout << p3 << std::endl;
c3.evolveTowards(0.4);
std::cout << c3 << std::endl;
std::cout << p2.prerequisites().at(2) << std::endl;
p2.unlocked_prerequisites().at(2).evolveTowards(0.3);
std::cout << c3 << std::endl;
std::cout << p2.prerequisites().at(2) << std::endl;
return EXIT_SUCCESS;
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ SET (EXERCICE_SOURCES
magnitude.cpp
competency.cpp
course.cpp
profession.cpp
)
ADD_LIBRARY(lModel STATIC ${EXERCICE_SOURCES})
......
......@@ -62,13 +62,13 @@ Course::Course(int id, int ects, std::string name)
{this->_weightedTeached = wComps;}
// ADDER
void Course::addTeachedComp(std::pair<Competency,double> wComp)
void Course::addTeachedComp(std::pair<Competency,double> & wComp)
{
if( _duplicataProtection(&(this->_weightedTeached), wComp.first))
return;
this->_weightedTeached.push_back(wComp);
}
void Course::addPrerequisite(Competency prereq)
void Course::addPrerequisite(Competency & prereq)
{
if( _duplicataProtection(&(this->_prerequisites), prereq) )
return;
......
......@@ -72,8 +72,8 @@ class Course
void setTeachedComps(std::vector<std::pair<Competency,double>>&);
// ADDER
void addTeachedComp(std::pair<Competency,double>);
void addPrerequisite(Competency);
void addTeachedComp(std::pair<Competency,double> &);
void addPrerequisite(Competency &);
void addTemporalFrame(int);
// DELETER
......
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include "profession.h"
#include "competency.h"
int Profession::PROFESSION_COUNTER = 0;
// === FACTORY
// No factory needed
// === END FACTORY
// === CONSTRUCTOR
Profession::Profession()
{
this->_id = assignID();
this->_name = "Profession#"+std::to_string(this->_id);
}
Profession::Profession(std::string name)
{
this->_id = assignID();
if(name.empty())
name = "Profession#"+std::to_string(this->_id);
this->_name = name;
}
Profession::Profession(std::vector<Competency> & p, std::string n)
: _prerequisites(p)
{
this->_id = assignID();
if(n.empty())
n = "Profession#"+std::to_string(this->_id);
this->_name = n;
}
// === END CONSTRUCTOR
// === MUTATOR
// SETTER
void Profession::setName(std::string name)
{
if(name.empty())
name = "Profession#"+std::to_string(this->_id);
this->_name = name;
}
std::vector<Competency> & Profession::setPrerequisites(std::vector<Competency> & p)
{
std::vector<Competency> * old = &this->_prerequisites;
this->_prerequisites = p;
return *old;
}
// ADDER
/** Adds a new competency to the prerequisites of a profession. It is protected against duplicata: it can't have twice the same competency.
*
* @return true if an insertion as been made into the prerequiste, false otherwise;
*
* Warning: does not use shallow copy. This can lead to a potential non constant behaviors if use with Profession(vector<Competency>) regarding the modification of compentecies outside this.
* @note Remove the referencing?
*/
bool Profession::addPrerequisite(Competency & c)
{
if(_duplicataProtection(& this->_prerequisites, c))
return false;
this->_prerequisites.push_back(c);
return true;
}
// === FUNC
/// _duplicataProtection returns true if the value (2nd param) searched into (1st param) is found
bool Profession::_duplicataProtection(std::vector<Competency> * prereq, Competency c)
{
std::vector<Competency>::iterator it = std::find( prereq->begin(), prereq->end(), c);
return it != prereq->end();
}
// === OPERATOR
std::ostream & operator<<(std::ostream & Stream, const Profession & p)
{
std::string s = "Profession\n\tid:"+std::to_string(p.id())+"\n\tname:"+p.name()+"\n\t#Prereq:"+std::to_string(p.prerequisites().size());
Stream << s;
return Stream;
}
// === STATIC
int Profession::assignID(){return ++Profession::PROFESSION_COUNTER;}
\ No newline at end of file
......@@ -13,12 +13,43 @@
class Profession
{
private:
std::vector<Competency> prerequisites;
std::vector<Competency> _prerequisites;
std::string _name;
int _id;
// === FUNC
/** _duplicataProtection returns true if the value (2nd param) searched into (1st param) is found*/
bool _duplicataProtection(std::vector<Competency> *, Competency);
// Static
static int S_professionCounter;
static int PROFESSION_COUNTER;
static int assignID();
public:
Profession();
Profession(std::string name);
Profession(std::vector<Competency> & p, std::string n = "");
// === GETTER
const int id() const{return this->_id;}
const std::string name() const{return this->_name;}
const std::vector<Competency> & prerequisites() const{return this->_prerequisites;}
/// return a modifiable reference to _prerequisite;
std::vector<Competency> & unlocked_prerequisites(){return this->_prerequisites;}
// === MUTATOR
// SETTER
/// Set name of the profession. If name empty, creates a default name based on ID
void setName(std::string name);
/// Set the prerequisites of a profession. The old prereq is returned.
std::vector<Competency> & setPrerequisites(std::vector<Competency> & v);
// ADDER
bool addPrerequisite(Competency &);
};
// === OPERATOR
std::ostream & operator<<(std::ostream & Stream, const Profession & p);
#endif // SRC_PROFESSION_H_
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment