| eRPC API Reference Rev. 1.8.1 NXP Semiconductors

- Main Page
- API Reference
- Classes
- Files

- File List
- File Members

erpc_manually_constructed.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2014, Freescale Semiconductor, Inc.
3 * Copyright 2016 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10 #ifndef _EMBEDDED_RPC__MANUALLY_CONSTRUCTED_H_
11 #define _EMBEDDED_RPC__MANUALLY_CONSTRUCTED_H_
12 #include <new>
13 #include <stdint.h>
14
21 // Classes
24
25 namespace erpc {
46 template <class T>
47 class ManuallyConstructed
48 {
49 public:
51
52 T *get(void) { return reinterpret_cast<T *>(&m_storage); }
53 const T *get(void) const { return reinterpret_cast<const T *>(&m_storage); }
54 T *operator->(void) { return get(); }
55 const T *operator->(void) const { return get(); }
56 T &operator*(void) { return *get(); }
57 const T &operator*(void) const { return *get(); }
58 operator T *(void) { return get(); }
59 operator const T *(void) const { return get(); }
61
63
64 void construct(void) { new (m_storage) T; }
65 template <typename A1>
66 void construct(const A1 &a1)
67 {
68 new (m_storage) T(a1);
69 }
70
71 template <typename A1, typename A2>
72 void construct(const A1 &a1, const A2 &a2)
73 {
74 new (m_storage) T(a1, a2);
75 }
76
77 template <typename A1, typename A2, typename A3>
78 void construct(const A1 &a1, const A2 &a2, const A3 &a3)
79 {
80 new (m_storage) T(a1, a2, a3);
81 }
82
83 template <typename A1, typename A2, typename A3, typename A4>
84 void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
85 {
86 new (m_storage) T(a1, a2, a3, a4);
87 }
88
89 template <typename A1, typename A2, typename A3, typename A4, typename A5>
90 void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
91 {
92 new (m_storage) T(a1, a2, a3, a4, a5);
93 }
94
95 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
96 void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6)
97 {
98 new (m_storage) T(a1, a2, a3, a4, a5, a6);
99 }
101
107 void destroy(void) { get()->~T(); }
108
109 protected:
115 uint64_t m_storage[(sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
116 };
117
118 } // namespace erpc
119
122 #endif // _EMBEDDED_RPC__MANUALLY_CONSTRUCTED_H_
erpc::ManuallyConstructed::m_storage
uint64_t m_storage[(sizeof(T)+sizeof(uint64_t)-1)/sizeof(uint64_t)]
Storage for the object.
Definition: erpc_manually_constructed.h:115
erpc
Definition: erpc_arbitrated_client_manager.h:25
erpc::ManuallyConstructed::destroy
void destroy(void)
Invoke the object&#39;s destructor.
Definition: erpc_manually_constructed.h:107
erpc::ManuallyConstructed
Allocates static storage for an object.
Definition: erpc_manually_constructed.h:47