File: byte_orderer_kernel_abstract.h

package info (click to toggle)
concurrentqueue 1.0.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,656 kB
  • sloc: cpp: 37,309; makefile: 99; ansic: 67; python: 46; sh: 11
file content (149 lines) | stat: -rw-r--r-- 3,974 bytes parent folder | download | duplicates (15)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (C) 2006  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#undef DLIB_BYTE_ORDEREr_ABSTRACT_ 
#ifdef DLIB_BYTE_ORDEREr_ABSTRACT_

#include "../algs.h"

namespace dlib
{

    class byte_orderer 
    {
        /*!
            INITIAL VALUE
                This object has no state.

            WHAT THIS OBJECT REPRESENTS
                This object simply provides a mechanism to convert data from a
                host machine's own byte ordering to big or little endian and to 
                also do the reverse.

                It also provides a pair of functions to convert to/from network byte
                order where network byte order is big endian byte order.  This pair of
                functions does the exact same thing as the host_to_big() and big_to_host()
                functions and is provided simply so that client code can use the most 
                self documenting name appropriate.

                Also note that this object is capable of correctly flipping the contents 
                of arrays when the arrays are declared on the stack.  e.g.  You can  
                say things like:
                int array[10]; 
                bo.host_to_network(array);
        !*/

    public:

        byte_orderer (        
        );
        /*!
            ensures                
                - #*this is properly initialized
            throws
                - std::bad_alloc
        !*/

        virtual ~byte_orderer (
        );
        /*!
            ensures
                - any resources associated with *this have been released
        !*/

        bool host_is_big_endian (
        ) const;
        /*!
            ensures
                - if (the host computer is a big endian machine) then
                    - returns true
                - else
                    - returns false
        !*/

        bool host_is_little_endian (
        ) const;
        /*!
            ensures
                - if (the host computer is a little endian machine) then
                    - returns true
                - else
                    - returns false
        !*/

        template <
            typename T
            >
        void host_to_network (
            T& item
        ) const;
        /*!
            ensures
                - #item == the value of item converted from host byte order 
                  to network byte order.
        !*/

        template <
            typename T
            >
        void network_to_host (
            T& item
        ) const;
        /*!
            ensures
                - #item == the value of item converted from network byte order
                  to host byte order.
        !*/

        template <
            typename T
            >
        void host_to_big (
            T& item
        ) const;
        /*!
            ensures
                - #item == the value of item converted from host byte order 
                  to big endian byte order.
        !*/

        template <
            typename T
            >
        void big_to_host (
            T& item
        ) const;
        /*!
            ensures
                - #item == the value of item converted from big endian byte order
                  to host byte order.
        !*/

        template <
            typename T
            >
        void host_to_little (
            T& item
        ) const;
        /*!
            ensures
                - #item == the value of item converted from host byte order 
                  to little endian byte order.
        !*/

        template <
            typename T
            >
        void little_to_host (
            T& item
        ) const;
        /*!
            ensures
                - #item == the value of item converted from little endian byte order
                  to host byte order.
        !*/

    };    
}

#endif // DLIB_BYTE_ORDEREr_ABSTRACT_