Scribus
Open source desktop publishing at your fingertips
transaction.h
1 
2 /*
3  For general Scribus (>=1.3.2) copyright and licensing information please refer
4  to the COPYING file provided with the program. Following this notice may exist
5  a copyright and/or license notice that predates the release of Scribus 1.3.2
6  for which a new license (GPL+exception) is in place.
7  */
8 /***************************************************************************
9 * Copyright (C) 2008 by Andreas Vox *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 ***************************************************************************/
26 
27 #ifndef TRANSACTION_H
28 #define TRANSACTION_H
29 
30 #include "scribusapi.h"
31 
32 #include <QSharedData>
33 #include <QExplicitlySharedDataPointer>
34 
40 class SCRIBUS_API Transaction {
41 
42 public:
43  enum Status {
44  STATE_OPEN,
45  STATE_WILLFAIL,
46  STATE_FAILED,
47  STATE_COMMITTED
48  };
49 
50  class TransactionStateBase : public QSharedData
51  {
52  public:
53  virtual ~TransactionStateBase() {};
54 
55  Status m_status;
56  };
57 
58  Transaction(TransactionStateBase* data) : m_data(data)
59  {
60  if (data != 0)
61  m_data->m_status = STATE_OPEN;
62  }
63 
70  virtual ~Transaction() {};
71 
75  operator bool() const { return (m_data.constData() != 0); }
76 
82  virtual bool commit() = 0;
83 
88  virtual bool cancel() = 0;
89 
93  virtual void markFailed();
94 
98  virtual void reset();
99 
100  int getState() const;
101 
102  bool isNull() const { return (m_data.constData() == 0); }
103 
104  bool isStarted() const { return (m_data.constData() != 0); }
105 
106  bool isOpened() const;
107 
108 protected:
109  // if you subclass, do *not* add any data members but use this pointer instead,
110  // otherwise the copy initializer will strip your objects.
111  QExplicitlySharedDataPointer<TransactionStateBase> m_data;
112 };
113 
114 #endif
virtual ~Transaction()
Definition: transaction.h:70
Definition: transaction.h:40
Definition: transaction.h:50