-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathOutput.h
77 lines (62 loc) · 1.79 KB
/
Output.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************
* Output.h
* KPS
*
* Author: Kareem Omar
* kareem.omar@uah.edu
* https://github.com/komrad36
*
* Last updated Feb 27, 2016
* This application is entirely my own work.
*******************************************************************/
//
// Realtime or cached, ASCII or binary output of satellite
// parameters to several files, one for each parameter.
//
#pragma once
#include <fstream>
#include <iostream>
#include "Earth.h"
#include "Satellite.h"
// pure virtual base class to allow branchless selection
// of binary or ASCII output
class Output {
protected:
bool realtime;
static const int NUM_OUTFILES = 10;
static const std::string OUT_PREFIXES[NUM_OUTFILES];
static const std::string LOCK_FILE_NAME;
std::ofstream out[NUM_OUTFILES];
bool initialized;
bool checkForExistingInstance();
std::ofstream lock_file;
public:
virtual void write(const double t, const Satellite& sat) = 0;
virtual bool init() = 0;
Output(bool realtime_output) : realtime(realtime_output), initialized(false) {}
virtual ~Output() = 0;
};
class ASCIIOutput : public Output {
private:
std::string OUT_NAMES[NUM_OUTFILES];
public:
ASCIIOutput(bool realtime_output) : Output(realtime_output) {
for (int i = 0; i < NUM_OUTFILES; ++i) {
OUT_NAMES[i] = OUT_PREFIXES[i] + ".csv";
}
}
bool init();
void write(const double t, const Satellite& sat);
};
class BinaryOutput : public Output {
private:
std::string OUT_NAMES[NUM_OUTFILES];
public:
BinaryOutput(bool realtime_output) : Output(realtime_output) {
for (int i = 0; i < NUM_OUTFILES; ++i) {
OUT_NAMES[i] = OUT_PREFIXES[i] + ".bin";
}
}
bool init();
void write(const double t, const Satellite& sat);
};