Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <cassert>
00022 #include <string>
00023 #include <sstream>
00024 #include <ios>
00025 #include <iostream>
00026 #include <iomanip>
00027
00028 #include "FormatableString.h"
00029
00030 namespace Aseba
00031 {
00034
00035 template<typename charT>
00036 void BasicFormatableString<charT>::proceedReplace(const S &replacement)
00037 {
00038 typename std::basic_ostringstream<charT> search;
00039 search << "%" << this->argLevel;
00040 typename S::size_type pos = this->find(search.str(), 0);
00041 assert(pos != S::npos);
00042 this->replace(pos, search.str().length(), replacement);
00043 ++argLevel;
00044 }
00045
00046 template<typename charT>
00047 BasicFormatableString<charT> &BasicFormatableString<charT>::arg(int value, int fieldWidth, int base, charT fillChar)
00048 {
00049 typename std::basic_ostringstream<charT> oss;
00050 oss << std::setbase(base);
00051 oss.width(fieldWidth);
00052 oss.fill(fillChar);
00053
00054
00055 oss << value;
00056
00057 proceedReplace(oss.str());
00058
00059
00060 return *this;
00061 }
00062
00063 template<typename charT>
00064 BasicFormatableString<charT> &BasicFormatableString<charT>::arg(unsigned value, int fieldWidth, int base, charT fillChar)
00065 {
00066 typename std::basic_ostringstream<charT> oss;
00067 oss << std::setbase(base);
00068 oss.width(fieldWidth);
00069 oss.fill(fillChar);
00070
00071
00072 oss << value;
00073
00074 proceedReplace(oss.str());
00075
00076
00077 return *this;
00078 }
00079
00080 template<typename charT>
00081 BasicFormatableString<charT> &BasicFormatableString<charT>::arg(float value, int fieldWidth, int precision, charT fillChar)
00082 {
00083 typename std::basic_ostringstream<charT> oss;
00084 oss.precision(precision);
00085 oss.width(fieldWidth);
00086 oss.fill(fillChar);
00087
00088 oss.setf(oss.fixed, oss.floatfield);
00089
00090 oss << value;
00091
00092 proceedReplace(oss.str());
00093
00094
00095 return *this;
00096 }
00097
00098 template<typename charT>
00099 BasicFormatableString<charT> &BasicFormatableString<charT>::operator=(const S& str)
00100 {
00101 this->assign(str);
00102 this->argLevel = 0;
00103 return (*this);
00104 }
00105
00106 template class BasicFormatableString<char>;
00107 template class BasicFormatableString<wchar_t>;
00108
00110 }