Cortex  10.0.0-a4
MemoryStream.h
1 //
3 // Copyright (c) 2007-2009, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IE_CORE_MEMORYSTREAM_H
36 #define IE_CORE_MEMORYSTREAM_H
37 
38 #include "boost/iostreams/categories.hpp"
39 #include "boost/iostreams/detail/ios.hpp"
40 #include "boost/iostreams/detail/fstream.hpp"
41 #include "boost/iostreams/operations.hpp"
42 
43 #include "IECore/Export.h"
44 #include "IECore/RefCounted.h"
45 
46 namespace IECore
47 {
48 
50 class IECORE_API MemoryStream
51 {
52  public:
53  struct category
54  : public boost::iostreams::device_tag
55  { };
56 
57  MemoryStream();
58 
62  MemoryStream( char *buf, std::streamsize sz, bool ownsBuf = false );
63 
65  std::streamsize read(char* s, std::streamsize n);
66 
68  std::streamsize write(const char* s, std::streamsize n);
69 
71  void get( char *& data, std::streamsize &sz ) const;
72 
73  private:
74 
75  struct Impl : public IECore::RefCounted
76  {
77  Impl();
78 
79  Impl( char *buf, std::streamsize sz, bool ownsBuf = false );
80 
81  ~Impl() override;
82 
83  std::streamsize read(char* s, std::streamsize n);
84 
85  std::streamsize write(const char* s, std::streamsize n);
86 
87  char *m_head;
88  char *m_next;
89 
90  std::streamsize m_size;
91  std::streamsize m_bufSize;
92 
93  bool m_ownsBuf;
94  };
95 
96  IE_CORE_DECLAREPTR( Impl );
97  ImplPtr m_impl;
98 };
99 
100 struct MemoryStreamSource : private MemoryStream
101 {
102  typedef char char_type;
103  typedef boost::iostreams::source_tag category;
104 
105  using MemoryStream::read;
106  using MemoryStream::get;
107 
108  MemoryStreamSource(char *buf, std::streamsize sz, bool ownsBuf = false);
109 };
110 
111 struct MemoryStreamSink : private MemoryStream
112 {
113  typedef char char_type;
114  typedef boost::iostreams::sink_tag category;
115 
116  using MemoryStream::write;
117  using MemoryStream::get;
118 
119  MemoryStreamSink();
120 };
121 
122 } // namespace IECore
123 
124 #endif // IE_CORE_MEMORYSTREAM_H
A boost.iostreams "device" for reading to/writing from memory.
Definition: MemoryStream.h:50
std::streamsize read(char *s, std::streamsize n)
Read from the stream.
void get(char *&data, std::streamsize &sz) const
Retrieve a reference to the contents of the stream.
std::streamsize write(const char *s, std::streamsize n)
Write to the stream.
Definition: RefCounted.h:124
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43