00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <cassert>
00025 #include <string>
00026 #include <sstream>
00027 #include <ios>
00028 #include <iostream>
00029 #include <iomanip>
00030
00031 #include "FormatableString.h"
00032
00033 namespace Aseba
00034 {
00037
00038 void FormatableString::proceedReplace(const std::string &replacement)
00039 {
00040 std::ostringstream search;
00041 search << "%" << this->argLevel;
00042 std::string::size_type pos = this->find(search.str(), 0);
00043 assert(pos != std::string::npos);
00044 this->replace(pos, search.str().length(), replacement);
00045 ++argLevel;
00046 }
00047
00048 FormatableString &FormatableString::arg(int value, int fieldWidth, int base, char fillChar)
00049 {
00050 std::ostringstream oss;
00051 oss << std::setbase(base);
00052 oss.width(fieldWidth);
00053 oss.fill(fillChar);
00054
00055
00056 oss << value;
00057
00058 proceedReplace(oss.str());
00059
00060
00061 return *this;
00062 }
00063
00064 FormatableString &FormatableString::arg(unsigned value, int fieldWidth, int base, char fillChar)
00065 {
00066 std::ostringstream 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 FormatableString &FormatableString::arg(float value, int fieldWidth, int precision, char fillChar)
00081 {
00082 std::ostringstream oss;
00083 oss.precision(precision);
00084 oss.width(fieldWidth);
00085 oss.fill(fillChar);
00086
00087 oss.setf(oss.fixed, oss.floatfield);
00088
00089 oss << value;
00090
00091 proceedReplace(oss.str());
00092
00093
00094 return *this;
00095 }
00096
00097 FormatableString &FormatableString::operator=(const std::string& str)
00098 {
00099 this->assign(str);
00100 this->argLevel = 0;
00101 return (*this);
00102 }
00103
00105 }