// Created on: 2004-05-18
// Created by: Sergey ZARITCHNY
-// Copyright (c) 2004-2012 OPEN CASCADE SAS
+// Copyright (c) 2004-2014 OPEN CASCADE SAS
//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
-#include <BinTools.ixx>
+#include <BinTools.hxx>
+#include <BinTools_ShapeSet.hxx>
#include <FSD_FileHeader.hxx>
+#include <OSD_OpenFile.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
//=======================================================================
//function : PutBool
//purpose :
//=======================================================================
-
Standard_OStream& BinTools::PutBool(Standard_OStream& OS, const Standard_Boolean aValue)
{
- OS.put((Standard_Byte)aValue);
+ OS.put((Standard_Byte)(aValue ? 1 : 0));
return OS;
}
Standard_IStream& BinTools::GetReal(Standard_IStream& IS, Standard_Real& aValue)
{
if(!IS.read ((char*)&aValue, sizeof(Standard_Real)))
- Storage_StreamTypeMismatchError::Raise();
+ throw Storage_StreamTypeMismatchError();
#if DO_INVERSE
aValue = InverseReal (aValue);
#endif
Standard_IStream& BinTools::GetInteger(Standard_IStream& IS, Standard_Integer& aValue)
{
if(!IS.read ((char*)&aValue, sizeof(Standard_Integer)))
- Storage_StreamTypeMismatchError::Raise();;
+ throw Storage_StreamTypeMismatchError();;
#if DO_INVERSE
aValue = InverseInt (aValue);
#endif
Standard_IStream& BinTools::GetExtChar(Standard_IStream& IS, Standard_ExtCharacter& theValue)
{
if(!IS.read ((char*)&theValue, sizeof(Standard_ExtCharacter)))
- Storage_StreamTypeMismatchError::Raise();;
+ throw Storage_StreamTypeMismatchError();;
#if DO_INVERSE
theValue = InverseExtChar (theValue);
#endif
Standard_IStream& BinTools::GetBool(Standard_IStream& IS, Standard_Boolean& aValue)
{
- aValue = (Standard_Boolean)IS.get();
+ aValue = (IS.get() != 0);
return IS;
}
+
+//=======================================================================
+//function : Write
+//purpose :
+//=======================================================================
+
+void BinTools::Write (const TopoDS_Shape& theShape, Standard_OStream& theStream)
+{
+ BinTools_ShapeSet aShapeSet(Standard_True);
+ aShapeSet.SetFormatNb (3);
+ aShapeSet.Add (theShape);
+ aShapeSet.Write (theStream);
+ aShapeSet.Write (theShape, theStream);
+}
+
+//=======================================================================
+//function : Read
+//purpose :
+//=======================================================================
+
+void BinTools::Read (TopoDS_Shape& theShape, Standard_IStream& theStream)
+{
+ BinTools_ShapeSet aShapeSet(Standard_True);
+ aShapeSet.Read (theStream);
+ aShapeSet.Read (theShape, theStream, aShapeSet.NbShapes());
+}
+
+//=======================================================================
+//function : Write
+//purpose :
+//=======================================================================
+
+Standard_Boolean BinTools::Write (const TopoDS_Shape& theShape, const Standard_CString theFile)
+{
+ ofstream aStream;
+ aStream.precision (15);
+ OSD_OpenStream (aStream, theFile, ios::out | ios::binary);
+ if (!aStream.good())
+ return Standard_False;
+
+ Write (theShape, aStream);
+ aStream.close();
+ return aStream.good();
+}
+
+//=======================================================================
+//function : Read
+//purpose :
+//=======================================================================
+
+Standard_Boolean BinTools::Read (TopoDS_Shape& theShape, const Standard_CString theFile)
+{
+ filebuf aBuf;
+ OSD_OpenStream (aBuf, theFile, ios::in | ios::binary);
+ if (!aBuf.is_open())
+ return Standard_False;
+
+ Standard_IStream aStream (&aBuf);
+ Read (theShape, aStream);
+ return aStream.good();
+}