Commit c54923a0 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Buffer combining multiple buffers

parent 7c1ec9b8
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, April 2016 *
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses standard input and *
* output. It can be used in combination with the SHELL pipe operator (|). *
* This class allows to combine different types of buffers and split output.
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_pipe_H
#define _BUFFER_OBS_pipe_H
#ifndef _BUFFER_OBS_mult_H
#define _BUFFER_OBS_mult_H
// Package headers
#include <buffer_obs.hpp>
#include <data_obs.hpp>
class buffer_obs_pipe : public buffer_obs
// C++ headers
#include <vector>
class buffer_obs_mult : public buffer_obs
{
//
......@@ -23,9 +26,8 @@ class buffer_obs_pipe : public buffer_obs
private:
// Precision
int precision;
// Vector of buffers
std::vector <buffer_obs*> buffers;
//
// Constructors
......@@ -33,7 +35,7 @@ int precision;
public:
buffer_obs_pipe(int precision=2);
buffer_obs_mult(buffer_obs* buffer);
//
// Public Methods
......@@ -46,6 +48,9 @@ public: int pop(data_obs* data);
/** Get last element and delete */
public: data_obs pop();
/** Add a buffer */
public: int add(buffer_obs* buffer);
//
// Private Methods
//
......@@ -55,4 +60,4 @@ private: int init();
};
#endif /* _BUFFER_OBS_pipe_H */
#endif /* _BUFFER_OBS_mult_H */
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, April 2016 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses standard input and *
* output. It can be used in combination with the SHELL pipe operator (|). *
* *
/*******************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, April 2016 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses standard input *
* and output. It can be used in combination with the SHELL pipe operator (|). *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
......@@ -13,7 +13,8 @@
#include <iostream> // Standard I/O
// Custom C++ Headers
#include <buffer_obs_pipe.hpp> // Buffer using Standard I/O and the SHELL Pipe
#include <buffer_obs_mult.hpp>
#include <buffer_obs.hpp>
/********************************************************************************
*********************************************************************************
......@@ -22,10 +23,10 @@
* *
*********************************************************************************
********************************************************************************/
buffer_obs_pipe::buffer_obs_pipe(int precision) {
this-> precision=precision;
buffer_obs_mult::buffer_obs_mult(buffer_obs* buffer) {
buffers.push_back(buffer);
}
/********************************************************************************
......@@ -42,15 +43,13 @@ buffer_obs_pipe::buffer_obs_pipe(int precision) {
* data to its string representation and writing to Standard Output. *
* *
********************************************************************************/
int buffer_obs_pipe::put(data_obs* data) {
std::string datastr;
int buffer_obs_mult::put(data_obs* data) {
data->string(&datastr,precision);
std::cout << datastr << std::endl;
return(0);
for (int i=0; i<buffers.size(); i++){
buffers.at(i)->put(data);
}
return(0);
}
......@@ -60,33 +59,30 @@ int buffer_obs_pipe::put(data_obs* data) {
* parsing the string. *
* *
********************************************************************************/
int buffer_obs_pipe::pop(data_obs* data) {
std::string input;
std::getline (std::cin,input);
/*std::cout << "STDIN: "
<< input
<< std::endl;
*/
data->parse(&input);
return(0);
int buffer_obs_mult::pop(data_obs* data) {
buffers.at(0)->pop(data);
return(0);
}
data_obs buffer_obs_pipe::pop(){
data_obs buffer_obs_mult::pop(){
data_obs data;
pop(&data);
return(data);
}
int buffer_obs_mult::add(buffer_obs* buffer) {
buffers.push_back(buffer);
return(0);
}
/********************************************************************************
*********************************************************************************
* *
......@@ -100,7 +96,7 @@ data_obs buffer_obs_pipe::pop(){
* Method dummy for initialization: No initialization is needed. *
* *
********************************************************************************/
int buffer_obs_pipe::init() {
int buffer_obs_mult::init() {
return(0);
......
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