0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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>
7fd59977 22
7fd59977 23#include <stdio.h> /* EOF */
24
04232180 25//! Class LDOM_SBuffer inherits std::streambuf and
e071e038 26//! redefines some virtual methods of it (overflow() and xsputn()).
27//! This class contains pointers on first and current element
28//! of sequence, also it has methods for the sequence management.
29class LDOM_SBuffer : public std::streambuf
7fd59977 30{
e071e038 31 //! One element of sequence.
32 //! Can only be allocated by the allocator and assumes
33 //! it is IncAllocator, so destructor isn't required.
6a38ff48 34 struct LDOM_StringElem
35 {
36 char* buf; //!< pointer on data string
37 int len; //!< quantity of really written data
38 LDOM_StringElem* next; //!< pointer on the next element of a sequence
39
40 DEFINE_NCOLLECTION_ALLOC
41
35c0599a 42 LDOM_StringElem(const int, const Handle(NCollection_BaseAllocator)&);
6a38ff48 43 ~LDOM_StringElem();
44
45 private:
46 LDOM_StringElem (const LDOM_StringElem&);
47 LDOM_StringElem& operator= (const LDOM_StringElem&);
48 };
49
50public:
e071e038 51 //! Constructor. Sets a default value for the
52 //! length of each sequence element.
7fd59977 53 Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf);
7fd59977 54
e071e038 55 //! Concatenates strings of all sequence elements
56 //! into one string. Space for output string is allocated
57 //! with operator new.
58 //! Caller of this function is responsible
59 //! for memory release after the string usage.
7fd59977 60 Standard_EXPORT Standard_CString str () const;
7fd59977 61
e071e038 62 //! Returns full length of data contained
5640d653 63 Standard_Integer Length () const {return myLength;}
7fd59977 64
e071e038 65 //! Clears first element of sequence and removes all others
7fd59977 66 Standard_EXPORT void Clear ();
7fd59977 67
04232180 68 // Methods of std::streambuf
7fd59977 69
e071e038 70 Standard_EXPORT virtual int overflow(int c = EOF) Standard_OVERRIDE;
71 Standard_EXPORT virtual int underflow() Standard_OVERRIDE;
72 //virtual int uflow();
7fd59977 73
e071e038 74 Standard_EXPORT virtual std::streamsize xsputn(const char* s, std::streamsize n) Standard_OVERRIDE;
75 //virtual int xsgetn(char* s, int n);
76 //virtual int sync();
7fd59977 77
78 Standard_EXPORT ~LDOM_SBuffer ();
79 // Destructor
80
6a38ff48 81private:
82
7fd59977 83 Standard_Integer myMaxBuf; // default length of one element
84 Standard_Integer myLength; // full length of contained data
85 LDOM_StringElem* myFirstString; // the head of the sequence
86 LDOM_StringElem* myCurString; // current element of the sequence
70167e69 87 Handle(NCollection_BaseAllocator) myAlloc; //allocator for chunks
7fd59977 88};
89
e071e038 90//! Subclass if std::ostream allowing to increase performance
91//! of outputting data into a string avoiding reallocation of buffer.
92//! Class LDOM_OSStream implements output into a sequence of
93//! strings and getting the result as a string.
04232180 94//! It inherits Standard_OStream (std::ostream).
95//! Beside methods of std::ostream, it also has additional
e071e038 96//! useful methods: str(), Length() and Clear().
7fd59977 97class LDOM_OSStream : public Standard_OStream
98{
e071e038 99public:
100 //! Constructor
101 Standard_EXPORT LDOM_OSStream(const Standard_Integer theMaxBuf);
7fd59977 102
6531dfea
BB
103 Standard_EXPORT virtual ~LDOM_OSStream();
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;
8f34d47e 113
114public:
115 // byte order mark defined at the start of a stream
116 enum BOMType {
117 BOM_UNDEFINED,
118 BOM_UTF8,
119 BOM_UTF16BE,
120 BOM_UTF16LE,
121 BOM_UTF32BE,
122 BOM_UTF32LE,
123 BOM_UTF7,
124 BOM_UTF1,
125 BOM_UTFEBCDIC,
126 BOM_SCSU,
127 BOM_BOCU1,
128 BOM_GB18030
129 };
7fd59977 130};
131
132#endif