Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-24 09:16:26

0001 // Created on: 2001-10-01
0002 // Created by: Julia DOROVSKIKH
0003 // Copyright (c) 2001-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef LDOM_OSStream_HeaderFile
0017 #define LDOM_OSStream_HeaderFile
0018 
0019 #include <NCollection_DefineAlloc.hxx>
0020 #include <NCollection_BaseAllocator.hxx>
0021 #include <Standard_OStream.hxx>
0022 
0023 #include <stdio.h> /* EOF */
0024 
0025 //! Class LDOM_SBuffer inherits std::streambuf and
0026 //! redefines some virtual methods of it (overflow() and xsputn()).
0027 //! This class contains pointers on first and current element
0028 //! of sequence, also it has methods for the sequence management.
0029 class LDOM_SBuffer : public std::streambuf
0030 {
0031   //! One element of sequence.
0032   //! Can only be allocated by the allocator and assumes
0033   //! it is IncAllocator, so destructor isn't required.
0034   struct LDOM_StringElem
0035   {
0036     char*            buf;  //!< pointer on data string
0037     int              len;  //!< quantity of really written data
0038     LDOM_StringElem* next; //!< pointer on the next element of a sequence
0039 
0040     DEFINE_NCOLLECTION_ALLOC
0041 
0042     LDOM_StringElem(const int, const occ::handle<NCollection_BaseAllocator>&);
0043     ~LDOM_StringElem();
0044 
0045   private:
0046     LDOM_StringElem(const LDOM_StringElem&);
0047     LDOM_StringElem& operator=(const LDOM_StringElem&);
0048   };
0049 
0050 public:
0051   //! Constructor. Sets a default value for the
0052   //!              length of each sequence element.
0053   Standard_EXPORT LDOM_SBuffer(const int theMaxBuf);
0054 
0055   //! Concatenates strings of all sequence elements
0056   //! into one string. Space for output string is allocated
0057   //! with operator new.
0058   //! Caller of this function is responsible
0059   //! for memory release after the string usage.
0060   Standard_EXPORT const char* str() const;
0061 
0062   //! Returns full length of data contained
0063   int Length() const { return myLength; }
0064 
0065   //! Clears first element of sequence and removes all others
0066   Standard_EXPORT void Clear();
0067 
0068   // Methods of std::streambuf
0069 
0070   Standard_EXPORT int overflow(int c = EOF) override;
0071   Standard_EXPORT int underflow() override;
0072   // virtual int uflow();
0073 
0074   Standard_EXPORT std::streamsize xsputn(const char* s, std::streamsize n) override;
0075   // virtual int xsgetn(char* s, int n);
0076   // virtual int sync();
0077 
0078   Standard_EXPORT ~LDOM_SBuffer() override;
0079   // Destructor
0080 
0081 private:
0082   int                                    myMaxBuf;      // default length of one element
0083   int                                    myLength;      // full length of contained data
0084   LDOM_StringElem*                       myFirstString; // the head of the sequence
0085   LDOM_StringElem*                       myCurString;   // current element of the sequence
0086   occ::handle<NCollection_BaseAllocator> myAlloc;       // allocator for chunks
0087 };
0088 
0089 //! Subclass if std::ostream allowing to increase performance
0090 //! of outputting data into a string avoiding reallocation of buffer.
0091 //! Class LDOM_OSStream implements output into a sequence of
0092 //! strings and getting the result as a string.
0093 //! It inherits Standard_OStream (std::ostream).
0094 //! Beside methods of std::ostream, it also has additional
0095 //! useful methods: str(), Length() and Clear().
0096 class LDOM_OSStream : public Standard_OStream
0097 {
0098 public:
0099   //! Constructor
0100   Standard_EXPORT LDOM_OSStream(const int theMaxBuf);
0101 
0102   Standard_EXPORT ~LDOM_OSStream() override;
0103 
0104   const char* str() const { return myBuffer.str(); }
0105 
0106   int Length() const { return myBuffer.Length(); }
0107 
0108   void Clear() { myBuffer.Clear(); }
0109 
0110 private:
0111   LDOM_SBuffer myBuffer;
0112 
0113 public:
0114   // byte order mark defined at the start of a stream
0115   enum BOMType
0116   {
0117     BOM_UNDEFINED,
0118     BOM_UTF8,
0119     BOM_UTF16BE,
0120     BOM_UTF16LE,
0121     BOM_UTF32BE,
0122     BOM_UTF32LE,
0123     BOM_UTF7,
0124     BOM_UTF1,
0125     BOM_UTFEBCDIC,
0126     BOM_SCSU,
0127     BOM_BOCU1,
0128     BOM_GB18030
0129   };
0130 };
0131 
0132 #endif