| 
									
										
										
										
											2020-03-03 22:34:50 +01:00
										 |  |  | // 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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:35:02 +01:00
										 |  |  | class EventBase : public Base { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	EventBase(struct dive *d, int dcNr); | 
					
						
							| 
									
										
										
										
											2020-03-03 22:34:50 +01:00
										 |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							| 
									
										
										
										
											2020-03-04 17:35:02 +01:00
										 |  |  | 	virtual void redoit() = 0; | 
					
						
							|  |  |  | 	virtual void undoit() = 0; | 
					
						
							| 
									
										
										
										
											2020-03-03 22:34:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// 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; | 
					
						
							| 
									
										
										
										
											2020-03-05 23:10:44 +01:00
										 |  |  | private: | 
					
						
							|  |  |  | 	void updateDive(); | 
					
						
							| 
									
										
										
										
											2020-03-04 17:35:02 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							| 
									
										
										
										
											2020-03-03 22:34:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	OwningEventPtr eventToAdd;	// for redo
 | 
					
						
							|  |  |  | 	event *eventToRemove;		// for undo
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AddEventBookmark : public AddEventBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	AddEventBookmark(struct dive *d, int dcNr, int seconds); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-03 22:54:54 +01:00
										 |  |  | class AddEventDivemodeSwitch : public AddEventBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	AddEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-03 23:31:46 +01:00
										 |  |  | class AddEventSetpointChange : public AddEventBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 18:13:02 +01:00
										 |  |  | class RenameEvent : public EventBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	RenameEvent(struct dive *d, int dcNr, struct event *ev, const char *name); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | 	void undoit() override; | 
					
						
							|  |  |  | 	void redoit() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	OwningEventPtr eventToAdd;	// for undo and redo
 | 
					
						
							|  |  |  | 	event *eventToRemove;		// for undo and redo
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 18:25:47 +01:00
										 |  |  | class RemoveEvent : public EventBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	RemoveEvent(struct dive *d, int dcNr, struct event *ev); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | 	void undoit() override; | 
					
						
							|  |  |  | 	void redoit() override; | 
					
						
							| 
									
										
										
										
											2020-03-06 23:20:58 +01:00
										 |  |  | 	void post() const; // Called to fix up dives should a gas-change have happened.
 | 
					
						
							| 
									
										
										
										
											2020-03-04 18:25:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	OwningEventPtr eventToAdd;	// for undo
 | 
					
						
							|  |  |  | 	event *eventToRemove;		// for redo
 | 
					
						
							| 
									
										
										
										
											2020-03-06 23:20:58 +01:00
										 |  |  | 	int cylinder;			// affected cylinder (if removing gas switch). <0: not a gas switch.
 | 
					
						
							| 
									
										
										
										
											2020-03-04 18:25:47 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 21:10:05 +01:00
										 |  |  | class AddGasSwitch : public EventBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	AddGasSwitch(struct dive *d, int dcNr, int seconds, int tank); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | 	void undoit() override; | 
					
						
							|  |  |  | 	void redoit() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	std::vector<int> cylinders; // cylinders that are modified
 | 
					
						
							|  |  |  | 	std::vector<OwningEventPtr> eventsToAdd; | 
					
						
							|  |  |  | 	std::vector<event *> eventsToRemove; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-03 22:34:50 +01:00
										 |  |  | } // namespace Command
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // COMMAND_EVENT_H
 |