0022627: Change OCCT memory management defaults
[occt.git] / src / LDOM / LDOM_OSStream.hxx
... / ...
CommitLineData
1// File: LDOM_OSStream.hxx
2// Created: 01.10.01 10:56:06
3// Author: Julia DOROVSKIKH
4// Copyright: Open Cascade 2001
5
6#ifndef LDOM_OSStream_HeaderFile
7#define LDOM_OSStream_HeaderFile
8
9// This implementation allows to increase performance
10// of outputting data into a string
11// avoiding reallocation of buffer.
12//
13// class LDOM_OSStream implements output into a sequence of
14// strings and getting the result as a string.
15// It inherits Standard_OStream (ostream).
16// Beside methods of ostream, it also has additional
17// useful methods: str(), Length() and Clear().
18//
19// struct LDOM_StringElem is one element of internal sequence
20//
21// class LDOM_SBuffer inherits streambuf and
22// redefines some virtual methods of it
23// (overflow() and xsputn())
24// This class contains pointers on first
25// and current element of sequence,
26// also it has methods for the sequence management.
27
28#include <Standard_OStream.hxx>
29#include <Standard_Boolean.hxx>
30
31#include <stdlib.h>
32#include <stdio.h> /* EOF */
33
34class LDOM_StringElem; // defined in cxx file
35
36class LDOM_SBuffer : public streambuf
37{
38 public:
39 Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf);
40 // Constructor. Sets a default value for the
41 // length of each sequence element.
42
43 Standard_EXPORT Standard_CString str () const;
44 // Concatenates strings of all sequence elements
45 // into one string. Space for output string is allocated
46 // with operator new.
47 // Caller of this function is responsible
48 // for memory release after the string usage.
49
50 Standard_Integer Length () const {return myLength;};
51 // Returns full length of data contained
52
53 Standard_EXPORT void Clear ();
54 // Clears first element of sequence and removes all others
55
56 // Methods of streambuf
57
58 Standard_EXPORT virtual int overflow(int c = EOF);
59 Standard_EXPORT virtual int underflow();
60 //virtual int uflow();
61
62 Standard_EXPORT virtual int xsputn(const char* s, int n);
63 //virtual int xsgetn(char* s, int n);
64 //virtual int sync();
65
66 Standard_EXPORT ~LDOM_SBuffer ();
67 // Destructor
68
69 private:
70 Standard_Integer myMaxBuf; // default length of one element
71 Standard_Integer myLength; // full length of contained data
72 LDOM_StringElem* myFirstString; // the head of the sequence
73 LDOM_StringElem* myCurString; // current element of the sequence
74};
75
76class LDOM_OSStream : public Standard_OStream
77{
78 public:
79 Standard_EXPORT LDOM_OSStream (const Standard_Integer theMaxBuf);
80 // Constructor
81
82 Standard_CString str () const {return myBuffer.str();};
83
84 Standard_Integer Length () const {return myBuffer.Length();};
85
86 void Clear () { myBuffer.Clear(); };
87
88 private:
89 LDOM_SBuffer myBuffer;
90};
91
92#endif