0030895: Coding Rules - specify std namespace explicitly for std::cout and streams
[occt.git] / src / TDF / TDF_Transaction.cxx
CommitLineData
b311480e 1// Created by: DAUTRY Philippe
2// Copyright (c) 1997-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// -------------------
7fd59977 17// Version: 0.0
b311480e 18//Version Date Purpose
7fd59977 19// 0.0 Oct 1 1997 Creation
20
42cf5bc1 21#include <Standard_DomainError.hxx>
22#include <Standard_NullObject.hxx>
23#include <TCollection_AsciiString.hxx>
24#include <TDF_Data.hxx>
25#include <TDF_Delta.hxx>
26#include <TDF_Transaction.hxx>
7fd59977 27
28#undef DEB_TRANSACTION
0797d9d3 29#ifdef OCCT_DEBUG
7fd59977 30#define DEB_TRANSACTION
31#endif
32#undef DEB_TRANSACTION_DUMP
33
34#include <TDF_Tool.hxx>
35
36//=======================================================================
37//function : TDF_Transaction
38//purpose :
39//=======================================================================
40
41TDF_Transaction::TDF_Transaction
42(const TCollection_AsciiString& aName)
43: myUntilTransaction(0),
44 myName(aName)
45{}
46
47
48//=======================================================================
49//function : TDF_Transaction
50//purpose : Private copy constructor.
51//=======================================================================
52
35e08fe8 53TDF_Transaction::TDF_Transaction(const TDF_Transaction& /*aTrans*/)
7fd59977 54{}
55
56
57//=======================================================================
58//function : TDF_Transaction
59//purpose :
60//=======================================================================
61
62TDF_Transaction::TDF_Transaction
63(const Handle(TDF_Data)& aDF,
64 const TCollection_AsciiString& aName)
65: myDF(aDF),
66 myUntilTransaction(0),
67 myName(aName)
68{}
69
70
71
72
73//=======================================================================
74//function : Initialize
75//purpose : Initializes a transaction ready to be opened.
76//=======================================================================
77
78void TDF_Transaction::Initialize(const Handle(TDF_Data)& aDF)
79{
80 if (IsOpen()) myDF->AbortUntilTransaction(myUntilTransaction);
81 myDF = aDF;
82 myUntilTransaction = 0;
83}
84
85
86//=======================================================================
87//function : Open
88//purpose :
89//=======================================================================
90
91Standard_Integer TDF_Transaction::Open()
92{
0797d9d3 93#ifdef OCCT_DEBUG_TRANSACTION
04232180 94 std::cout<<"Transaction "<<myName<<" opens #"<<myDF->Transaction()+1<<std::endl;
7fd59977 95#endif
96 if (IsOpen())
9775fa61 97 throw Standard_DomainError("This transaction is already open.");
7fd59977 98 if (myDF.IsNull())
9775fa61 99 throw Standard_NullObject("Null TDF_Data.");
7fd59977 100 return myUntilTransaction = myDF->OpenTransaction();
101}
102
103
104//=======================================================================
105//function : Commit
106//purpose :
107//=======================================================================
108
109Handle(TDF_Delta) TDF_Transaction::Commit(const Standard_Boolean withDelta)
110{
0797d9d3 111#ifdef OCCT_DEBUG_TRANSACTION
04232180 112 std::cout<<"Transaction "<<myName<<" commits ";
7fd59977 113#endif
114 Handle(TDF_Delta) delta;
115 if (IsOpen()) {
0797d9d3 116#ifdef OCCT_DEBUG_TRANSACTION
04232180 117 std::cout<<"from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<std::endl;
7fd59977 118#endif
0797d9d3 119#ifdef OCCT_DEBUG_TRANSACTION_DUMP
04232180 120 std::cout<<"DF before commit"<<std::endl;
121 TDF_Tool::DeepDump(std::cout,myDF);
7fd59977 122#endif
123 Standard_Integer until = myUntilTransaction;
124 myUntilTransaction = 0;
125 delta = myDF->CommitUntilTransaction(until, withDelta);
0797d9d3 126#ifdef OCCT_DEBUG_TRANSACTION_DUMP
04232180 127 std::cout<<"DF after commit"<<std::endl;
128 TDF_Tool::DeepDump(std::cout,myDF);
7fd59977 129#endif
130 }
0797d9d3 131#ifdef OCCT_DEBUG_TRANSACTION
04232180 132 else std::cout<<"but this transaction is not open!"<<std::endl;
7fd59977 133#endif
134 return delta;
135}
136
137
138//=======================================================================
139//function : Abort
140//purpose : alias ~
141//=======================================================================
142
143void TDF_Transaction::Abort()
144{
145 if (IsOpen()) {
0797d9d3 146#ifdef OCCT_DEBUG_TRANSACTION
04232180 147 std::cout<<"Transaction "<<myName<<" aborts from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<std::endl;
7fd59977 148#endif
0797d9d3 149#ifdef OCCT_DEBUG_TRANSACTION_DUMP
04232180 150 std::cout<<"DF before abort"<<std::endl;
151 TDF_Tool::DeepDump(std::cout,myDF);
7fd59977 152#endif
153 myDF->AbortUntilTransaction(myUntilTransaction);
154 myUntilTransaction = 0;
0797d9d3 155#ifdef OCCT_DEBUG_TRANSACTION_DUMP
04232180 156 std::cout<<"DF after abort"<<std::endl;
157 TDF_Tool::DeepDump(std::cout,myDF);
7fd59977 158#endif
159 }
160}
161