0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / LDOM / LDOM_OSStream.hxx
1 // Created on: 2001-10-01
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
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.
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().
27 //  struct LDOM_StringElem is one element of internal sequence
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 <NCollection_BaseAllocator.hxx>
36 #include <Standard_OStream.hxx>
37 #include <Standard_Boolean.hxx>
38
39 #include <stdlib.h>
40 #include <stdio.h> /* EOF */
41
42 class LDOM_StringElem; // defined in cxx file
43
44 class LDOM_SBuffer : public streambuf
45 {
46  public:
47   Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf);
48   // Constructor. Sets a default value for the
49   //              length of each sequence element.
50
51   Standard_EXPORT Standard_CString str () const;
52   // Concatenates strings of all sequence elements
53   // into one string. Space for output string is allocated
54   // with operator new.
55   // Caller of this function is responsible
56   // for memory release after the string usage.
57
58   Standard_Integer Length () const {return myLength;}
59   // Returns full length of data contained
60
61   Standard_EXPORT void Clear ();
62   // Clears first element of sequence and removes all others
63
64     // Methods of streambuf
65
66     Standard_EXPORT virtual int overflow(int c = EOF);
67     Standard_EXPORT virtual int underflow();
68     //virtual int uflow();
69
70     Standard_EXPORT virtual int xsputn(const char* s, int n);
71     //virtual int xsgetn(char* s, int n);
72     //virtual int sync();
73
74   Standard_EXPORT ~LDOM_SBuffer ();
75   // Destructor
76
77  private:
78  
79   Standard_Integer      myMaxBuf; // default length of one element
80   Standard_Integer      myLength; // full length of contained data
81   LDOM_StringElem* myFirstString; // the head of the sequence
82   LDOM_StringElem* myCurString;   // current element of the sequence
83   Handle(NCollection_BaseAllocator) myAlloc; //allocator for chunks
84 };
85
86 class LDOM_OSStream : public Standard_OStream
87 {
88  public:
89   Standard_EXPORT LDOM_OSStream (const Standard_Integer theMaxBuf);
90   // Constructor
91
92   Standard_CString str () const {return myBuffer.str();}
93
94   Standard_Integer Length () const {return myBuffer.Length();}
95
96   void Clear () { myBuffer.Clear(); }
97
98  private:
99   LDOM_SBuffer myBuffer;
100 };
101
102 #endif