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

string_format.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00029 #ifndef header_string_format
00030 #define header_string_format
00031 
00032 #include <vector>
00033 
00034 class CL_StringFormat
00035 {
00037 public:
00038         CL_StringFormat(const CL_String &format_string);
00039         
00040         ~CL_StringFormat();
00041 
00043 public:
00044         const CL_String &get_result() const;
00045 
00047 public:
00048         void set_arg(int index, const CL_StringA &text);
00049 
00050         void set_arg(int index, const CL_StringW &text);
00051         
00052         void set_arg(int index, int value, int min_length = 0);
00053         
00054         void set_arg(int index, double value);
00055 
00057 private:
00058         void create_arg(int index, int start, int length);
00059 
00060         CL_String string;
00061         
00062         struct ArgPosition
00063         {
00064                 ArgPosition() : start(0), length(0) { }
00065                 ArgPosition(int s, int l) : start(s), length(l) {}
00066                 int start;
00067                 int length;
00068         };
00069         
00070         std::vector<ArgPosition> args;
00071 };
00072 
00073 template <class Arg1>
00074 CL_String cl_format(const CL_String &format, Arg1 arg1)
00075 { CL_StringFormat f(format); f.set_arg(1, arg1); return f.get_result(); }
00076 
00077 template <class Arg1, class Arg2>
00078 CL_String cl_format(const CL_String &format, Arg1 arg1, Arg2 arg2)
00079 { CL_StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); return f.get_result(); }
00080 
00081 template <class Arg1, class Arg2, class Arg3>
00082 CL_String cl_format(const CL_String &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
00083 { CL_StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); return f.get_result(); }
00084 
00085 template <class Arg1, class Arg2, class Arg3, class Arg4>
00086 CL_String cl_format(const CL_String &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
00087 { CL_StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); f.set_arg(4, arg4); return f.get_result(); }
00088 
00089 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
00090 CL_String cl_format(const CL_String &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
00091 { CL_StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); f.set_arg(4, arg4); f.set_arg(5, arg5); return f.get_result(); }
00092 
00093 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
00094 CL_String cl_format(const CL_String &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
00095 { CL_StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); f.set_arg(4, arg4); f.set_arg(5, arg5); f.set_arg(6, arg6); return f.get_result(); }
00096 
00097 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
00098 CL_String cl_format(const CL_String &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
00099 { CL_StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); f.set_arg(4, arg4); f.set_arg(5, arg5); f.set_arg(6, arg6); f.set_arg(7, arg7); return f.get_result(); }
00100 
00101 #endif

Generated on Sat Feb 19 22:51:16 2005 for npcore by  doxygen 1.4.1