OpenLexocad  27.1
Transaction.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de> *
3  * Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
4  * *
5  * This file is part of the FreeCAD CAx development system. *
6  * *
7  * This library is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU Library General Public *
9  * License as published by the Free Software Foundation; either *
10  * version 2 of the License, or (at your option) any later version. *
11  * *
12  * This library is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU Library General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Library General Public *
18  * License along with this library; see the file COPYING.LIB. If not, *
19  * write to the Free Software Foundation, Inc., 59 Temple Place, *
20  * Suite 330, Boston, MA 02111-1307, USA *
21  * *
22  ***************************************************************************/
23 
24 
25 #pragma once
26 
27 #include <unordered_map>
28 #include <Base/Factory.h>
29 #include <Base/Persistence.h>
30 #include <Core/PropertyContainer.h>
31 #include <Core/DynamicProperty.h>
32 
33 
34 namespace Core
35 {
36 
37 class CoreDocument;
38 class Property;
39 class Transaction;
40 class TransactionObject;
41 class DocObject;
42 class TransactionP;
43 
46 class LX_CORE_EXPORT Transaction : public Base::Persistence
47 {
49 
50 public:
59  Transaction(int id = 0);
61  virtual ~Transaction();
62 
64  void apply(CoreDocument &Doc,bool forward);
65 
66  // the utf-8 name of the transaction
67  std::string Name;
68 
69  virtual void save(Base::AbstractWriter& /*writer*/, Base::PersistenceVersion& /*save_version*/);
71  virtual void restore(Base::AbstractXMLReader& /*reader*/, Base::PersistenceVersion& /*version*/);
72 
74  int getID(void) const;
75 
77  static int getNewID(void);
78  static int getLastID(void);
79 
81  bool isEmpty() const;
83  bool hasObject(const Core::DocObject *Obj) const;
84  void addOrRemoveProperty(Core::DocObject *Obj, const Property* pcProp, bool add);
85 
86  void addObjectNew(Core::DocObject *Obj);
87  void addObjectDel(const Core::DocObject *Obj);
88  void addObjectChange(const Core::DocObject *Obj, const Property *Prop);
89 
90 private:
91  int transID;
92  std::unique_ptr<TransactionP> mPimpl;
93 };
94 
97 class LX_CORE_EXPORT TransactionObject : public Base::Persistence
98 {
100 
101 public:
105  virtual ~TransactionObject();
106 
107  virtual void applyNew(CoreDocument &Doc, Core::DocObject *pcObj);
108  virtual void applyDel(CoreDocument &Doc, Core::DocObject *pcObj);
109  virtual void applyChn(CoreDocument &Doc, Core::DocObject *pcObj, bool Forward);
110 
111  void setProperty(const Property* pcProp);
112  void addOrRemoveProperty(const Property* pcProp, bool add);
113 
114  virtual void save(Base::AbstractWriter& /*writer*/, Base::PersistenceVersion& /*save_version*/);
116  virtual void restore(Base::AbstractXMLReader& /*reader*/, Base::PersistenceVersion& /*version*/);
117 
118  friend class Transaction;
119 
120 protected:
121  enum Status {New,Del,Chn} status;
122 
123 #ifndef SWIG
126  };
127  std::unordered_map<const Property*, PropData> _PropChangeMap;
128 #endif
129  std::string _NameInDocument;
130 };
131 
134 class LX_CORE_EXPORT TransactionDocumentObject : public TransactionObject
135 {
137 
138 public:
142  virtual ~TransactionDocumentObject();
143 
144  void applyNew(CoreDocument &Doc, Core::DocObject *pcObj);
145  void applyDel(CoreDocument &Doc, Core::DocObject *pcObj);
146 };
147 
148 class LX_CORE_EXPORT TransactionFactory
149 {
150 public:
151  static TransactionFactory& instance();
152  static void destruct ();
153 
154  TransactionObject* createTransaction (const Base::Type& type) const;
155  void addProducer (const Base::Type& type, Base::AbstractProducer *producer);
156 
157 private:
158  static TransactionFactory* self;
159  std::map<Base::Type, Base::AbstractProducer*> producers;
160 
162  ~TransactionFactory(){}
163 };
164 
165 template <class CLASS>
167 {
168 public:
170  {
172  }
173 
174  virtual ~TransactionProducer (){}
175 
179  virtual void* Produce () const
180  {
181  return (new CLASS);
182  }
183 };
184 
185 } //namespace Core
186 
187 
CoreDocument()
Abstract base class of all producers.
Definition: Factory.h:61
Definition: Persistence.h:14
Definition: Transaction.h:46
Definition: Transaction.h:148
std::string _NameInDocument
Definition: Transaction.h:129
Definition: Transaction.h:134
Persistence class and root of the type system.
Definition: Persistence.h:23
Definition: Type.h:52
Definition: CoreDocument.h:210
std::string Name
Definition: Transaction.h:67
Definition: DocObject.h:26
Base::Type propertyType
Definition: Transaction.h:125
Definition: DynamicProperty.h:139
Definition: AbstractXMLReader.h:7
Definition: Transaction.h:124
virtual ~TransactionProducer()
Definition: Transaction.h:174
static TransactionFactory & instance()
Definition: Base.h:12
void addProducer(const Base::Type &type, Base::AbstractProducer *producer)
Definition: Writer.h:16
Definition: Transaction.h:97
TransactionProducer(const Base::Type &type)
Definition: Transaction.h:169
Definition: Property.h:77
std::unordered_map< const Property *, PropData > _PropChangeMap
Definition: Transaction.h:127
TYPESYSTEM_HEADER()
Definition: DocObject.h:51
Status
Definition: Transaction.h:121
Definition: Transaction.h:166
virtual void * Produce() const
Definition: Transaction.h:179