eRPC API Reference  Rev. 1.7.2
NXP Semiconductors
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>
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  }
95 
101  void destroy(void) { get()->~T(); }
102 
103 protected:
109  uint64_t m_storage[(sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
110 };
111 
112 } // namespace erpc
113 
116 #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:109
Definition: erpc_arbitrated_client_manager.h:25
void destroy(void)
Invoke the object&#39;s destructor.
Definition: erpc_manually_constructed.h:101
Allocates static storage for an object.
Definition: erpc_manually_constructed.h:47