summaryrefslogtreecommitdiffstats
path: root/import/hwpf/fapi2/include/buffer_parameters.H
blob: 89ed223cf68a73102c02ab31bcf2be80ebe4e5eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: hwpf/fapi2/include/buffer_parameters.H $                      */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* EKB Project                                                            */
/*                                                                        */
/* COPYRIGHT 2012,2015                                                    */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 * @file buffer_parameters.H
 * @brief definitions for fapi2 buffer parameter types
 */

#ifndef __FAPI2_BUFFER_PARAM__
#define __FAPI2_BUFFER_PARAM__

#include <stdint.h>

namespace fapi2
{
/// @cond
/// @brief Traits of buffer parameters - things passed in
/// @tparam T is the type of i_value (typically an integral type)
template<typename T>
class parameterTraits
{
    public:
        // Why constexpr functions? Enums are hard to do math on, and
        // static const doesn't work without -O1 (or greater.) That might
        // be a bug in g++ but this works just the same.
        constexpr static T mask(void)
        {
            return T(~0);
        }

        constexpr static uint32_t byte_length(void)
        {
            return sizeof(T);
        }

        constexpr static uint32_t bit_length(void)
        {
            return sizeof(T) * 8;
        }

        template<typename U>
        inline static void write_element(void* i_data, T i_value, uint32_t i_offset)
        {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
            T* ptr = (T*)i_data + (i_offset ^ ((sizeof(U) / sizeof(T)) - 1));
#else
            T* ptr = (T*)i_data + i_offset;
#endif
            *ptr = i_value;
        }
};
/// @endcond
}

#endif
OpenPOWER on IntegriCloud