00001 #ifndef Formatter_CPP 00002 #define Formatter_CPP 00003 00008 #include "common.hpp" 00009 #include <fstream> 00010 00012 class Formatter 00013 { 00014 public: 00015 00018 template <class T> static void IntToStringBack( 00019 T n, char* buffer, std::streamsize& pos ); 00020 00023 template <class T> static void IntToStringFront( 00024 T n, char* buffer, std::streamsize& pos ); 00025 00028 static void SupportToStringBack( 00029 counter_t support, char* buffer, std::streamsize& pos ); 00030 00033 template <typename InputIterator> static void ItemsetToStringBack( 00034 InputIterator first, InputIterator last, char* buffer, 00035 std::streamsize& pos ); 00036 00037 00038 private: 00039 }; 00049 template <class T> inline void Formatter::IntToStringBack( 00050 T n, char* buffer, std::streamsize& pos ) 00051 { 00052 if( n == 0 ) 00053 buffer[--pos] = '0'; 00054 else 00055 { 00056 while( n > 0 ) 00057 { 00058 buffer[--pos] = n % 10 + '0'; 00059 n /= 10; 00060 } 00061 } 00062 } 00063 00073 template <class T> inline void Formatter::IntToStringFront( 00074 T n, char* buffer, std::streamsize& pos ) 00075 { 00076 if( n == 0 ) 00077 buffer[pos++] = '0'; 00078 else 00079 { 00080 size_t length=0; 00081 { 00082 register T n2(n); 00083 while(n2) 00084 { 00085 length++; 00086 n2 /= 10; 00087 } 00088 } 00089 char* buffer2 = buffer + pos + length -1; 00090 while(n) 00091 { 00092 *buffer2-- = '0' + n%10; 00093 n /= 10; 00094 } 00095 pos += length; 00096 } 00097 } 00106 inline void Formatter::SupportToStringBack( 00107 counter_t support, char* buffer, std::streamsize& pos ) 00108 { 00109 buffer[--pos] = '\n'; 00110 buffer[--pos] = ')'; 00111 00112 while (support > 0) 00113 { 00114 buffer[--pos] = support % 10 + '0'; 00115 support /= 10; 00116 } 00117 buffer[--pos] = '('; 00118 } 00119 00120 template <typename InputIterator> inline void Formatter::ItemsetToStringBack( 00121 InputIterator first, InputIterator last, char* buffer, 00122 std::streamsize& pos ) 00123 { 00124 while(last != first) 00125 { 00126 buffer[--pos] = ' '; 00127 --last; 00128 IntToStringBack(*last, buffer, pos); 00129 } 00130 } 00131 00132 00133 00134 #endif