1 /* 2 3 Copyright (c) 2002-2008, Yauheni Akhotnikau 4 Copyright (c) 2008-2016, The SObjectizer Project 5 All rights reserved. 6 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions are met: 9 10 - Redistributions of source code must retain the above copyright notice, this 11 list of conditions and the following disclaimer. 12 13 - Redistributions in binary form must reproduce the above copyright notice, this 14 list of conditions and the following disclaimer in the documentation and/or 15 other materials provided with the distribution. 16 17 - The name of the author may not be used to endorse or promote products derived 18 from this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 23 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 25 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 28 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 29 OF SUCH DAMAGE. 30 31 */ 32 33 /*! 34 \file 35 \brief Sizes of binary representations of main types. 36 */ 37 38 #if !defined( OESS_2_IO_BIN_DATA_SIZE_HPP ) 39 #define OESS_2_IO_BIN_DATA_SIZE_HPP 40 41 #include <oess_2/defs/h/types.hpp> 42 43 namespace oess_2 { 44 45 namespace io { 46 47 /*! 48 \brief A tool for getting size of binary representation. 49 50 Usage example: 51 \code 52 int char_size = oess_2::io::bin_data_size_t< oess_2::char_t >::image_size; 53 int int_size = oess_2::io::bin_data_size_t< oess_2::int_t >::image_size; 54 int double_size = oess_2::io::bin_data_size_t< oess_2::double_t >::image_size; 55 \endcode 56 57 \attention 58 The correct value is defined only for oess_2::char_t, oess_2::schar_t, 59 oess_2::uchar_t, oess_2::short_t, oess_2::ushort_t, oess_2::int_t, 60 oess_2::uint_t, oess_2::long_t, oess_2::ulong_t, oess_2::single_t, 61 oess_2::double_t. 62 */ 63 template< class Type > 64 struct bin_data_size_t { 65 }; 66 67 template<> 68 struct bin_data_size_t< oess_2::char_t > 69 { 70 enum 71 { 72 image_size = 1 73 }; 74 }; 75 76 template<> 77 struct bin_data_size_t< oess_2::schar_t > 78 { 79 enum 80 { 81 image_size = 1 82 }; 83 }; 84 85 template<> 86 struct bin_data_size_t< oess_2::uchar_t > 87 { 88 enum 89 { 90 image_size = 1 91 }; 92 }; 93 94 template<> 95 struct bin_data_size_t< oess_2::short_t > 96 { 97 enum 98 { 99 image_size = 2 100 }; 101 }; 102 103 template<> 104 struct bin_data_size_t< oess_2::ushort_t > 105 { 106 enum 107 { 108 image_size = 2 109 }; 110 }; 111 112 template<> 113 struct bin_data_size_t< oess_2::int_t > 114 { 115 enum 116 { 117 image_size = 4 118 }; 119 }; 120 121 template<> 122 struct bin_data_size_t< oess_2::uint_t > 123 { 124 enum 125 { 126 image_size = 4 127 }; 128 }; 129 130 template<> 131 struct bin_data_size_t< oess_2::long_t > 132 { 133 enum 134 { 135 image_size = 8 136 }; 137 }; 138 139 template<> 140 struct bin_data_size_t< oess_2::ulong_t > 141 { 142 enum 143 { 144 image_size = 8 145 }; 146 }; 147 148 template<> 149 struct bin_data_size_t< oess_2::single_t > 150 { 151 enum 152 { 153 image_size = 4 154 }; 155 }; 156 157 template<> 158 struct bin_data_size_t< oess_2::double_t > 159 { 160 enum 161 { 162 image_size = 8 163 }; 164 }; 165 166 template<> 167 struct bin_data_size_t< bool > 168 { 169 enum 170 { 171 image_size = 172 oess_2::io::bin_data_size_t< oess_2::uchar_t >::image_size 173 }; 174 }; 175 176 } /* namespace io */ 177 178 } /* namespace oess_2 */ 179 180 #endif 181