Commit 95284637 authored by Olivier Lagrasse's avatar Olivier Lagrasse
Browse files

Realisation messages ok

parent b22ce8f8
CXX=g++
CXXFLAGS = -Wall -g
BIN_DIR = ../bin/
OBJECT_FILE = error.o message.o end.o
OBJECT_FILE = enderror.o endwarning.o endinformation.o message.o message_ns.o
all : $(OBJECT_FILE)
......
/*!
*\file end.cpp
*\brief This is the end message C source code.
*/
#include "end.hpp"
End::End(){
}
/*!
*\file enderror.cpp
*\brief This is the end error message C source code.
*/
#include "enderror.hpp"
Enderror::Enderror(){
}
/*!
*\file end.hpp
*\file enderror.hpp
*/
#ifndef END_HPP
#define END_HPP
#ifndef ENDERROR_HPP
#define ENDERROR_HPP
#include <sstream>
class End : public std::stringstream{
struct Enderror{
public:
/*!
* \brief The default constructor.
*/
End();
Enderror();
};
......
/*!
*\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
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
struct Endwarning{
/*!
* \brief The default constructor.
*/
Endwarning();
};
#endif
/*!
*\file error.cpp
*\brief This is the error message C source code.
*/
#include "error.hpp"
using namespace std;
Error::Error(){
}
const Error& Error::operator<<(const End&){
if (Message::get_interface_instance() != NULL){
Message::get_interface_instance()->error(this->str());
this->str().clear();
}
return *this;
}
/*!
*\file error.hpp
*/
#ifndef ERROR_HPP
#define ERROR_HPP
#include <sstream>
#include <cstdlib>
#include <iostream>
#include "message.hpp"
#include "end.hpp"
class Error : public std::stringstream{
public:
/*!
* \brief The default constructor.
*/
Error();
/*!
* \brief This defines the << operator for error messages.
*/
const Error& operator<<(const End&);
};
#endif
......@@ -8,6 +8,9 @@
#include <sstream>
#include "enderror.hpp"
#include "endwarning.hpp"
#include "endinformation.hpp"
......@@ -23,7 +26,13 @@ class Interface{
public:
void error(const std::string& s){
std::cerr <<"[[[ " << s << " ]]]" << std::endl;
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;
}
};
......@@ -34,23 +43,24 @@ public:
/*!
*\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:
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:
public:
/*!
* \brief This function defines the interface from which message should be displayed.
......@@ -65,7 +75,6 @@ public:
static Interface* get_interface_instance();
};
#endif
/*!
*\file message_ns.cpp
*/
#include "message_ns.hpp"
namespace message_ns{
std::stringstream message;
/* the operator functions */
#define OP_FUNC(T, V) std::ostream& operator<<(std::ostream& stream, T & e ){ \
if (Message::get_interface_instance() != NULL){ \
Message::get_interface_instance()-> V (message.str()); \
message.str("");/* flush the stream */ \
}/* end if */ \
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{
extern std::stringstream message;/* declared inside message_ns.cpp */
/* the operator function declaration */
#define OP_FUNC_DECL(T) std::ostream& operator<< (std::ostream& stream, T & e );
OP_FUNC_DECL(Enderror)
OP_FUNC_DECL(Endwarning)
OP_FUNC_DECL(Endinformation)
}
#endif
......@@ -2,11 +2,11 @@ CXX=g++
CXXFLAGS = -Wall -g
BIN_DIR = ../bin/
SRC_DIR = ../src/
OBJECT_FILE_BIN = $(BIN_DIR)message.o $(BIN_DIR)end.o $(BIN_DIR)error.o
OBJECT_FILE = error.o message.o end.o
OBJECT_FILE_BIN = $(BIN_DIR)enderror.o $(BIN_DIR)endwarning.o $(BIN_DIR)endinformation.o $(BIN_DIR)message.o $(BIN_DIR)message_ns.o
OBJECT_FILE = enderror.o endwarning.o endinformation.o message.o message_ns.o
TEST_FLAGS = -DTEST_MESSAGE
all : make_src test_error
all : make_src test_enderror test_endwarning test_endinformation
@echo " "
@echo "Message files compiled successfully ! (test)"
@echo " "
......
......@@ -2,35 +2,32 @@
* \brief Test error message
*/
#include <cstdlib>
#include "../src/message_ns.hpp"
#include "../src/error.hpp"
Error error;
End end;
using namespace std;
Interface i;
using namespace std;
using namespace message_ns;
int main(int argc, char** argv){
Enderror ende;
Message::set_interface_instance(&i);
message << "ttt" << 45<<ende;
message << ende;
error << "Test:" << 23 << " -";
error << end;
error << end;
return EXIT_SUCCESS;
}
......
/*!
* \brief Test error message
*/
#include <cstdlib>
#include "../src/message_ns.hpp"
using namespace std;
Interface i;
using namespace message_ns;
int main(int argc, char** argv){
Enderror ende;
Message::set_interface_instance(&i);
message << "ttt" << 45<<ende;
message << ende;
return EXIT_SUCCESS;
}
/*!
* \brief Test error message
*/
#include <cstdlib>
#include "../src/message_ns.hpp"
using namespace std;
Interface i;
using namespace message_ns;
int main(int argc, char** argv){
Endwarning endw;
Message::set_interface_instance(&i);
message << "ttt" << 45<<endw;
message << endw;
return EXIT_SUCCESS;
}
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