Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2026 Accenture
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 :
11 : #pragma once
12 :
13 : #include "someip/ISomeIpSerializable.h"
14 :
15 : #include <cstring>
16 :
17 : namespace someip
18 : {
19 : class UnionBase : public ISomeIpSerializable
20 : {
21 : protected:
22 : template<typename T>
23 : static T const* castAsConstUnionType(uint8_t const* data);
24 :
25 : template<typename T>
26 : static T* castAsUnionType(uint8_t* data);
27 :
28 : static void memCpy(void* toData, void const* fromData, size_t size);
29 : };
30 :
31 : /*
32 : * inline implementation
33 : */
34 :
35 : // static
36 : template<typename T>
37 1 : inline T const* UnionBase::castAsConstUnionType(uint8_t const* const data)
38 : {
39 1 : return reinterpret_cast<T const*>(data);
40 : }
41 :
42 : // static
43 : template<typename T>
44 1 : inline T* UnionBase::castAsUnionType(uint8_t* const data)
45 : {
46 1 : return reinterpret_cast<T*>(data);
47 : }
48 :
49 : // static
50 1 : inline void UnionBase::memCpy(void* const toData, void const* const fromData, size_t const size)
51 : {
52 1 : (void)::memcpy(toData, fromData, size);
53 1 : }
54 :
55 : } // namespace someip
|