1/*****************************************************************************/
2// Copyright 2006-2007 Adobe Systems Incorporated
3// All Rights Reserved.
4//
5// NOTICE: Adobe permits you to use, modify, and distribute this file in
6// accordance with the terms of the Adobe license agreement accompanying it.
7/*****************************************************************************/
8
9/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_memory_stream.h#2 $ */
10/* $DateTime: 2012/07/31 22:04:34 $ */
11/* $Change: 840853 $ */
12/* $Author: tknoll $ */
13
14/** \file
15 * Stream abstraction to/from in-memory data.
16 */
17
18/*****************************************************************************/
19
20#ifndef __dng_memory_stream__
21#define __dng_memory_stream__
22
23/*****************************************************************************/
24
25#include "dng_stream.h"
26
27/*****************************************************************************/
28
29/// \brief A dng_stream which can be read from or written to memory.
30///
31/// Stream is populated via writing and either read or accessed by asking for contents as a pointer.
32
33class dng_memory_stream: public dng_stream
34 {
35
36 protected:
37
38 dng_memory_allocator &fAllocator;
39
40 uint32 fPageSize;
41
42 uint32 fPageCount;
43 uint32 fPagesAllocated;
44
45 dng_memory_block **fPageList;
46
47 uint64 fMemoryStreamLength;
48
49 public:
50
51 /// Construct a new memory-based stream.
52 /// \param allocator Allocator to use to allocate memory in stream as needed.
53 /// \param sniffer If non-NULL used to check for user cancellation.
54 /// \param pageSize Unit of allocation for data stored in stream.
55
56 dng_memory_stream (dng_memory_allocator &allocator,
57 dng_abort_sniffer *sniffer = NULL,
58 uint32 pageSize = 64 * 1024);
59
60 virtual ~dng_memory_stream ();
61
62 /// Copy a specified number of bytes to a target stream.
63 /// \param dstStream The target stream.
64 /// \param count The number of bytes to copy.
65
66 virtual void CopyToStream (dng_stream &dstStream,
67 uint64 count);
68
69 protected:
70
71 virtual uint64 DoGetLength ();
72
73 virtual void DoRead (void *data,
74 uint32 count,
75 uint64 offset);
76
77 virtual void DoSetLength (uint64 length);
78
79 virtual void DoWrite (const void *data,
80 uint32 count,
81 uint64 offset);
82
83 private:
84
85 // Hidden copy constructor and assignment operator.
86
87 dng_memory_stream (const dng_memory_stream &stream);
88
89 dng_memory_stream & operator= (const dng_memory_stream &stream);
90
91 };
92
93/*****************************************************************************/
94
95#endif
96
97/*****************************************************************************/
98