Commit faf2cf8b authored by Kevin Coulomb's avatar Kevin Coulomb

Correction d'erreurs.

parent a26edda8
#ifndef BINARYTREE
#define BINARYTREE
/*
*
*\file tree/BinaryTree.hpp
* \brief File that contains the definition of a binary tree
*\author COULOMB Kevin
*\date 03/09
*
*/
#ifndef BINARYTREE_HPP
#define BINARYTREE_HPP
#include <iostream>
......@@ -9,6 +19,7 @@
template <class E>
class BinaryTree{
// BinaryTree <E> * _current;
Node <E> * _current;
/*
......@@ -17,9 +28,9 @@ class BinaryTree{
*
*/
Node <E> *_father;
Node <E> *_left_child;
Node <E> *_right_child;
BinaryTree <E> *_father;
BinaryTree <E> *_left_child;
BinaryTree <E> *_right_child;
public :
......@@ -39,7 +50,7 @@ public :
/*
*
*\fn set_current_node( Node * event )
*\fn set_current_node( BinaryTree * event )
*\brief Set the current node
*
*/
......@@ -53,17 +64,17 @@ public :
*\brief Return the event field
*
*/
Node <E> *get_event(){
Node <E> *get_current(){
return _current;
}
/*
*
*\fn set_father( Node * )
*\fn set_father( BinaryTree * )
*\brief Set the father's node
*
*/
void set_father( Node <E> * father ){
void set_father( BinaryTree <E> * father ){
this->_father = father;
}
......@@ -73,27 +84,49 @@ public :
*\brief Returns the father
*
*/
Node <E> * get_father(){
BinaryTree <E> * get_father(){
return _father;
}
/*
*
*\fn has_father()
*\brief Returns if the current node has a father
*
*/
bool has_father(){
return (_father == NULL);
}
/*
*
*\fn has_father()
*\brief Returns if the current node has a father
*
*/
bool has_children(){
return ((_left_child == NULL)&&(_right_child==NULL));
}
/*
*
*\fn set_left_child( Node * child )
*\fn set_left_child( BinaryTree * child )
*\brief Set only the left child to child
*
*/
void set_left_child( Node <E> * child ){
void set_left_child( BinaryTree <E> * child ){
this->_left_child = child;
}
/*
*
*\fn set_right_child( Node * child )
*\fn set_right_child( BinaryTree * child )
*\brief Set only the right child to child
*
*/
void set_right_child( Node <E> * child ){
void set_right_child( BinaryTree <E> * child ){
this->_right_child = child;
}
......@@ -103,7 +136,7 @@ public :
*\brief Return only the left child
*
*/
Node <E> * get_left_child(){
BinaryTree <E> * get_left_child(){
return _left_child;
}
......@@ -113,17 +146,17 @@ public :
*\brief Return only the right child
*
*/
Node <E> * get_right_child(){
BinaryTree <E> * get_right_child(){
return _right_child;
}
/*
*
*\fn set_children ( Node * leftChild , Node * rightChild)
*\fn set_children ( BinaryTree * leftChild , BinaryTree * rightChild)
*\brief Calling setleft and set right, set the 2 children
*
*/
void set_children ( Node <E> * leftChild , Node <E> * rightChild){
void set_children ( BinaryTree <E> * leftChild , BinaryTree <E> * rightChild){
this->_left_child = leftChild;
this->_right_child = rightChild;
}
......@@ -134,8 +167,8 @@ public :
*\brief Return a pointer to a structure that contain respectively the left then the right child
*
*/
Node <E> * get_children(){
Node<E> * res[2];
BinaryTree <E> * get_children(){
BinaryTree<E> * res[2];
res[0] = get_left_child();
res[1] = get_right_child();
return res;
......
/*
*
*\file tree/Data.hpp
* \brief File that contains the definition of the data that will be displayed with if the user want more info on an event of the trace
*\author COULOMB Kevin
*\date 03/09
*
*/
#ifndef DATACONTAINER_HPP
#define DATACONTAINER_HPP
#include <iostream>
#include <string>
template <class E>
class Data{
std::string name;
std::string description;
E element;
}
private :
std::string _name;
std::string _description;
E _element;
public :
void set_name(std::string s);
std::string get_name();
};
#endif
#include "Interval.hpp"
Interval::Interval(){
leftSide = 0;
rightSide = 100;
interval = new Interval[4];
_left_side = 0;
_right_side = 100;
// _interval = new Interval[4];
}
void Interval::setLeft( time left ){
leftSide = left;
void Interval::set_left( time left ){
_left_side = left;
}
void Interval::setRight( time right ){
rightSide = right;
void Interval::set_right( time right ){
_right_side = right;
}
time Interval::getLeft (){
return leftSide;
time Interval::get_left (){
return _left_side;
}
time Interval::getRight (){
return rightSide;
time Interval::get_right (){
return _right_side;
}
#ifndef INTERVAL
#define INTERVAL
/*
*
*\file tree/Interval.hpp
* \brief File that contains the definition of an interval
*\author COULOMB Kevin
*\date 03/09
*
*/
#include "../../interface/ressource.hpp"
#ifndef INTERVAL_HPP
#define INTERVAL_HPP
#include "../../interface/resource.hpp"
class Interval{
times leftSide;
times rightSide;
Times _left_side;
Times _right_side;
public :
Interval();
void setLeft( times left );
void setRight( times right );
times getLeft () const;
times getRight () const;
void set_left( Times left );
void set_light( Times right );
Times get_left () const;
Times get_right () const;
};
......
PP = g++ -Wall -c
all : BinaryTree.o Interval.o Node.o TreeBuilder.o TreeUser.o
all :
clean :
rm *~ *.o
BinaryTree.o : BinaryTree.hpp
$(PP) BinaryTree.hpp -o BinaryTree.o
test : main.o test.o
$(LD) main.o test.o
Interval.o : Interval.cpp
$(PP) Interval.cpp -o Interval.o
main.o : MainTest.cpp
$(PP) MainTest.cpp -o main.o
Node.o : Node.hpp
$(PP) Node.hpp -o Node.o
TreeBuilder.o : TreeBuilder.hpp
$(PP) TreeBuilder.hpp -o TreeBuilder.o
TreeUser.o : TreeUser.hpp
$(PP) TreeUser.hpp -o TreeUser.o
\ No newline at end of file
test.o : TestTemplate.cpp
$(PP) TestTemplate.cpp -o test.o
\ No newline at end of file
/*
*
*\file tree/Node.hpp
* \brief File that contains the definition of a Node in the binary tree that contain the events
*\author COULOMB Kevin
*\date 03/09
......@@ -7,11 +8,11 @@
*/
#ifndef NODEEVENT
#define NODEEVENT
#ifndef NODEEVENT_HPP
#define NODEEVENT_HPP
#include <iostream>
//#include "../../../svn/svn_forge/vite/source/src/trace/values/"
#include "../values/Date.hpp"
#include "Interval.hpp"
#include "Data.hpp"
......@@ -25,8 +26,8 @@ class Node{
*\brief Used in the structure to know whether it is the beginning or the event of a state
*
*/
static const int BEGINNING=0;
static const int END=1;
static const int _BEGINNING=0;
static const int _END=1;
/*
......@@ -49,7 +50,7 @@ class Node{
*\brief To know whether it is the beginning or the end of an event
*
*/
int _typeofevent;
int _type_of_event;
/*
*
......@@ -92,7 +93,7 @@ public :
*
*/
void setTypeOfEvent(int TYPE){
_typeofevent = TYPE;
_type_of_event = TYPE;
}
/*
......@@ -102,7 +103,7 @@ public :
*
*/
int getTypeOfEvent(){
return _typeofevent;
return _type_of_event;
}
/*
......@@ -113,18 +114,30 @@ public :
*/
Data <E> * getCaracteristic(){
return _data;
return _caracteristic_of_event;
}
/*
*
*\fn getName()
*\fn get_name()
*\brief Returns only the name of the container in the data
*
*/
std::string getName(){
return _data.getName();
std::string get_name(){
return _caracteristic_of_event.getName();
}
/*
*
*\fn set_name()
*\brief Set the name of the container
*
*/
void set_name(std::string s){
_caracteristic_of_event.set_name(s);
}
/*
*
......@@ -133,7 +146,7 @@ public :
*
*/
std::string getDescription(){
return _data.getDescription();
return _caracteristic_of_event.getDescription();
}
/*
......
......@@ -4,6 +4,7 @@
/*
*
*\file tree/TreeBuiler.hpp
*\brief This class is used in order to build a binary tree from a list
*\author Kevin COULOMB
*\date March 09
......@@ -11,10 +12,154 @@
*/
#include "BinaryTree.hpp"
#inclue "Node.hpp"
#include "Node.hpp"
template <class E>
class TreeBuilder(){
class TreeBuilder{
public :
typedef enum STATUS{
FREE,
OCCUPED,
LOCKED
}STATUS;
private :
/*
*
*\brief Inner class that only exists for the tree builder
*\brief It is only used as a box in an array
*\brief 2 main fields : a STATUS and a NODE*
*\brief The status field represents if the box is free
*\brief The NODE* field is a pointer to a node that is not totaly fixed in the binary tree (missing a child or its father)
*
*/
class TableNode{
STATUS _status;
BinaryTree <E> * _tree;
public :
/*
*
*\fn TableNode()
*\brief Default constructor
*
*/
TableNode(){
_tree = NULL;
_status = FREE;
}
/*
*
*\fn set_status( int status)
*\brief Set the status of the node to'status'
*
*/
void set_status(int status){
this->_status = status;
}
/*
*
*\fn is_occuped()
*\brief To know if the box is occuped
*
*/
bool is_occuped(){
return _status == OCCUPED;
}
/*
*
*\fn is_free()
*\brief To know if the box is free
*
*/
bool is_free(){
return _status == free;
}
/*
*
*\fn is_occuped()
*\brief To know if the box is occuped
*
*/
bool is_locked(){
return _status == LOCKED;
}
/*
*
*\fn set_occuped()
*\brief Set the box status to occuped
*
*/
void set_busy(){
_status = OCCUPED;
}
/*
*
*\fn set_free()
*\brief Set the box status to free
*
*/
void set_free(){
_status = FREE;
}
/*
*
*\fn set_locked()
*\brief Set the box status to locked
*
*/
void set_locked(){
_status = LOCKED;
}
/*
*
*\fn get_status()
*\brief Return the current status
*
*/
STATUS get_status(){
return _status;
}
/*
*
*\fnset_node(Node *)
*\brief Set the node value
*
*/
void set_node(Node<E> * node){
this->_tree->current = node;
}
/*
*
*\fn get_node()
*\brief Return a pointer to the current node
*
*/
Node<E> * get_node(){
return _tree->get_node();
}
};//end of class node included
private :
std::list <E> _list;
BinaryTree <E> *_tree;
......@@ -33,14 +178,14 @@ class TreeBuilder(){
*
*
*/
TableNode<E> *_temporary;// = new TableNode[size];
TableNode *_temporary;// = new TableNode[size];
/*
*
*\brief The position where we have to begin in the table (avoid testing again if the first box is known to be locked)
*
*/
int _begining;
int _beginning;
public :
......@@ -55,7 +200,26 @@ class TreeBuilder(){
_list = NULL;
_tree = NULL;
_beginning = 0;
_temporary = new TableNode[size];
_temporary = new TableNode[_size];
}
TreeBuilder(std::list<E> l, BinaryTree<E> * t){
_size = 1;
_list = l;
_tree = t;
_beginning = 0;
_temporary = new TableNode[_size];
}
/*
*
*\fn get_tree()
*\brief Return the binary tree
*
*
*/
BinaryTree<E> * get_tree(){
return this->_tree;
}
/*
......@@ -96,6 +260,7 @@ class TreeBuilder(){
*/
void set_size(int size){
this->_size = size;
_temporary = new TableNode[size];
}
/*
......@@ -115,7 +280,7 @@ class TreeBuilder(){
*
*/
void clear_tree(){
BinaryTree<E> * copy = tree->getRoot();
BinaryTree<E> * copy = _tree->getRoot();
copy->clear_tree();
}
......@@ -125,7 +290,7 @@ class TreeBuilder(){
*\brief set the list that must be used to build the binary tree
*
*/
void set_list( list <E *> list){
void set_list( std::list <E >* list){
this->_list = list;
}
......@@ -182,7 +347,7 @@ class TreeBuilder(){
while (this->_list->has_next() ){
// create a node with the current element of the list
tmp = create_binary_tree(_list->get_current());
create_binary_tree(_list->get_current(),tmp);
// Getting the first position free where we can insert the node in the table
pos = get_first_freebox();
......@@ -230,7 +395,7 @@ class TreeBuilder(){
}//endwhile
// Treating the last Node and filling the tree
tmp = create_binary_tree(_list->get_current());
create_binary_tree(_list->get_current(),tmp);
pos = get_first_freebox();
set_node(tmp.get_current_node(),pos);
tmp = _temporary[pos];
......@@ -265,7 +430,7 @@ class TreeBuilder(){
}
else{
this->_beginning = -1;
this->_tree = new BinaryTree();
this->_tree = new BinaryTree<E>();
}
}
......@@ -273,16 +438,34 @@ class TreeBuilder(){
private :
/*
/*
*
*\fn get_rest(int power, int size)
*\brief Return the rest of size minus 2^power
*\fn create_binary_tree(std::list<E>,BinaryTree<E>*)
*\brief Create and fill a binary tree with the list parameter
*\param std::list : An element of the element
*\param BinaryTree : A binary tree with the node field filled with the list parameter. Others remain NULL.
*
*/
void create_binary_tree(std::list<E> list, BinaryTree<E> * tree){
Node<E> * node = new Node<E>();
node->set_name((string)list.pop());
set_father(NULL);
set_children(NULL,NULL);
set_current(node);
}
/*
*
*\fn get_rest(int power, int size)
*\brief Return the rest of size minus 2^power
*
*/
int get_rest(int power, int size){
return (size_list - pow(2,n));
return (size - pow(2,power));
}
/*
......@@ -306,7 +489,7 @@ class TreeBuilder(){
*
*/
void set_node(Node <E>* node, int pos){
_temporary[pos}.set_node(node);
_temporary[pos].set_node(node);
_temporary[pos].set_busy();
}
......@@ -328,144 +511,6 @@ class TreeBuilder(){