0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / LDOM / LDOM_OSStream.hxx
CommitLineData
b311480e 1// Created on: 2001-10-01
2// Created by: Julia DOROVSKIKH
3// Copyright (c) 2001-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#ifndef LDOM_OSStream_HeaderFile
22#define LDOM_OSStream_HeaderFile
23
24// This implementation allows to increase performance
25// of outputting data into a string
26// avoiding reallocation of buffer.
7fd59977 27// class LDOM_OSStream implements output into a sequence of
28// strings and getting the result as a string.
29// It inherits Standard_OStream (ostream).
30// Beside methods of ostream, it also has additional
31// useful methods: str(), Length() and Clear().
7fd59977 32// struct LDOM_StringElem is one element of internal sequence
7fd59977 33// class LDOM_SBuffer inherits streambuf and
34// redefines some virtual methods of it
35// (overflow() and xsputn())
36// This class contains pointers on first
37// and current element of sequence,
38// also it has methods for the sequence management.
39
40#include <Standard_OStream.hxx>
41#include <Standard_Boolean.hxx>
42
43#include <stdlib.h>
44#include <stdio.h> /* EOF */
45
46class LDOM_StringElem; // defined in cxx file
47
48class LDOM_SBuffer : public streambuf
49{
50 public:
51 Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf);
52 // Constructor. Sets a default value for the
53 // length of each sequence element.
54
55 Standard_EXPORT Standard_CString str () const;
56 // Concatenates strings of all sequence elements
57 // into one string. Space for output string is allocated
58 // with operator new.
59 // Caller of this function is responsible
60 // for memory release after the string usage.
61
62 Standard_Integer Length () const {return myLength;};
63 // Returns full length of data contained
64
65 Standard_EXPORT void Clear ();
66 // Clears first element of sequence and removes all others
67
68 // Methods of streambuf
69
70 Standard_EXPORT virtual int overflow(int c = EOF);
71 Standard_EXPORT virtual int underflow();
72 //virtual int uflow();
73
74 Standard_EXPORT virtual int xsputn(const char* s, int n);
75 //virtual int xsgetn(char* s, int n);
76 //virtual int sync();
77
78 Standard_EXPORT ~LDOM_SBuffer ();
79 // Destructor
80
81 private:
82 Standard_Integer myMaxBuf; // default length of one element
83 Standard_Integer myLength; // full length of contained data
84 LDOM_StringElem* myFirstString; // the head of the sequence
85 LDOM_StringElem* myCurString; // current element of the sequence
86};
87
88class LDOM_OSStream : public Standard_OStream
89{
90 public:
91 Standard_EXPORT LDOM_OSStream (const Standard_Integer theMaxBuf);
92 // Constructor
93
94 Standard_CString str () const {return myBuffer.str();};
95
96 Standard_Integer Length () const {return myBuffer.Length();};
97
98 void Clear () { myBuffer.Clear(); };
99
100 private:
101 LDOM_SBuffer myBuffer;
102};
103
104#endif