buffer_obs_queue.cpp 3.78 KB
Newer Older
Achim Morschhauser's avatar
Achim Morschhauser committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/********************************************************************************
 * 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.				*
 *										*
 ********************************************************************************/

// C++ Headers
#include <queue> // Standard I/O
#include <iostream>

// Custom C++ Headers
#include <buffer_obs_queue.hpp> // Buffer using C++ queue
#include <data_obs_vector.hpp>
#include <data_obs_scalar.hpp>

/********************************************************************************
 *********************************************************************************
 *										*
 * 				Constructors.					*
 *										*
 *********************************************************************************
 ********************************************************************************/
buffer_obs_queue::buffer_obs_queue() {


}

/********************************************************************************
 *********************************************************************************
 *										*
 * 			      Public Methods.					*
 *										*
 *********************************************************************************
 ********************************************************************************/

/********************************************************************************
 *									 	*
 * Add data of type data_obs to the buffer. This is done by converting the	*
 * data to its string representation and writing to Standard Output.		*
 *										*
 ********************************************************************************/
int buffer_obs_queue::put(data_obs* data) {

	if (dynamic_cast <data_obs_vector*> (data)){
		queue.push(new data_obs_vector((data_obs_vector*) data));
	} else if (dynamic_cast <data_obs_scalar*> ((data_obs_scalar*) data)){
		//queue.push(new data_obs_scalar(data));
	} else {
		queue.push(new data_obs(data));
	}

	std::string string;

	data->string(&string,5);

61
	std::cerr << "PUT_QUEUE: " << string << std::endl;
Achim Morschhauser's avatar
Achim Morschhauser committed
62
63
64
65
66
67
68
69
70
71
72
73
74

	return(0);

}

/********************************************************************************
 *									 	*
 * Read data from the buffer. This is done by reading from Standard Input and	*
 * parsing the string.								*
 *										*
 ********************************************************************************/
int buffer_obs_queue::pop(data_obs* data) {

75
	std::cerr << "POP1: " << data << " " << queue.size() << std::endl;
Achim Morschhauser's avatar
Achim Morschhauser committed
76
77
78
79
80
81
82
83
84
85
86

	//data_obs* get;

	while (1){

		if (queue.size()>0){

			*data=queue.front();

			//*data=*get;

87
			std::cerr << "POP2: " << data << std::endl;
Achim Morschhauser's avatar
Achim Morschhauser committed
88
89
90
91
92
93
94

			queue.pop();

			std::string string;

			data->string(&string,5);

95
			std::cerr << "POP_QUEUE: " << string << std::endl;
Achim Morschhauser's avatar
Achim Morschhauser committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

			return(0);

		}

	}

}

data_obs buffer_obs_queue::pop(){

	data_obs data;

	data=*queue.front();

	queue.pop();

	return(data);

}

/********************************************************************************
 *********************************************************************************
 *										*
 * 			      Private Methods.					*
 *										*
 *********************************************************************************
 ********************************************************************************/

/********************************************************************************
 *										*
 * Method dummy for initialization: No initialization is needed.		 	*
 *										*
 ********************************************************************************/
int buffer_obs_queue::init() {

	return(0);

}