Choreonoid  1.8
EditRecord.h
Go to the documentation of this file.
1 #ifndef CNOID_BASE_EDIT_RECORD_H
2 #define CNOID_BASE_EDIT_RECORD_H
3 
4 #include <cnoid/Referenced>
5 #include <vector>
6 #include <string>
7 #include "exportdecl.h"
8 
9 namespace cnoid {
10 
11 class CNOID_EXPORT EditRecord : public Referenced
12 {
13 public:
14  virtual EditRecord* clone() const = 0;
15  virtual std::string label() const = 0;
16 
17  bool applyUndo() { return !isReverse_ ? undo() : redo(); }
18  bool applyRedo() { return !isReverse_ ? redo() : undo(); }
19 
20  void flip(){ isReverse_ = !isReverse_; }
21  bool isReverse() const { return isReverse_; }
22  EditRecord* getFlipped() const;
23 
24 protected:
25  EditRecord();
26  EditRecord(const EditRecord& org);
27 
28  virtual bool undo() = 0;
29  virtual bool redo() = 0;
30 
31 private:
32  bool isReverse_;
33 };
34 
36 
37 
38 class CNOID_EXPORT EditRecordGroup : public EditRecord
39 {
40 public:
41  EditRecordGroup(const std::string& label);
42 
43  virtual EditRecord* clone() const override;
44  virtual std::string label() const override;
45 
46  void addRecord(EditRecord* record){
47  group_.push_back(record);
48  }
49  bool empty() const { return group_.empty(); }
50  int numRecords() const { return group_.size(); }
51  EditRecord* record(int index){ return group_[index]; }
52 
53  virtual bool undo() override;
54  virtual bool redo() override;
55 
56 protected:
57  EditRecordGroup(const EditRecordGroup& org);
58 
59 private:
60  std::vector<EditRecordPtr> group_;
61  std::string label_;
62 };
63 
65 
66 }
67 
68 #endif
cnoid::EditRecordGroup
Definition: EditRecord.h:38
cnoid::EditRecord::applyRedo
bool applyRedo()
Definition: EditRecord.h:18
cnoid::EditRecord
Definition: EditRecord.h:11
cnoid::EditRecordGroup::empty
bool empty() const
Definition: EditRecord.h:49
cnoid::EditRecordGroup::addRecord
void addRecord(EditRecord *record)
Definition: EditRecord.h:46
cnoid::EditRecord::isReverse
bool isReverse() const
Definition: EditRecord.h:21
cnoid::ref_ptr
Definition: Referenced.h:103
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::EditRecord::flip
void flip()
Definition: EditRecord.h:20
cnoid::Referenced
Definition: Referenced.h:54
cnoid::EditRecordPtr
ref_ptr< EditRecord > EditRecordPtr
Definition: EditRecord.h:35
cnoid::EditRecordGroupPtr
ref_ptr< EditRecordGroup > EditRecordGroupPtr
Definition: EditRecord.h:64
cnoid::EditRecordGroup::numRecords
int numRecords() const
Definition: EditRecord.h:50
cnoid::EditRecordGroup::record
EditRecord * record(int index)
Definition: EditRecord.h:51
cnoid::EditRecord::applyUndo
bool applyUndo()
Definition: EditRecord.h:17