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 | // |
973c2be1 |
7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public version 2.1 as published |
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 | |
35 | #include <Standard_OStream.hxx> |
36 | #include <Standard_Boolean.hxx> |
37 | |
38 | #include <stdlib.h> |
39 | #include <stdio.h> /* EOF */ |
40 | |
41 | class LDOM_StringElem; // defined in cxx file |
42 | |
43 | class LDOM_SBuffer : public streambuf |
44 | { |
45 | public: |
46 | Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf); |
47 | // Constructor. Sets a default value for the |
48 | // length of each sequence element. |
49 | |
50 | Standard_EXPORT Standard_CString str () const; |
51 | // Concatenates strings of all sequence elements |
52 | // into one string. Space for output string is allocated |
53 | // with operator new. |
54 | // Caller of this function is responsible |
55 | // for memory release after the string usage. |
56 | |
57 | Standard_Integer Length () const {return myLength;}; |
58 | // Returns full length of data contained |
59 | |
60 | Standard_EXPORT void Clear (); |
61 | // Clears first element of sequence and removes all others |
62 | |
63 | // Methods of streambuf |
64 | |
65 | Standard_EXPORT virtual int overflow(int c = EOF); |
66 | Standard_EXPORT virtual int underflow(); |
67 | //virtual int uflow(); |
68 | |
69 | Standard_EXPORT virtual int xsputn(const char* s, int n); |
70 | //virtual int xsgetn(char* s, int n); |
71 | //virtual int sync(); |
72 | |
73 | Standard_EXPORT ~LDOM_SBuffer (); |
74 | // Destructor |
75 | |
76 | private: |
77 | Standard_Integer myMaxBuf; // default length of one element |
78 | Standard_Integer myLength; // full length of contained data |
79 | LDOM_StringElem* myFirstString; // the head of the sequence |
80 | LDOM_StringElem* myCurString; // current element of the sequence |
81 | }; |
82 | |
83 | class LDOM_OSStream : public Standard_OStream |
84 | { |
85 | public: |
86 | Standard_EXPORT LDOM_OSStream (const Standard_Integer theMaxBuf); |
87 | // Constructor |
88 | |
89 | Standard_CString str () const {return myBuffer.str();}; |
90 | |
91 | Standard_Integer Length () const {return myBuffer.Length();}; |
92 | |
93 | void Clear () { myBuffer.Clear(); }; |
94 | |
95 | private: |
96 | LDOM_SBuffer myBuffer; |
97 | }; |
98 | |
99 | #endif |