eRPC API Reference  Rev. 1.7.0
NXP Semiconductors
erpc_manually_constructed.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2014, Freescale Semiconductor, Inc.
4  * Copyright 2016 NXP
5  * All rights reserved.
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted (subject to the limitations in the disclaimer below) provided
10  * that the following conditions are met:
11  *
12  * o Redistributions of source code must retain the above copyright notice, this list
13  * of conditions and the following disclaimer.
14  *
15  * o Redistributions in binary form must reproduce the above copyright notice, this
16  * list of conditions and the following disclaimer in the documentation and/or
17  * other materials provided with the distribution.
18  *
19  * o Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _EMBEDDED_RPC__MANUALLY_CONSTRUCTED_H_
37 #define _EMBEDDED_RPC__MANUALLY_CONSTRUCTED_H_
38 #include <new>
39 #include <stdint.h>
40 
47 // Classes
50 
51 namespace erpc {
72 template <class T>
74 {
75 public:
77 
78  T *get(void) { return reinterpret_cast<T *>(&m_storage); }
79  const T *get(void) const { return reinterpret_cast<const T *>(&m_storage); }
80  T *operator->(void) { return get(); }
81  const T *operator->(void)const { return get(); }
82  T &operator*(void) { return *get(); }
83  const T &operator*(void)const { return *get(); }
84  operator T *(void) { return get(); }
85  operator const T *(void)const { return get(); }
87 
89 
90  void construct(void) { new (m_storage) T; }
91  template <typename A1>
92  void construct(const A1 &a1)
93  {
94  new (m_storage) T(a1);
95  }
96 
97  template <typename A1, typename A2>
98  void construct(const A1 &a1, const A2 &a2)
99  {
100  new (m_storage) T(a1, a2);
101  }
102 
103  template <typename A1, typename A2, typename A3>
104  void construct(const A1 &a1, const A2 &a2, const A3 &a3)
105  {
106  new (m_storage) T(a1, a2, a3);
107  }
108 
109  template <typename A1, typename A2, typename A3, typename A4>
110  void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
111  {
112  new (m_storage) T(a1, a2, a3, a4);
113  }
114 
115  template <typename A1, typename A2, typename A3, typename A4, typename A5>
116  void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
117  {
118  new (m_storage) T(a1, a2, a3, a4, a5);
119  }
121 
127  void destroy(void) { get()->~T(); }
128 
129 protected:
135  uint64_t m_storage[(sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
136 };
137 
138 } // namespace erpc
139 
142 #endif // _EMBEDDED_RPC__MANUALLY_CONSTRUCTED_H_
uint64_t m_storage[(sizeof(T)+sizeof(uint64_t)-1)/sizeof(uint64_t)]
Storage for the object.
Definition: erpc_manually_constructed.h:135
Definition: erpc_arbitrated_client_manager.h:51
void destroy(void)
Invoke the object&#39;s destructor.
Definition: erpc_manually_constructed.h:127
Allocates static storage for an object.
Definition: erpc_manually_constructed.h:73