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 #include <Standard_ArrayStreamBuffer.hxx>
16 // =======================================================================
17 // function : Standard_ArrayStreamBuffer
19 // =======================================================================
20 Standard_ArrayStreamBuffer::Standard_ArrayStreamBuffer (const char* theBegin,
23 myEnd (theBegin + theSize),
29 // =======================================================================
30 // function : ~Standard_ArrayStreamBuffer
32 // =======================================================================
33 Standard_ArrayStreamBuffer::~Standard_ArrayStreamBuffer()
38 // =======================================================================
41 // =======================================================================
42 void Standard_ArrayStreamBuffer::Init (const char* theBegin,
46 myEnd = theBegin + theSize;
50 // =======================================================================
51 // function : underflow
53 // =======================================================================
54 Standard_ArrayStreamBuffer::int_type Standard_ArrayStreamBuffer::underflow()
56 if (myCurrent == myEnd)
58 return traits_type::eof();
61 return traits_type::to_int_type(*myCurrent);
64 // =======================================================================
67 // =======================================================================
68 Standard_ArrayStreamBuffer::int_type Standard_ArrayStreamBuffer::uflow()
70 if (myCurrent == myEnd)
72 return traits_type::eof();
75 return traits_type::to_int_type(*myCurrent++);
78 // =======================================================================
79 // function : pbackfail
81 // =======================================================================
82 Standard_ArrayStreamBuffer::int_type Standard_ArrayStreamBuffer::pbackfail (int_type ch)
84 if (myCurrent == myBegin
85 || (ch != traits_type::eof()
86 && ch != myCurrent[-1]))
88 return traits_type::eof();
91 return traits_type::to_int_type(*--myCurrent);
94 // =======================================================================
95 // function : showmanyc
97 // =======================================================================
98 std::streamsize Standard_ArrayStreamBuffer::showmanyc()
100 if (myCurrent > myEnd)
104 return myEnd - myCurrent;
107 // =======================================================================
108 // function : seekoff
110 // =======================================================================
111 Standard_ArrayStreamBuffer::pos_type Standard_ArrayStreamBuffer::seekoff (off_type theOff,
112 std::ios_base::seekdir theWay,
113 std::ios_base::openmode theWhich)
117 case std::ios_base::beg:
119 myCurrent = myBegin + theOff;
120 if (myCurrent >= myEnd)
126 case std::ios_base::cur:
129 if (myCurrent >= myEnd)
135 case std::ios_base::end:
137 myCurrent = myEnd - theOff;
138 if (myCurrent < myBegin)
150 return myCurrent - myBegin;
153 // =======================================================================
154 // function : seekpos
156 // =======================================================================
157 Standard_ArrayStreamBuffer::pos_type Standard_ArrayStreamBuffer::seekpos (pos_type thePosition,
158 std::ios_base::openmode theWhich)
160 return seekoff (off_type(thePosition), std::ios_base::beg, theWhich);
163 // =======================================================================
166 // =======================================================================
167 std::streamsize Standard_ArrayStreamBuffer::xsgetn (char* thePtr,
168 std::streamsize theCount)
170 const char* aCurrent = myCurrent + theCount;
171 if (aCurrent >= myEnd)
175 size_t aCopied = aCurrent - myCurrent;
180 memcpy (thePtr, myCurrent, aCopied);
181 myCurrent = aCurrent;