summaryrefslogtreecommitdiffhomepage
path: root/opentrack-logic/tracklogger.hpp
blob: feed7fa2975e1dd05b72b57ed7d8a6f562d899da (plain)
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
#pragma once
#include "main-settings.hpp"
#include "opentrack-compat/options.hpp"

#include <fstream>
#include <QString>
#include <QMessageBox>
#include <QWidget>

class OPENTRACK_LOGIC_EXPORT TrackLogger
{
public:
    TrackLogger()
    {
    }

    static mem<TrackLogger> make() { return std::make_shared<TrackLogger>(); }

    virtual void write(const char *)
    {
    }

    virtual void write(const double *, int n)
    {
    }

    virtual void next_line()
    {
    }

    void write_pose(const double *p)
    {
        write(p, 6);
    }
};


class OPENTRACK_LOGIC_EXPORT TrackLoggerCSV : public TrackLogger
{
    std::ofstream out;
    bool first_col;
public:
    TrackLoggerCSV(const QString &filename)  :  TrackLogger(),
        first_col(true)
    {
        out.open(filename.toStdString());
        if (!out.is_open())
            throw std::ios_base::failure("unable to open file");
    }

    static mem<TrackLogger> make(const main_settings &s) { return std::static_pointer_cast<TrackLogger>(std::make_shared<TrackLoggerCSV>(s.tracklogging_filename)); }

    virtual void write(const char *s);
    virtual void write(const double *p, int n);
    virtual void next_line();
};