FormatableString.h
Go to the documentation of this file.
00001 /*
00002         Aseba - an event-based framework for distributed robot control
00003         Copyright (C) 2007--2012:
00004                 Stephane Magnenat <stephane at magnenat dot net>
00005                 (http://stephane.magnenat.net)
00006                 and other contributors, see authors.txt for details
00007         
00008         This program is free software: you can redistribute it and/or modify
00009         it under the terms of the GNU Lesser General Public License as published
00010         by the Free Software Foundation, version 3 of the License.
00011         
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU Lesser General Public License for more details.
00016         
00017         You should have received a copy of the GNU Lesser General Public License
00018         along with this program. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #ifndef FORMATABLESTRING_H
00022 #define FORMATABLESTRING_H
00023 
00024 #include <string>
00025 #include <sstream>
00026 
00027 namespace Aseba
00028 {
00031         
00038         template<typename charT>
00039         class BasicFormatableString : public std::basic_string<charT>
00040         {
00041                 typedef std::basic_string<charT> S;
00042                 
00043                 private:
00047                         int argLevel;
00048                 
00052                         void proceedReplace(const S &replacement);
00053                         
00054                 public:
00055                         
00056                         BasicFormatableString() : S(), argLevel(0) { }
00063                         BasicFormatableString(const S &s) : S(s), argLevel(0) { }
00064                         
00073                         BasicFormatableString &arg(int value, int fieldWidth = 0, int base = 10, charT fillChar = ' ');
00074                         
00083                         BasicFormatableString &arg(unsigned value, int fieldWidth = 0, int base = 10, charT fillChar = ' ');
00084                         
00093                         BasicFormatableString &arg(float value, int fieldWidth = 0, int precision = 6, charT fillChar = ' ');
00094                         
00100                         template <typename T> BasicFormatableString &arg(const T& value)
00101                         {
00102                                 // transform value into S
00103                                 std::basic_ostringstream<charT> oss;
00104                                 oss << value;
00105                         
00106                                 proceedReplace(oss.str());
00107         
00108                                 // return reference to this so that .arg can proceed further
00109                                 return *this;
00110                         }
00111                         
00117                         BasicFormatableString& operator=(const S& str) ;
00118         };
00119         
00120         typedef BasicFormatableString<char> FormatableString;
00121         typedef BasicFormatableString<wchar_t> WFormatableString;
00122         
00124 }
00125 
00126 #endif // FORMATABLESTRING_H //


aseba
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:46:38