00001 /* 00002 * WiPal - A library and a set of tools to manipulate wireless traces. 00003 * Copyright (C) 2007 Universite Pierre et Marie Curie - Paris 6 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00018 * MA 02110-1301 USA 00019 * 00020 * Author: Thomas Claveirole <thomas.claveirole@lip6.fr> 00021 */ 00022 #ifndef TOOL_SI_HH_ 00023 # define TOOL_SI_HH_ 00024 00025 # include <cstdlib> 00026 # include <string> 00027 # include <ostream> 00028 00029 namespace tool 00030 { 00031 00033 namespace internals 00034 { 00035 00050 template <size_t OneUnitInBits> 00051 struct SI_unit 00052 { 00054 SI_unit(size_t); 00055 00057 template <size_t OneRHSUnitInBits> 00058 SI_unit(const SI_unit<OneRHSUnitInBits>&); 00059 00061 size_t bits() const; 00062 00064 size_t bytes() const; 00065 00067 static std::string abbrev(); 00068 00069 private: 00070 size_t bits_; 00071 00073 static const char* abbrev_; 00074 }; 00075 00077 template <size_t OneUnitInBits> 00078 std::ostream& 00079 operator << (std::ostream&, const SI_unit<OneUnitInBits>&); 00080 00081 } // End of namespace internals. 00082 00084 typedef internals::SI_unit<1> b; 00085 00087 typedef internals::SI_unit<1000> kb; 00088 00090 typedef internals::SI_unit<1024> Kib; 00091 00093 typedef internals::SI_unit<1000000> Mb; 00094 00096 typedef internals::SI_unit<1048576> Mib; 00097 00098 00100 typedef internals::SI_unit<8> B; 00101 00103 typedef internals::SI_unit<8000> kB; 00104 00106 typedef internals::SI_unit<8192> KiB; 00107 00109 typedef internals::SI_unit<8000000> MB; 00110 00112 typedef internals::SI_unit<8388608> MiB; 00113 00114 } // End of namespace tool. 00115 00116 # include "si.hxx" 00117 00118 #endif // ! TOOL_SI_HH_