Commit 56a074de authored by Clément Vuchener's avatar Clément Vuchener

Changement du sytème de message

parent b9c8ee9f
......@@ -7,8 +7,6 @@
#include "interface_console.hpp"
using namespace std;
using namespace message_ns;
/***********************************
*
......@@ -39,7 +37,7 @@ Interface_console::Interface_console(int argc, char ** argv){
_run_env[1] = argv[0];
Message::set_interface_instance(this);/* define which interface will receive messages */
Message::set_interface(this);/* define which interface will receive messages */
useGUI = true;
......@@ -101,7 +99,7 @@ bool Interface_console::draw_trace(const string & filename, Render_area* render_
}
catch (const string &error){
//message << "unable to parse " << filename << ende;
message << "Reason : " << error << ende;
*Message::get_instance() << "Reason : " << error << Message::ende;
return false;
}
drawing.build(render_area, &trace);
......@@ -123,7 +121,7 @@ bool Interface_console::draw_trace(const string & filename, Svg* svg){
}
catch (const string &error){
//message << "unable to parse " << filename << ende;
message << "Reason : " << error << ende;
*Message::get_instance() << "Reason : " << error << Message::ende;
return false;
}
......@@ -259,19 +257,19 @@ void Interface_console::launch_action(int state){
case _STATE_LAUNCH_GRAPHICAL_INTERFACE :
_main_window = new Interface_graphic(this);/* launch the window interface */
Message::set_interface_instance(_main_window);/* define which interface will receive messages */
Message::set_interface(_main_window);/* define which interface will receive messages */
break;
case _STATE_OPEN_FILE:
information(string("Opening the file: ")+string(_file_opened));
_main_window = new Interface_graphic(this, _file_opened);/* launch the window interface and open a file */
Message::set_interface_instance(_main_window);/* define which interface will receive messages */
Message::set_interface(_main_window);/* define which interface will receive messages */
break;
case _STATE_EXPORT_FILE:
message << "export of " << _file_opened << " to " << _path_to_export << endi;
*Message::get_instance() << "export of " << _file_opened << " to " << _path_to_export << Message::endi;
///// Do the export /////
{
Svg svg;
......
......@@ -9,8 +9,7 @@
using namespace std;
using namespace message_ns;
#define message message_ns::message << "(" << __FILE__ << " l." << __LINE__ << "): "
#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): "
/***********************************
......@@ -154,7 +153,7 @@ void Render_area::resizeGL(int width, int height){
glOrtho(0, _render_width, 0, _render_height, 0, -1000);
break;
default:
message << "Undefined value for the drawing state attribute - Render area" << ende;
message << "Undefined value for the drawing state attribute - Render area" << Message::ende;
}
......@@ -249,7 +248,7 @@ void Render_area::paintGL(){
if (glIsList(_list_containers)==GL_FALSE)
message << "ERROR LIST not exist for containers." << ende;
message << "ERROR LIST not exist for containers." << Message::ende;
else
glCallList(_list_containers);
......@@ -302,7 +301,7 @@ void Render_area::paintGL(){
if (glIsList(_list_states)==GL_FALSE)
message << "ERROR LIST not exist for states." << ende;
message << "ERROR LIST not exist for states." << Message::ende;
else
glCallList(_list_states);
......@@ -314,8 +313,9 @@ void Render_area::paintGL(){
glTranslated(_default_entity_x_translate - _state_translate , 0.0f, _z_counter);
glScalef( _state_scale*(_render_width/_state_x_max), (_render_height-_rule_height)/_container_y_max, 0.0f);
if (glIsList(_list_counters)==GL_FALSE)
message << "ERROR LIST not exist for counters." << ende;
if (glIsList(_list_counters)==GL_FALSE) {
message << "ERROR LIST not exist for counters." << Message::ende;
}
else
glCallList(_list_counters);
......@@ -331,7 +331,7 @@ void Render_area::paintGL(){
break;
default:
message << "Undefined value for the drawing state attribute - Render area" << ende;
message << "Undefined value for the drawing state attribute - Render area" << Message::ende;
}
......@@ -342,7 +342,7 @@ void Render_area::paintGL(){
GLenum glerror;
glerror = glGetError();
if( glerror != GL_NO_ERROR)
message << "Render area : the following OpengGL error occured: " << (char *)gluErrorString(glerror) << endw;
message << "Render area : the following OpengGL error occured: " << (char *)gluErrorString(glerror) << Message::endw;
}
......@@ -417,22 +417,22 @@ bool Render_area::unbuild(){
glDeleteLists(_list_containers, 1);
_list_containers = 0;
if (glIsList(_list_containers)==GL_TRUE)/* if the list exists */
message << "Cannot delete container list" << ende;
if (glIsList(_list_containers)==GL_TRUE) /* if the list exists */
message << "Cannot delete container list" << Message::ende;
/* Free state list */
glDeleteLists(_list_states, 1);
_list_states = 0;
if (glIsList(_list_states)==GL_TRUE)/* if the list exists */
message << "Cannot delete state list" << ende;
if (glIsList(_list_states)==GL_TRUE) /* if the list exists */
message << "Cannot delete state list" << Message::ende;
/* Free counter list */
glDeleteLists(_list_counters, 1);
_list_counters = 0;
if (glIsList(_list_counters)==GL_TRUE)/* if the list exists */
message << "Cannot delete counter list" << ende;
if (glIsList(_list_counters)==GL_TRUE) /* if the list exists */
message << "Cannot delete counter list" << Message::ende;
/********************
......@@ -453,14 +453,14 @@ bool Render_area::unbuild(){
if (glIsList(_wait_list)==GL_FALSE)
_wait_list = draw_wait();/* create the wait draw */
else{
message << "The wait draw was not released." << endw;
else {
message << "The wait draw was not released." << Message::endw;
return false;
}
/* if there is an error, do not display the wait an return immediatly */
if (glIsList(_wait_list)==GL_FALSE) {
message << "Cannot create the wait draw." << endw;
message << "Cannot create the wait draw." << Message::endw;
return false;
}
......@@ -528,9 +528,8 @@ GLuint Render_area::draw_wait() {
GLuint texture;
object = glGenLists(1);/* create the list */
if (object == 0){
message << "Error when creating list" << endw;
}
if (object == 0)
message << "Error when creating list" << Message::endw;
glGenTextures(1, &texture);/* create the texture and link it with the list previously created */
......
#include "render_svg.hpp"
#include "../message/message_ns.hpp"
#include "../message/Message.hpp"
using namespace std;
......
......@@ -29,11 +29,11 @@ typedef double Element_col;
/* Message management */
#include "message/message_ns.hpp"
#include "message/Message.hpp"
/* Example:
* message << "Test:" << 45 << " and " << true << endi;
* *Message::get_instance() << "Test:" << 45 << " and " << true << Message::endi;
* -> display as an informative message.
*/
......
#include "Message.hpp"
Message *Message::_message = NULL;
Interface *Message::_interface = NULL;
Message::Message() {
}
Message *Message::get_instance() {
if (_message)
return _message;
else
return _message = new Message();
}
void Message::kill() {
if (_message)
delete _message;
_message = NULL;
}
void Message::set_interface(Interface *interface) {
_interface = interface;
}
Interface *Message::get_interface() {
return _interface;
}
std::ostream &operator<<(std::ostream &out, Message::end_error_t) {
Message *message = Message::get_instance();
Interface *interface = Message::get_interface();
if (interface) {
interface->error(message->str());
message->str(""); // flush the stream
} else {
std::cerr << "Warning: no interface designed to display messages." << std::endl;
}
return out;
}
std::ostream &operator<<(std::ostream &out, Message::end_warning_t) {
Message *message = Message::get_instance();
Interface *interface = Message::get_interface();
if (interface) {
interface->warning(message->str());
message->str(""); // flush the stream
} else {
std::cerr << "Warning: no interface designed to display messages." << std::endl;
}
return out;
}
std::ostream &operator<<(std::ostream &out, Message::end_information_t) {
Message *message = Message::get_instance();
Interface *interface = Message::get_interface();
if (interface) {
interface->warning(message->str());
message->str(""); // flush the stream
} else {
std::cerr << "Warning: no interface designed to display messages." << std::endl;
}
return out;
}
#ifndef MESSAGE_HPP
#define MESSAGE_HPP
#include <sstream>
#ifndef TEST_MESSAGE
/* Release mode */
#include "../interface/interface.hpp"
#else
/* Test mode */
#include <iostream>
class Interface {
public:
void error(const std::string& s) {
std::cerr <<"ERROR: " << s << std::endl;
}
void warning(const std::string& s) {
std::cerr <<"WARNING: " << s << std::endl;
}
void information(const std::string& s) {
std::cerr <<"INFORMATION: " << s << std::endl;
}
};
#endif
class Message: public std::stringstream {
private:
static Message *_message;
static Interface *_interface;
Message();
public:
static const struct end_error_t { } ende;
static const struct end_warning_t { } endw;
static const struct end_information_t { } endi;
static Message *get_instance();
static void kill();
static void set_interface(Interface *);
static Interface *get_interface();
};
std::ostream &operator<<(std::ostream &, Message::end_error_t);
std::ostream &operator<<(std::ostream &, Message::end_warning_t);
std::ostream &operator<<(std::ostream &, Message::end_information_t);
#endif
/*!
*\file enderror.cpp
*\brief This is the end error message C source code.
*/
#include "enderror.hpp"
Enderror::Enderror(){
}
/*!
*\file enderror.hpp
*/
#ifndef ENDERROR_HPP
#define ENDERROR_HPP
/*!
* \brief This class is used by message system to determine what kind of message information belongs to. Here, it is for error messages.
*/
struct Enderror{
/*!
* \brief The default constructor.
*/
Enderror();
};
#endif
/*!
*\file endinformation.cpp
*\brief This is the end information message C source code.
*/
#include "endinformation.hpp"
Endinformation::Endinformation(){
}
/*!
*\file endinformation.hpp
*/
#ifndef ENDINFORMATION_HPP
#define ENDINFORMATION_HPP
/*!
* \brief This class is used by message system to determine what kind of message information belongs to. Here, it is for informative messages.
*/
struct Endinformation{
/*!
* \brief The default constructor.
*/
Endinformation();
};
#endif
/*!
*\file endwarning.cpp
*\brief This is the end warning message C source code.
*/
#include "endwarning.hpp"
Endwarning::Endwarning(){
}
/*!
*\file endwarning.hpp
*/
#ifndef ENDWARNING_HPP
#define ENDWARNING_HPP
/*!
* \brief This class is used by message system to determine what kind of message information belongs to. Here, it is for warning messages.
*/
struct Endwarning{
/*!
* \brief The default constructor.
*/
Endwarning();
};
#endif
/*!
*\file message.cpp
*\brief This is the message C source code.
*/
#include "message.hpp"
using namespace std;
/* define the static variable */
Interface* Message::_interface = NULL;
Message::Message(){
}
void Message::set_interface_instance(Interface* i){
_interface = i;
}
Interface* Message::get_interface_instance(){
return _interface;
}
/*!
*\file message.hpp
*/
#ifndef MESSAGE_HPP
#define MESSAGE_HPP
#include <sstream>
#include "enderror.hpp"
#include "endwarning.hpp"
#include "endinformation.hpp"
#ifndef TEST_MESSAGE
/* Release mode */
#include "../interface/interface.hpp"
#else
/* Test mode */
#include <iostream>
class Interface{
public:
void error(const std::string& s){
std::cerr <<"ERROR: " << s << std::endl;
}
void warning(const std::string& s){
std::cerr <<"WARNING: " << s << std::endl;
}
void information(const std::string& s){
std::cerr <<"INFORMATION: " << s << std::endl;
}
};
#endif
/*!
*\brief This class provides a iostream like way to put message to terminal or to Qt, depending to the kind of interface.
*/
class Message{
protected:
/*!
* \brief Static variable which contains pointer to the message displaying interface.
*/
static Interface* _interface;
/*!
* \brief The default constructor in private scope. It prevents any instance creation.
*/
Message();
public:
/*!
* \brief This function defines the interface from which message should be displayed.
* \param i The instance of the right interface.
*/
static void set_interface_instance(Interface* i);
/*!
* \brief This function returns the interface from which message should be displayed.
* \return A pointer to an interface instance.
*/
static Interface* get_interface_instance();
};
#endif
/*!
*\file message_ns.cpp
*/
#include "message_ns.hpp"
namespace message_ns{
std::stringstream message;
Enderror ende;
Endwarning endw;
Endinformation endi;
/* the operator functions */
#define OP_FUNC(T, V) std::ostream& operator<<(std::ostream& stream, T &){ \
if (Message::get_interface_instance() != NULL){ \
Message::get_interface_instance()-> V (message.str()); \
message.str("");/* flush the stream */ \
}else{ \
std::cerr << "Warning : no interface designed to display messages." << std::endl; \
} \
return stream; \
}
OP_FUNC(Enderror, error)
OP_FUNC(Endwarning, warning)
OP_FUNC(Endinformation, information)
}
/*!
*\file message_ns.hpp
*/
#ifndef MESSAGE_NS_HPP
#define MESSAGE_NS_HPP
#include "message.hpp"
/*!
* \brief Namespace for error, warning and informative messages.
*/
namespace message_ns{
/*******************************
Declared inside message_ns.cpp
********************************/
/*!
* \brief Message variabel will contain messages which must be displayed.
*/
extern std::stringstream message;
/*!
* \brief Putting ende in message variable will triggered message display with the error flag.
*/
extern Enderror ende;
/*!
* \brief Putting endw in message variable will triggered message display with the warning flag.
*/
extern Endwarning endw;
/*!
* \brief Putting endi in message variable will triggered message display with the information flag.
*/
extern Endinformation endi;
/*******************************
The operator function declaration
********************************/
/*!
* \brief The macro OP_FUNC_DECL defines operator << for message displaying system.
*
* It will create as operator << functions as different kind of message classes. Operator takes a string stream (it can be strings with numbers and booleans) than trigger the display of this stream according to the second argument which decides what kind of message it is (for example : an error message or a warning message).
*/
#define OP_FUNC_DECL(T) std::ostream& operator<< (std::ostream& stream, T & e );
/*!
* \brief Defines operator<< function for error message class.
*/
OP_FUNC_DECL(Enderror)
/*!
* \brief Defines operator<< function for warning message class.
*/
OP_FUNC_DECL(Endwarning)
/*!
* \brief Defines operator<< function for informative message class.
*/
OP_FUNC_DECL(Endinformation)
}
#endif
#include "Errors.hpp"
using namespace std;
using namespace message_ns;
std::queue<std::string> Error::_errors;
std::queue<std::string> Error::_warnings;
......@@ -61,13 +60,13 @@ bool Error::set_if(bool condition, const string kind_of_error, const unsigned in
void Error::print(const int priority){
message << _content ;
*Message::get_instance() << _content;
switch(priority){
case _WARNING:
message << endw;
*Message::get_instance() << Message::endw;
break;
default: // Include the _ERROR
message << ende;
*Message::get_instance() << Message::ende;
break;
}
}
......@@ -82,15 +81,15 @@ bool Error::set_and_print_if(bool condition, const string kind_of_error, const u
void Error::print_numbers(){
message << Error::_errors.size() << " errors and " << Error::_warnings.size() << " warnings were found during parsing.";
*Message::get_instance() << Error::_errors.size() << " errors and " << Error::_warnings.size() << " warnings were found during parsing.";
if(Error::_warnings.size() == 0 && Error::_errors.size() == 0){
message << endi;
*Message::get_instance() << Message::endi;
}
else if(Error::_errors.size() == 0){
message << endw;