Jamba C++ API  5.1.1
ReadOnlyMemoryStream.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 pongasoft
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 
19 #ifndef JAMBA_READONLYMEMORYSTREAM_H
20 #define JAMBA_READONLYMEMORYSTREAM_H
21 
22 #include <pluginterfaces/base/ibstream.h>
23 
24 namespace pongasoft::VST::VstUtils {
25 
26 using namespace Steinberg;
27 
28 class ReadOnlyMemoryStream : public IBStream
29 {
30 public:
32  ReadOnlyMemoryStream(char const *iMemory, TSize iMemorySize);
33 
34  virtual ~ReadOnlyMemoryStream() = default;
35 
36  //---IBStream---------------------------------------
37  virtual tresult PLUGIN_API read(void *buffer, int32 numBytes, int32 *numBytesRead) SMTG_OVERRIDE;
38  virtual tresult PLUGIN_API write(void *buffer, int32 numBytes, int32 *numBytesWritten) SMTG_OVERRIDE;
39  virtual tresult PLUGIN_API seek(int64 pos, int32 mode, int64 *result) SMTG_OVERRIDE;
40  virtual tresult PLUGIN_API tell(int64 *pos) SMTG_OVERRIDE;
41 
42  TSize getSize() const { return fMemorySize - fPos; };
43  inline char const* getData() const { return fMemory; }
44  TSize getMemorySize() const { return fMemorySize; };
45  inline int64 pos() const { return fPos; }
46 
47  //------------------------------------------------------------------------
48 DECLARE_FUNKNOWN_METHODS
49 
50 protected:
51  char const *fMemory; // memory block
52  TSize fMemorySize; // size of the memory block
53  int64 fPos; // stream pointer
54 };
55 
56 }
57 
58 #endif //JAMBA_READONLYMEMORYSTREAM_H
Definition: ExpiringDataCache.h:27
TSize fMemorySize
Definition: ReadOnlyMemoryStream.h:52
TSize getMemorySize() const
Definition: ReadOnlyMemoryStream.h:44
TSize getSize() const
Definition: ReadOnlyMemoryStream.h:42
char const * fMemory
Definition: ReadOnlyMemoryStream.h:51
int64 pos() const
returns the total size of the memory
Definition: ReadOnlyMemoryStream.h:45
Definition: ReadOnlyMemoryStream.h:28
int64 fPos
Definition: ReadOnlyMemoryStream.h:53
char const * getData() const
returns the current memory size (how many chars can be read until the end)
Definition: ReadOnlyMemoryStream.h:43