00001 // Copyright (C) 2001, Compaq Computer Corporation 00002 00003 // This file is part of Vesta. 00004 00005 // Vesta is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 00010 // Vesta 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 GNU 00013 // Lesser General Public License for more details. 00014 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with Vesta; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 #ifndef _UNITS_H 00020 #define _UNITS_H 00021 00022 #include "Basics.H" 00023 00024 namespace Basics 00025 { 00026 // Format a possibly large value with a unit multiplier to make it 00027 // more readable. If "decimal" is true, base-10 units are used, 00028 // otherwise base-2 units are used 00029 00030 // base-10 base-2 unit suffix 00031 // ------- ------ ----------- 00032 // 10^3 k 00033 // 2^10 K 00034 // 10^6 2^20 M 00035 // 10^9 2^30 G 00036 // 10^12 2^40 T 00037 // 10^15 2^50 P 00038 // 10^18 2^60 E 00039 00040 // The lowercase k is used for deciaml by convention (as K also 00041 // means degress Kelvin). 00042 Text FormatUnitVal(Basics::uint64 val, bool decimal = false) throw (); 00043 00044 // Exception thrown if parsing a value with units fails 00045 struct ParseUnitValFailure 00046 { 00047 // The input value 00048 Text val; 00049 // A message about what went wrong 00050 Text emsg; 00051 }; 00052 00053 // Parse a value with a unit multiplier. This must be of the form 00054 // [0-9]+[kKmMgGtTpPeE]. Anything else will result in 00055 // ParseUnitValFailure being thrown. 00056 Basics::uint64 ParseUnitVal(const char *val, bool decimal = false) 00057 throw (ParseUnitValFailure); 00058 inline Basics::uint64 ParseUnitVal(const Text &val, bool decimal = false) 00059 throw (ParseUnitValFailure) 00060 { 00061 return ParseUnitVal(val.cchars(), decimal); 00062 } 00063 } 00064 00065 #endif