summaryrefslogtreecommitdiffstats
path: root/commands/command_event.h
blob: a674e258ba1fb4a0b549703a9af441c48658aad2 (plain) (blame)
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
// SPDX-License-Identifier: GPL-2.0
// Note: this header file is used by the undo-machinery and should not be included elsewhere.

#ifndef COMMAND_EVENT_H
#define COMMAND_EVENT_H

#include "command_base.h"


// We put everything in a namespace, so that we can shorten names without polluting the global namespace
namespace Command {

// Events are a strange thing: they contain there own description which means
// that on changing the description a new object must be allocated. Moreover,
// it means that these objects can't be collected in a table.
// Therefore, the undo commands work on events as they do with dives: using
// owning pointers. See comments in command_base.h

class EventBase : public Base {
protected:
	EventBase(struct dive *d, int dcNr);
	void undo() override;
	void redo() override;
	virtual void redoit() = 0;
	virtual void undoit() = 0;

	// Note: we store dive and the divecomputer-number instead of a pointer to the divecomputer.
	// Since one divecomputer is integrated into the dive structure, pointers to divecomputers
	// are probably not stable.
	struct dive *d;
	int dcNr;
};

class AddEventBase : public EventBase {
public:
	AddEventBase(struct dive *d, int dcNr, struct event *ev); // Takes ownership of event!
private:
	bool workToBeDone() override;
	void undoit() override;
	void redoit() override;

	OwningEventPtr eventToAdd;	// for redo
	event *eventToRemove;		// for undo
};

class AddEventBookmark : public AddEventBase {
public:
	AddEventBookmark(struct dive *d, int dcNr, int seconds);
};

class AddEventDivemodeSwitch : public AddEventBase {
public:
	AddEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode);
};

class AddEventSetpointChange : public AddEventBase {
public:
	AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2);
};

} // namespace Command

#endif // COMMAND_EVENT_H