0026990: Compiler warnings in LDOM_OSStream.hxx
[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
6a38ff48 19#include <NCollection_DefineAlloc.hxx>
70167e69 20#include <NCollection_BaseAllocator.hxx>
7fd59977 21#include <Standard_OStream.hxx>
22#include <Standard_Boolean.hxx>
23
24#include <stdlib.h>
25#include <stdio.h> /* EOF */
26
e071e038 27//! Class LDOM_SBuffer inherits streambuf and
28//! redefines some virtual methods of it (overflow() and xsputn()).
29//! This class contains pointers on first and current element
30//! of sequence, also it has methods for the sequence management.
31class LDOM_SBuffer : public std::streambuf
7fd59977 32{
e071e038 33 //! One element of sequence.
34 //! Can only be allocated by the allocator and assumes
35 //! it is IncAllocator, so destructor isn't required.
6a38ff48 36 struct LDOM_StringElem
37 {
38 char* buf; //!< pointer on data string
39 int len; //!< quantity of really written data
40 LDOM_StringElem* next; //!< pointer on the next element of a sequence
41
42 DEFINE_NCOLLECTION_ALLOC
43
35c0599a 44 LDOM_StringElem(const int, const Handle(NCollection_BaseAllocator)&);
6a38ff48 45 ~LDOM_StringElem();
46
47 private:
48 LDOM_StringElem (const LDOM_StringElem&);
49 LDOM_StringElem& operator= (const LDOM_StringElem&);
50 };
51
52public:
e071e038 53 //! Constructor. Sets a default value for the
54 //! length of each sequence element.
7fd59977 55 Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf);
7fd59977 56
e071e038 57 //! Concatenates strings of all sequence elements
58 //! into one string. Space for output string is allocated
59 //! with operator new.
60 //! Caller of this function is responsible
61 //! for memory release after the string usage.
7fd59977 62 Standard_EXPORT Standard_CString str () const;
7fd59977 63
e071e038 64 //! Returns full length of data contained
5640d653 65 Standard_Integer Length () const {return myLength;}
7fd59977 66
e071e038 67 //! Clears first element of sequence and removes all others
7fd59977 68 Standard_EXPORT void Clear ();
7fd59977 69
e071e038 70 // Methods of streambuf
7fd59977 71
e071e038 72 Standard_EXPORT virtual int overflow(int c = EOF) Standard_OVERRIDE;
73 Standard_EXPORT virtual int underflow() Standard_OVERRIDE;
74 //virtual int uflow();
7fd59977 75
e071e038 76 Standard_EXPORT virtual std::streamsize xsputn(const char* s, std::streamsize n) Standard_OVERRIDE;
77 //virtual int xsgetn(char* s, int n);
78 //virtual int sync();
7fd59977 79
80 Standard_EXPORT ~LDOM_SBuffer ();
81 // Destructor
82
6a38ff48 83private:
84
7fd59977 85 Standard_Integer myMaxBuf; // default length of one element
86 Standard_Integer myLength; // full length of contained data
87 LDOM_StringElem* myFirstString; // the head of the sequence
88 LDOM_StringElem* myCurString; // current element of the sequence
70167e69 89 Handle(NCollection_BaseAllocator) myAlloc; //allocator for chunks
7fd59977 90};
91
e071e038 92//! Subclass if std::ostream allowing to increase performance
93//! of outputting data into a string avoiding reallocation of buffer.
94//! Class LDOM_OSStream implements output into a sequence of
95//! strings and getting the result as a string.
96//! It inherits Standard_OStream (ostream).
97//! Beside methods of ostream, it also has additional
98//! useful methods: str(), Length() and Clear().
7fd59977 99class LDOM_OSStream : public Standard_OStream
100{
e071e038 101public:
102 //! Constructor
103 Standard_EXPORT LDOM_OSStream(const Standard_Integer theMaxBuf);
7fd59977 104
5640d653 105 Standard_CString str () const {return myBuffer.str();}
7fd59977 106
e071e038 107 Standard_Integer Length () const { return myBuffer.Length(); }
7fd59977 108
5640d653 109 void Clear () { myBuffer.Clear(); }
7fd59977 110
111 private:
112 LDOM_SBuffer myBuffer;
113};
114
115#endif