string_format.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2009 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 may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00031 
00032 #pragma once
00033 
00034 #include "../api_core.h"
00035 #include <vector>
00036 #include "string_types.h"
00037 
00041 class CL_API_CORE CL_TempStringFormat
00042 {
00045 
00046 public:
00047 
00051         CL_TempStringFormat(const CL_StringRef &format_string);
00052 
00053         ~CL_TempStringFormat();
00054 
00058 
00059 public:
00060         const CL_TempString &get_result() const;
00061 
00065 
00066 public:
00067 
00072         void set_arg(int index, const CL_StringRef &text);
00073 
00079         void set_arg(int index, int value, int min_length = 0);
00080 
00086         void set_arg(int index, unsigned int value, int min_length = 0);
00087 
00092         void set_arg(int index, float value);
00093 
00098         void set_arg(int index, double value);
00099 
00103 
00104 private:
00105 
00111         void create_arg(int index, int start, int length);
00112 
00113         CL_TempString string;
00114 
00115         struct ArgPosition
00116         {
00117                 ArgPosition() : start(0), length(0) { }
00118                 ArgPosition(int s, int l) : start(s), length(l) {}
00119                 int start;
00120                 int length;
00121         };
00122 
00123         std::vector<ArgPosition> args;
00125 };
00126 
00127 template <class Arg1>
00128 CL_TempString cl_format(const CL_StringRef &format, Arg1 arg1)
00129 { CL_TempStringFormat f(format); f.set_arg(1, arg1); return f.get_result(); }
00130 
00131 template <class Arg1, class Arg2>
00132 CL_TempString cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2)
00133 { CL_TempStringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); return f.get_result(); }
00134 
00135 template <class Arg1, class Arg2, class Arg3>
00136 CL_TempString cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
00137 { CL_TempStringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); return f.get_result(); }
00138 
00139 template <class Arg1, class Arg2, class Arg3, class Arg4>
00140 CL_TempString cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
00141 { CL_TempStringFormat 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(); }
00142 
00143 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
00144 CL_TempString cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
00145 { CL_TempStringFormat 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(); }
00146 
00147 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
00148 CL_TempString cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
00149 { CL_TempStringFormat 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(); }
00150 
00151 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
00152 CL_TempString cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
00153 { CL_TempStringFormat 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(); }
00154 

Generated on Thu Dec 3 02:39:32 2009 for ClanLib by  doxygen 1.4.6