버전

menu_open
Wwise SDK 2024.1.0
IBytes.h
이 파일의 문서화 페이지로 가기
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Copyright (c) 2024 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 /// \file
28 /// AK::IReadBytes, AK::IWriteBytes simple serialization interfaces.
29 
30 #ifndef _AK_IBYTES_H
31 #define _AK_IBYTES_H
32 
33 #include <wchar.h>
35 
36 namespace AK
37 {
38  /// Generic binary input interface.
39  /// \akwarning
40  /// The functions in this interface are not thread-safe, unless stated otherwise.
41  /// \endakwarning
42  class IReadBytes
43  {
44  public:
45  ////////////////////////////////////////////////////////////////////////
46  /// @name Interface
47  //@{
48 
49  /// Reads some bytes into a buffer.
50  /// \return True if the operation was successful, False otherwise
51  virtual bool ReadBytes(
52  void * in_pData, ///< Pointer to a buffer
53  AkInt32 in_cBytes, ///< Size of the buffer (in bytes)
54  AkInt32 & out_cRead ///< Returned number of read bytes
55  ) = 0;
56 
57  //@}
58 
59  ////////////////////////////////////////////////////////////////////////
60  /// @name Helpers
61  //@{
62 
63  /// Reads a simple type or structure.
64  /// \akwarning
65  /// Not for object serialization.
66  /// \endakwarning
67  /// \return True if the operation was successful, False otherwise.
68  template<class T>
69  bool Read(
70  T & out_data) ///< Data to be read
71  {
72  AkInt32 cRead;
73  return ReadBytes(&out_data, sizeof(T), cRead);
74  }
75 
76  template<>
77  bool Read<bool>(
78  bool & out_data)
79  {
80  AkInt32 cRead;
81  uint8_t byte;
82  if (ReadBytes(&byte, 1, cRead))
83  {
84  out_data = byte;
85  return true;
86  }
87  return false;
88  }
89 
90  /// Reads a simple type or structure.
91  /// \warning This method does not allow for error checking. Use other methods when error cases need to be handled.
92  /// \warning Not for object serialization.
93  /// \return Read data
94  template<class T>
95  T Read()
96  {
97  T value;
98  this->Read<T>(value);
99  return value;
100  }
101 
102  //@}
103  };
104 
105 
106  /// Generic binary output interface.
107  /// \akwarning
108  /// The functions in this interface are not thread-safe, unless stated otherwise.
109  /// \endakwarning
111  {
112  public:
113  ////////////////////////////////////////////////////////////////////////
114  /// @name Interface
115  //@{
116 
117  /// Writes some bytes from a buffer.
118  /// \return True if the operation was successful, False otherwise
119  virtual bool WriteBytes(
120  const void * in_pData, ///< Pointer to a buffer
121  AkInt32 in_cBytes, ///< Size of the buffer (in bytes)
122  AkInt32 & out_cWritten ///< Returned number of written bytes
123  ) = 0;
124 
125  //@}
126 
127  ////////////////////////////////////////////////////////////////////////
128  /// @name Helpers
129  //@{
130 
131  /// Writes a simple type or struct.
132  /// \warning Not for object serialization.
133  /// \return True if the operation was successful, False otherwise
134  template<class T>
135  bool Write(
136  const T & in_data) ///< Data to be written
137  {
138  AkInt32 cWritten;
139  return WriteBytes(&in_data, sizeof(T), cWritten);
140  }
141 
142  template<>
143  bool Write<bool>(
144  const bool & in_data)
145  {
146  AkInt32 cWritten;
147  const uint8_t byte = in_data;
148  return WriteBytes(&byte, 1, cWritten);
149  }
150 
151  //@}
152  };
153 
154  /// Generic memory buffer interface.
155  /// \akwarning
156  /// The functions in this interface are not thread-safe, unless stated otherwise.
157  /// \endakwarning
158  class IWriteBuffer : public IWriteBytes
159  {
160  public:
161  ////////////////////////////////////////////////////////////////////////
162  /// @name Interface
163  //@{
164 
165  /// Get the number of bytes written to the buffer.
166  /// \return number of bytes written.
167  virtual AkInt32 Count() const = 0;
168 
169  /// Get pointer to buffer.
170  /// \return pointer to buffer.
171  virtual AkUInt8 * Bytes() const = 0;
172 
173  /// Set number of bytes written.
174  virtual void SetCount(AkInt32 in_cBytes) = 0;
175 
176  /// Allocate memory.
177  /// \return true if allocation was successful.
178  virtual bool Reserve(AkInt32 in_cBytes) = 0;
179 
180  /// Clear the buffer contents.
181  virtual void Clear() = 0;
182 
183  /// Return pointer to buffer and clear internal pointer.
184  virtual AkUInt8 * Detach() = 0;
185 
186  //@}
187  };
188 }
189 
190 #endif // _AK_IBYTES_H
virtual AkUInt8 * Detach()=0
Return pointer to buffer and clear internal pointer.
Definition of data structures for AkAudioObject
bool Read(T &out_data)
Definition: IBytes.h:69
uint8_t AkUInt8
Unsigned 8-bit integer
virtual bool Reserve(AkInt32 in_cBytes)=0
virtual void SetCount(AkInt32 in_cBytes)=0
Set number of bytes written.
int32_t AkInt32
Signed 32-bit integer
virtual bool WriteBytes(const void *in_pData, AkInt32 in_cBytes, AkInt32 &out_cWritten)=0
bool Write(const T &in_data)
Definition: IBytes.h:135
virtual bool ReadBytes(void *in_pData, AkInt32 in_cBytes, AkInt32 &out_cRead)=0
virtual AkInt32 Count() const =0
virtual AkUInt8 * Bytes() const =0
virtual void Clear()=0
Clear the buffer contents.

이 페이지가 도움이 되었나요?

지원이 필요하신가요?

질문이 있으신가요? 문제를 겪고 계신가요? 더 많은 정보가 필요하신가요? 저희에게 문의해주시면 도와드리겠습니다!

지원 페이지를 방문해 주세요

작업하는 프로젝트에 대해 알려주세요. 언제든지 도와드릴 준비가 되어 있습니다.

프로젝트를 등록하세요. 아무런 조건이나 의무 사항 없이 빠른 시작을 도와드리겠습니다.

Wwise를 시작해 보세요