Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cRIFF.h
Go to the documentation of this file.
1 //
4 //
5 #ifndef _INC_cRIFF_H
6 #define _INC_cRIFF_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "cRIFFFormat.h"
12 #include "GrayCore/include/cHeap.h"
17 
18 namespace GrayLib
19 {
20  class GRAYLIB_LINK cRIFFBlock : public cRefBase, public cRIFFHead
21  {
25 
26  protected:
27  virtual HRESULT ReadStreamBody(cStreamInput& strIn) = 0;
28  virtual HRESULT WriteStreamBody(cStreamOutput* pFile) const = 0;
29 
30  public:
31  cRIFFBlock(FOURCC nTypeChunk, RIFF_SIZE_t nSize)
32  : cRIFFHead(nTypeChunk, nSize)
33  {
34  }
35  virtual ~cRIFFBlock()
36  {
37  }
38 
39  virtual bool isListType() const = 0;
40 
41  static HRESULT GRAYCALL ReadStreamUnk(cStreamInput& strIn, cRefPtr<cRIFFBlock>* ppRet);
42  HRESULT WriteStream(cStreamOutput* pFile) const;
43  };
45 
47  {
50 
51  public:
53 
54  protected:
55  virtual HRESULT ReadStreamBody(cStreamInput& strIn);
56  virtual HRESULT WriteStreamBody(cStreamOutput* pFile) const;
57 
58  public:
59  cRIFFChunk(FOURCC nTypeChunk, RIFF_SIZE_t nDataSize)
60  : cRIFFBlock(nTypeChunk, nDataSize)
61  {
62  }
63  virtual ~cRIFFChunk()
64  {
65  }
66 
67  virtual bool isListType() const
68  {
69  return false;
70  }
71  void* get_Data() const
72  {
73  // If this is loaded.
74  return m_Data.get_Data();
75  }
76  };
77 
79  {
82 
83  public:
86 
87  protected:
88  virtual HRESULT ReadStreamBody(cStreamInput& strIn);
89  virtual HRESULT WriteStreamBody(cStreamOutput* pFile) const;
90 
91  public:
92  cRIFFList(FOURCC nTypeList, FOURCC nTypeChunk, RIFF_SIZE_t nDataSize)
93  : cRIFFBlock(nTypeChunk, nDataSize)
94  , m_nTypeList(nTypeList)
95  {
96  }
97  virtual ~cRIFFList()
98  {
99  }
100 
101  virtual bool isListType() const
102  {
104  return true;
105  }
106  cRIFFChunk* EnumChunk(int i) const
107  {
108  if (!m_aList.IsValidIndex(i))
109  return nullptr;
110  return SMARTS_CAST(cRIFFChunk,m_aList[i]);
111  }
112  cRIFFChunk* FindChunkId(FOURCC nTypeChunk) const
113  {
114  for (int i = 0; i < m_aList.GetSize(); i++)
115  {
116  cRIFFBlock* pChunk = m_aList[i];
117  if (pChunk->m_nTypeChunk == nTypeChunk)
118  return static_cast<cRIFFChunk*>(pChunk);
119  }
120  return nullptr;
121  }
122  };
123 
125  {
129 
130  public:
132 
133  public:
135  {
136  }
137 
138  size_t get_Size() const
139  {
141  if (m_pRIFF == nullptr)
142  return 0;
143  return m_pRIFF->m_nDataSize;
144  }
145 
146  HRESULT ReadStream(cStreamInput& strIn);
147  HRESULT WriteStream(cStreamOutput* pFile) const;
148 
149  HRESULT LoadFile(const FILECHAR_t* pszFile);
150  HRESULT SaveFile(const FILECHAR_t* pszFile) const;
151 
153  };
154 };
155 
156 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
UINT32 FOURCC
32 bit code. Also defined in _MMSYSTEM_H
Definition: cFourCC.h:19
#define SMARTS_CAST(_DSTCLASS, p)
Definition: cPtrFacade.h:138
Definition: cFourCC.h:96
Definition: cRIFF.h:21
cRIFFBlock(FOURCC nTypeChunk, RIFF_SIZE_t nSize)
Definition: cRIFF.h:31
virtual HRESULT ReadStreamBody(cStreamInput &strIn)=0
virtual ~cRIFFBlock()
Definition: cRIFF.h:35
virtual HRESULT WriteStreamBody(cStreamOutput *pFile) const =0
virtual bool isListType() const =0
Definition: cRIFF.h:47
cHeapBlock m_Data
the chunk data payload.
Definition: cRIFF.h:52
virtual bool isListType() const
Definition: cRIFF.h:67
virtual ~cRIFFChunk()
Definition: cRIFF.h:63
void * get_Data() const
Definition: cRIFF.h:71
cRIFFChunk(FOURCC nTypeChunk, RIFF_SIZE_t nDataSize)
Definition: cRIFF.h:59
Definition: cRIFFFormat.h:34
FOURCC m_nTypeChunk
chunk ID. i.e. 'RIFF','LIST','FORM' FOURCC_RIFF or 'data' for non list (MMCKINFO ckid)
Definition: cRIFFFormat.h:39
Definition: cRIFF.h:79
virtual bool isListType() const
Definition: cRIFF.h:101
virtual ~cRIFFList()
Definition: cRIFF.h:97
cFourCC m_nTypeList
What type of RIFF or LIST block is this? e.g. "WAVE".
Definition: cRIFF.h:84
cArrayRef< cRIFFBlock > m_aList
list of child chunks in this.
Definition: cRIFF.h:85
cRIFFList(FOURCC nTypeList, FOURCC nTypeChunk, RIFF_SIZE_t nDataSize)
Definition: cRIFF.h:92
cRIFFChunk * FindChunkId(FOURCC nTypeChunk) const
Definition: cRIFF.h:112
cRIFFChunk * EnumChunk(int i) const
Definition: cRIFF.h:106
Definition: cRIFF.h:125
cRIFF()
Definition: cRIFF.h:134
UNITTEST_FRIEND(cRIFF)
cRefPtr< cRIFFList > m_pRIFF
The main RIFF list. //!< Array of these for AVIX (64 bit extension)
Definition: cRIFF.h:131
size_t get_Size() const
Definition: cRIFF.h:138
ITERATE_t GetSize() const noexcept
Definition: cArray.h:137
Definition: cArrayRef.h:21
bool IsValidIndex(ITERATE_t i) const noexcept
Definition: cArray.h:495
Definition: cHeap.h:156
void * get_Data() const noexcept
Definition: cHeap.h:363
Definition: cRefPtr.h:22
Definition: cRefPtr.h:225
Definition: cStream.h:306
Definition: cStream.h:126
Definition: cMesh.h:22
cRefPtr< cRIFFBlock > cRIFFBasePtr
Definition: cRIFF.h:44
UINT32 RIFF_SIZE_t
32 bit Size limit for any chunk
Definition: cRIFFFormat.h:17
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22