Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

bytedisp.hpp

Go to the documentation of this file.
00001 /* 00002 * wxChecksums 00003 * Copyright (C) 2003-2004 Julien Couot 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /** 00021 * \file bytedisp.hpp 00022 * Smart byte displayer. 00023 */ 00024 00025 #ifndef INC_BYTEDISP_HPP 00026 #define INC_BYTEDISP_HPP 00027 00028 //--------------------------------------------------------------------------- 00029 // For compilers that support precompilation, includes "wx.h". 00030 #include <wx/wxprec.h> 00031 00032 #ifdef __BORLANDC__ 00033 #pragma hdrstop 00034 #endif 00035 00036 #ifndef WX_PRECOMP 00037 // Include your minimal set of headers here, or wx.h 00038 #include <wx/wx.h> 00039 #endif 00040 //--------------------------------------------------------------------------- 00041 00042 00043 /** 00044 * Displays a byte size in a range of [1,1024[ with a suffix. 00045 * 00046 * <B>Important:</B> Call initStatic() (only once is needed) before using this 00047 * class. It is needed for i18n. 00048 * 00049 * The suffix could be: 00050 * <table border="1"> 00051 * <tr><td>Name</td><td>Abbr</td><td>Factor</td></tr> 00052 * <tr><td>kilo</td><td>K</td><td>2<sup>10</sup> = 1024</td></tr> 00053 * <tr><td>mega</td><td>M</td><td>2<sup>20</sup> = 1&nbsp;048&nbsp;576</td></tr> 00054 * <tr><td>giga</td><td>G</td><td>2<sup>30</sup> = 1&nbsp;073&nbsp;741&nbsp;824</td></tr> 00055 * <tr><td>tera</td><td>T</td><td>2<sup>40</sup> = 1&nbsp;099&nbsp;511&nbsp;627&nbsp;776</td></tr> 00056 * <tr><td>peta</td><td>P</td><td>2<sup>50</sup> = 1&nbsp;125&nbsp;899&nbsp;906&nbsp;842&nbsp;624</td></tr> 00057 * <tr><td>exa</td><td>E</td><td>2<sup>60</sup> = 1&nbsp;152&nbsp;921&nbsp;504&nbsp;606&nbsp;846&nbsp;976</td></tr> 00058 * <tr><td>zetta</td><td>Z</td><td>2<sup>70</sup> = 1&nbsp;180&nbsp;591&nbsp;620&nbsp;717&nbsp;411&nbsp;303&nbsp;424</td></tr> 00059 * <tr><td>yotta</td><td>Y</td><td>2<sup>80</sup> = 1&nbsp;208&nbsp;925&nbsp;819&nbsp;614&nbsp;629&nbsp;174&nbsp;706&nbsp;176</td></tr> 00060 * </table> 00061 * Source: <A HREF="http://www.wikipedia.org/">Wikipedia</A>. 00062 * 00063 * This class manages only positives integers and should not be used for precise 00064 * work with sizes since it uses internally doubles values. Use it only for 00065 * display sizes in xB. 00066 */ 00067 class BytesDisplayer 00068 { 00069 public: 00070 /// List of the units. 00071 enum Units 00072 { 00073 byte = 0, 00074 kilo, 00075 mega, 00076 giga, 00077 tera, 00078 peta, 00079 exa, 00080 zetta, 00081 yotta 00082 }; 00083 00084 /// Units format types 00085 enum UnitsFormat 00086 { 00087 None, 00088 Short, 00089 Long 00090 }; 00091 00092 protected: 00093 // These static arrays should be work with the Units enum. 00094 static wxString long_units[9]; ///< Name of the units (long format). 00095 static wxString short_units[9]; ///< Name of the units (short format). 00096 00097 /// Internal type of size values. 00098 typedef double bytesize_type; 00099 00100 bytesize_type size; ///< Value of the size. 00101 Units unit; ///< Current unit. 00102 00103 // Clones the source instance in this instance. 00104 void clone(const BytesDisplayer& source); 00105 00106 // Normalizes the value. 00107 void normalize(); 00108 00109 public: 00110 // Initializes the static part of the class. 00111 static void initStatic(); 00112 00113 // Constructor. 00114 BytesDisplayer(); 00115 00116 // Copy constructor. 00117 BytesDisplayer(const BytesDisplayer& source); 00118 00119 // Assignment operator. 00120 BytesDisplayer& operator=(const BytesDisplayer& source); 00121 00122 // Assignment operator. 00123 BytesDisplayer& operator=(const double value); 00124 00125 // Assignment operator. 00126 BytesDisplayer& operator=(const long value); 00127 00128 // Assignment operator. 00129 BytesDisplayer& operator=(const unsigned long value); 00130 00131 // Constructor with a double size. 00132 BytesDisplayer(const double value); 00133 00134 // Constructor with a long size. 00135 BytesDisplayer(const long value); 00136 00137 // Constructor with a long size. 00138 BytesDisplayer(const unsigned long value); 00139 00140 // Operator += 00141 BytesDisplayer& operator+=(const BytesDisplayer& a); 00142 00143 // Gets the size as a double. 00144 double toDouble(const Units u = byte) const; 00145 00146 // Gets the size as a string. 00147 wxString toString(const Units u, const UnitsFormat uf = Short) const; 00148 00149 // Gets the size as a string. 00150 wxString toString(const UnitsFormat uf = Short) const; 00151 }; 00152 //--------------------------------------------------------------------------- 00153 00154 #endif // INC_BYTEDISP_HPP

Generated on Sun May 30 13:37:43 2004 for wxChecksums by doxygen 1.3.7