0025616: Avoid Classes using "new" to allocate Instances but not defining a copy...
[occt.git] / src / LDOM / LDOM_OSStream.hxx
CommitLineData
b311480e 1// Created on: 2001-10-01
2// Created by: Julia DOROVSKIKH
973c2be1 3// Copyright (c) 2001-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#ifndef LDOM_OSStream_HeaderFile
17#define LDOM_OSStream_HeaderFile
18
19// This implementation allows to increase performance
20// of outputting data into a string
21// avoiding reallocation of buffer.
7fd59977 22// class LDOM_OSStream implements output into a sequence of
23// strings and getting the result as a string.
24// It inherits Standard_OStream (ostream).
25// Beside methods of ostream, it also has additional
26// useful methods: str(), Length() and Clear().
7fd59977 27// struct LDOM_StringElem is one element of internal sequence
7fd59977 28// class LDOM_SBuffer inherits streambuf and
29// redefines some virtual methods of it
30// (overflow() and xsputn())
31// This class contains pointers on first
32// and current element of sequence,
33// also it has methods for the sequence management.
34
6a38ff48 35#include <NCollection_DefineAlloc.hxx>
70167e69 36#include <NCollection_BaseAllocator.hxx>
7fd59977 37#include <Standard_OStream.hxx>
38#include <Standard_Boolean.hxx>
39
40#include <stdlib.h>
41#include <stdio.h> /* EOF */
42
7fd59977 43class LDOM_SBuffer : public streambuf
44{
6a38ff48 45 // One element of sequence.
46 // Can only be allocated by the allocator and assumes
47 // it is IncAllocator, so destructor isn't required.
48 struct LDOM_StringElem
49 {
50 char* buf; //!< pointer on data string
51 int len; //!< quantity of really written data
52 LDOM_StringElem* next; //!< pointer on the next element of a sequence
53
54 DEFINE_NCOLLECTION_ALLOC
55
56 LDOM_StringElem(const int, const Handle_NCollection_BaseAllocator&);
57 ~LDOM_StringElem();
58
59 private:
60 LDOM_StringElem (const LDOM_StringElem&);
61 LDOM_StringElem& operator= (const LDOM_StringElem&);
62 };
63
64public:
7fd59977 65 Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf);
66 // Constructor. Sets a default value for the
67 // length of each sequence element.
68
69 Standard_EXPORT Standard_CString str () const;
70 // Concatenates strings of all sequence elements
71 // into one string. Space for output string is allocated
72 // with operator new.
73 // Caller of this function is responsible
74 // for memory release after the string usage.
75
5640d653 76 Standard_Integer Length () const {return myLength;}
7fd59977 77 // Returns full length of data contained
78
79 Standard_EXPORT void Clear ();
80 // Clears first element of sequence and removes all others
81
82 // Methods of streambuf
83
84 Standard_EXPORT virtual int overflow(int c = EOF);
85 Standard_EXPORT virtual int underflow();
86 //virtual int uflow();
87
88 Standard_EXPORT virtual int xsputn(const char* s, int n);
89 //virtual int xsgetn(char* s, int n);
90 //virtual int sync();
91
92 Standard_EXPORT ~LDOM_SBuffer ();
93 // Destructor
94
6a38ff48 95private:
96
7fd59977 97 Standard_Integer myMaxBuf; // default length of one element
98 Standard_Integer myLength; // full length of contained data
99 LDOM_StringElem* myFirstString; // the head of the sequence
100 LDOM_StringElem* myCurString; // current element of the sequence
70167e69 101 Handle(NCollection_BaseAllocator) myAlloc; //allocator for chunks
7fd59977 102};
103
104class LDOM_OSStream : public Standard_OStream
105{
106 public:
107 Standard_EXPORT LDOM_OSStream (const Standard_Integer theMaxBuf);
108 // Constructor
109
5640d653 110 Standard_CString str () const {return myBuffer.str();}
7fd59977 111
5640d653 112 Standard_Integer Length () const {return myBuffer.Length();}
7fd59977 113
5640d653 114 void Clear () { myBuffer.Clear(); }
7fd59977 115
116 private:
117 LDOM_SBuffer myBuffer;
118};
119
120#endif