Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
aligned_storage.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_core/aligned_storage.h
10//! @brief Aligned storage.
11
12#ifndef ROC_CORE_ALIGNED_STORAGE_H_
13#define ROC_CORE_ALIGNED_STORAGE_H_
14
15#include "roc_core/stddefs.h"
16
17namespace roc {
18namespace core {
19
20//! Fixed-size maximum-aligned storage.
21template <size_t Size> class AlignedStorage {
22public:
23 //! Get storage size.
24 static size_t size() {
25 return sizeof(Memory);
26 }
27
28 //! Get storage memory.
29 const void* memory() const {
30 return memory_.payload;
31 }
32
33 //! Get storage memory.
34 void* memory() {
35 return memory_.payload;
36 }
37
38private:
39 union Memory {
40 double d;
41 void (*fp)();
42 char payload[Size != 0 ? Size : 1];
43 };
44
45 Memory memory_;
46};
47
48} // namespace core
49} // namespace roc
50
51#endif // ROC_CORE_ALIGNED_STORAGE_H_
Fixed-size maximum-aligned storage.
const void * memory() const
Get storage memory.
void * memory()
Get storage memory.
static size_t size()
Get storage size.
Root namespace.
Commonly used types and functions.