1 // Copyright (c) 2016 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Standard_ArrayStreamBuffer_HeaderFile
15 #define _Standard_ArrayStreamBuffer_HeaderFile
17 #include <Standard_Type.hxx>
21 // Suppress VC9 warning on xsputn() function
24 #pragma warning(disable: 4996)
27 //! Custom buffer object implementing STL interface std::streambuf for streamed reading from allocated memory block.
28 //! Implements minimal sub-set of methods for passing buffer to std::istream, including seek support.
30 //! This class can be used for creating a seekable input stream in cases,
31 //! when the source data does not satisfies Reader requirements (non-seekable stream, compressed data)
32 //! or represents an in-memory resource.
34 //! The memory itself is NOT managed by this class - it is up to the caller to ensure that passed memory pointer
35 //! is not released during Standard_ArrayStreamBuffer lifetime.
39 //! const char* theBuffer;
40 //! const size_t theBufferLength;
41 //! Standard_ArrayStreamBuffer aStreamBuffer (theBuffer, theBufferLength);
42 //! std::istream aStream (&aStreamBuffer);
43 //! TopoDS_Shape aShape;
44 //! BRep_Builder aBuilder;
45 //! BRepTools::Read (aShape, aStream, aBuilder);
47 class Standard_ArrayStreamBuffer : public std::streambuf
52 //! Passed pointer is stored as is (memory is NOT copied nor released with destructor).
53 //! @param theBegin pointer to the beggining of pre-allocated buffer
54 //! @param theSize length of pre-allocated buffer
55 Standard_EXPORT Standard_ArrayStreamBuffer (const char* theBegin,
56 const size_t theSize);
59 Standard_EXPORT virtual ~Standard_ArrayStreamBuffer();
61 //! (Re)-initialize the stream.
62 //! Passed pointer is stored as is (memory is NOT copied nor released with destructor).
63 //! @param theBegin pointer to the beggining of pre-allocated buffer
64 //! @param theSize length of pre-allocated buffer
65 Standard_EXPORT virtual void Init (const char* theBegin,
66 const size_t theSize);
70 //! Get character on underflow.
71 //! Virtual function called by other member functions to get the current character
72 //! in the controlled input sequence without changing the current position.
73 Standard_EXPORT virtual int_type underflow() Standard_OVERRIDE;
75 //! Get character on underflow and advance position.
76 //! Virtual function called by other member functions to get the current character
77 //! in the controlled input sequence and then advance the position indicator to the next character.
78 Standard_EXPORT virtual int_type uflow() Standard_OVERRIDE;
80 //! Put character back in the case of backup underflow.
81 //! Virtual function called by other member functions to put a character back
82 //! into the controlled input sequence and decrease the position indicator.
83 Standard_EXPORT virtual int_type pbackfail (int_type ch) Standard_OVERRIDE;
85 //! Get number of characters available.
86 //! Virtual function (to be read s-how-many-c) called by other member functions
87 //! to get an estimate on the number of characters available in the associated input sequence.
88 Standard_EXPORT virtual std::streamsize showmanyc() Standard_OVERRIDE;
90 //! Seek to specified position.
91 Standard_EXPORT virtual pos_type seekoff (off_type theOff,
92 std::ios_base::seekdir theWay,
93 std::ios_base::openmode theWhich) Standard_OVERRIDE;
95 //! Change to specified position, according to mode.
96 Standard_EXPORT virtual pos_type seekpos (pos_type thePosition,
97 std::ios_base::openmode theWhich) Standard_OVERRIDE;
101 //! Read a bunch of bytes at once.
102 Standard_EXPORT virtual std::streamsize xsgetn (char* thePtr,
103 std::streamsize theCount) Standard_OVERRIDE;
107 // copying is not allowed
108 Standard_ArrayStreamBuffer (const Standard_ArrayStreamBuffer& );
109 Standard_ArrayStreamBuffer& operator= (const Standard_ArrayStreamBuffer& );
115 const char* myCurrent;
123 #endif // _Standard_ArrayStreamBuffer_HeaderFile