0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / StdObjMgt / StdObjMgt_WriteData.cxx
CommitLineData
ec964372 1// Copyright (c) 2017 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <StdObjMgt_WriteData.hxx>
15#include <StdObjMgt_Persistent.hxx>
16
17#include <Standard_GUID.hxx>
18
19
39c8dc70 20StdObjMgt_WriteData::StdObjMgt_WriteData (const Handle(Storage_BaseDriver)& theDriver)
21 : myDriver (theDriver)
ec964372 22{
23}
24
25void StdObjMgt_WriteData::WritePersistentObject (const Handle(StdObjMgt_Persistent)& thePersistent)
26{
27 if (thePersistent)
28 {
29 myDriver->WritePersistentObjectHeader(thePersistent->RefNum(), thePersistent->TypeNum());
30 myDriver->BeginWritePersistentObjectData();
31 thePersistent->Write(*this);
32 myDriver->EndWritePersistentObjectData();
33 }
34}
35
36StdObjMgt_WriteData& StdObjMgt_WriteData::operator << (const Handle(StdObjMgt_Persistent)& thePersistent)
37{
fcca9d7c 38 myDriver->PutReference(thePersistent ? thePersistent->RefNum() : 0);
ec964372 39 return *this;
40}
41
42//=======================================================================
43//function : operator >>
44//purpose : Read persistent data from a file
45//=======================================================================
46StdObjMgt_WriteData& operator <<
472433e2 47 (StdObjMgt_WriteData& theWriteData, const Standard_GUID& theGUID)
ec964372 48{
472433e2 49 StdObjMgt_WriteData::ObjectSentry aSentry (theWriteData);
50
ec964372 51 const Standard_UUID anUUID = theGUID.ToUUID();
52
53 Standard_Integer a32b;
54 Standard_ExtCharacter a16b[3];
55 Standard_Character a8b [6];
56
57 // see Standard_GUID::Standard_GUID(const Standard_UUID& aWntGuid)
58 a32b = anUUID.Data1;
59 a16b[0] = anUUID.Data2;
60 a16b[1] = anUUID.Data3;
61 a16b[2] = (anUUID.Data4[0] << 8) | (anUUID.Data4[1]);
62 a8b[0] = anUUID.Data4[2];
63 a8b[1] = anUUID.Data4[3];
64 a8b[2] = anUUID.Data4[4];
65 a8b[3] = anUUID.Data4[5];
66 a8b[4] = anUUID.Data4[6];
67 a8b[5] = anUUID.Data4[7];
68
69 theWriteData << a32b << a16b[0] << a16b[1] << a16b[2];
70 theWriteData << a8b[0] << a8b[1] << a8b[2] << a8b[3] << a8b[4] << a8b[5];
71
72 return theWriteData;
73}