XVector
xvec_buffer.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2026 XCENA Inc.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of 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,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
30 #pragma once
31 
32 #ifdef __cplusplus
33 
34 #include <cstddef>
35 
37 
38 #include "xvector/xvec_types.h"
39 
40 namespace xvec
41 {
42 
50 class Buffer
51 {
52 public:
59  Buffer(xvecExecutionContextTag* context, size_t size);
60 
61  virtual ~Buffer();
62 
63  Buffer(Buffer&& other) noexcept;
64  Buffer& operator=(Buffer&& other) noexcept;
65 
66  Buffer(const Buffer&) = delete;
67  Buffer& operator=(const Buffer&) = delete;
68 
72  xvecBufferTag* handle() const noexcept;
73 
78  void* data() const;
79 
84  template <typename T>
85  T* data() const
86  {
87  return static_cast<T*>(data());
88  }
89 
94  size_t size() const;
95 
96 private:
97  xvecExecutionContextTag* context_ = nullptr;
98  xvecBufferTag* handle_ = nullptr;
99 };
100 
101 } // namespace xvec
102 
103 #endif // __cplusplus
RAII wrapper for xvecBufferTag.
Definition: xvec_buffer.hpp:51
xvecBufferTag * handle() const noexcept
Get the underlying C API handle.
Buffer & operator=(const Buffer &)=delete
Buffer(Buffer &&other) noexcept
virtual ~Buffer()
Buffer(xvecExecutionContextTag *context, size_t size)
Create a buffer.
void * data() const
Get the raw data pointer.
Buffer & operator=(Buffer &&other) noexcept
size_t size() const
Get the buffer size in bytes.
Buffer(const Buffer &)=delete
Exception types for C++ XVECTOR wrappers.
Core types, enums, and structures for the XVector library.