Subversion Repositories Scribus

Rev

Rev 11614 | Rev 19416 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11576 avox 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.,                                       *
18122 mrdocs 24
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
11576 avox 25
***************************************************************************/
26
 
27
#ifndef TRANSACTION_H
28
#define TRANSACTION_H
29
 
30
#include "scribusapi.h"
31
 
32
 
33
/**
34
  Interface class for objects representing a going transaction.
35
  Will be specialized by classes like Undomanager for use as
36
  a result type in their beginTransaction() method.
37
*/
38
class SCRIBUS_API Transaction {
39
 
40
public:
41
        enum Status {
42
                STATE_OPEN,
43
                STATE_WILLFAIL,
44
                STATE_FAILED,
45
                STATE_COMMITTED
46
        };
47
 
48
        struct TransactionStateBase {
49
                Status m_status;
50
        };
51
 
52
        Transaction(TransactionStateBase* data) : m_data(data)
53
        {
11614 fschmid 54
                if (data != 0)
55
                        m_data->m_status = STATE_OPEN;
11576 avox 56
        }
57
 
58
        Transaction(const Transaction& other) : m_data(other.m_data)
59
        {
60
                const_cast<Transaction&>(other).m_data = 0;  // mean, but necessary so that not both destructors commit/close
61
        }
62
 
63
 
64
        /**
65
                Automatically commits if forgotten.
66
                Override as appropiate. Since the superclass destructor is called last, you
67
            can cancel in the subclass destructor; the commit here then will do nothing.
68
            Don't forget to set m_data to NULL if you free the m_data pointer!
69
         */
70
        virtual ~Transaction();
71
 
72
        /**
73
          Commits this transaction if in STATE_OPEN.
74
          If in STATE_WILLFAIL, cancel the transaction instead; otherwise do nothing.
75
          Returns true iff the transaction was committed or canceled.
76
         */
77
        virtual bool commit() = 0;
78
 
79
        /**
80
                Cancels this transaction if in STATE_OPEN or STATE_WILLFAIL; otherwise do nothing
81
            Returns true iff the transaction was canceled.
82
         */
83
        virtual bool cancel() = 0;
84
 
85
        /**
86
                Marks this transaction as failed.
87
         */
88
        virtual void markFailed();
89
 
90
        int getState() const;
91
 
92
protected:
93
        // if you subclass, do *not* add any data members but use this pointer instead,
94
        // otherwise the copy initializer will strip your objects.
95
        TransactionStateBase*    m_data;
96
 
97
private:
98
        // blocked
99
        Transaction& operator= (const Transaction&) { return *this; }
100
};
101
 
11577 mrdocs 102
#endif