[Positioning] Add OutputMedium & OutputTerminal
OutputMedium is the super-class of all output media. OutputTerminal prints a Result on the terminal (or on any stream).
This commit is contained in:
parent
7c8038edc2
commit
7088e524d4
|
@ -55,13 +55,17 @@ OBJ_LIST = \
|
|||
realposition.o \
|
||||
configuration.o \
|
||||
userinterface.o \
|
||||
outputterminal.o \
|
||||
input.o \
|
||||
inputcsv.o \
|
||||
inputlogcsv.o
|
||||
OBJ_NOTEST_LIST = \
|
||||
posexcept.o \
|
||||
inputmedium.o
|
||||
INTERFACES_LIST = inputlogmedium.hh positioningalgorithm.hh
|
||||
INTERFACES_LIST = \
|
||||
inputlogmedium.hh \
|
||||
outputmedium.hh \
|
||||
positioningalgorithm.hh
|
||||
|
||||
OBJ = $(OBJ_LIST:%=$(OBJ_DIR)/%)
|
||||
OBJ_NOTEST = $(OBJ_NOTEST_LIST:%=$(OBJ_DIR)/%)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef _OWLPS_POSITIONING_OUTPUTMEDIUM_HH_
|
||||
#define _OWLPS_POSITIONING_OUTPUTMEDIUM_HH_
|
||||
|
||||
#include "result.hh"
|
||||
|
||||
/// Super class of all output media
|
||||
/**
|
||||
* Provide interface for output media, i.e. to write Results computed
|
||||
* by a PositioningAlgorithm.
|
||||
*/
|
||||
class OutputMedium
|
||||
{
|
||||
public:
|
||||
OutputMedium(void) {}
|
||||
|
||||
virtual ~OutputMedium(void) {}
|
||||
|
||||
/** @name Operations */
|
||||
//@{
|
||||
virtual void write(const Result &result) = 0 ;
|
||||
//@} // End Operations
|
||||
} ;
|
||||
|
||||
#endif // _OWLPS_POSITIONING_OUTPUTMEDIUM_HH_
|
|
@ -0,0 +1,8 @@
|
|||
#include "outputterminal.hh"
|
||||
|
||||
|
||||
|
||||
void OutputTerminal::write(const Result &result)
|
||||
{
|
||||
output_stream << result << '\n' ;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef _OWLPS_POSITIONING_OUTPUTTERMINAL_HH_
|
||||
#define _OWLPS_POSITIONING_OUTPUTTERMINAL_HH_
|
||||
|
||||
#include "outputmedium.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/// Writes a result to a stream (defaults to the standard output)
|
||||
class OutputTerminal: public OutputMedium
|
||||
{
|
||||
protected:
|
||||
std::ostream &output_stream ;
|
||||
|
||||
public:
|
||||
OutputTerminal(std::ostream &_output_stream = std::cout):
|
||||
output_stream(_output_stream) {}
|
||||
|
||||
void write(const Result &result) ;
|
||||
} ;
|
||||
|
||||
#endif // _OWLPS_POSITIONING_OUTPUTTERMINAL_HH_
|
|
@ -0,0 +1,28 @@
|
|||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "outputterminal.hh"
|
||||
#include "result.hh"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class OutputTerminal_test: public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
|
||||
void test_output(void)
|
||||
{
|
||||
std::ostringstream output_stream ;
|
||||
OutputTerminal output(output_stream) ;
|
||||
Result result ;
|
||||
|
||||
TS_ASSERT(output_stream.str().empty()) ;
|
||||
output.write(result) ;
|
||||
|
||||
TS_ASSERT(! output_stream.str().empty()) ;
|
||||
|
||||
std::ostringstream result_stream ;
|
||||
result_stream << result << '\n' ;
|
||||
TS_ASSERT_EQUALS(output_stream.str(), result_stream.str()) ;
|
||||
}
|
||||
|
||||
} ;
|
Loading…
Reference in New Issue