00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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_StringFormat
00042 {
00045
00046 public:
00047
00051 CL_StringFormat(const CL_StringRef &format_string);
00052
00053 ~CL_StringFormat();
00054
00058
00059 public:
00060 const CL_String &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
00093 void set_arg(int index, long unsigned int value, int min_length = 0);
00094
00100 void set_arg(int index, long long value, int min_length = 0);
00101
00107 void set_arg(int index, unsigned long long value, int min_length = 0);
00108
00113 void set_arg(int index, float value);
00114
00119 void set_arg(int index, double value);
00120
00124
00125 private:
00126
00132 void create_arg(int index, int start, int length);
00133
00134 CL_String string;
00135
00136 struct ArgPosition
00137 {
00138 ArgPosition() : start(0), length(0) { }
00139 ArgPosition(int s, int l) : start(s), length(l) {}
00140 int start;
00141 int length;
00142 };
00143
00144 std::vector<ArgPosition> args;
00146 };
00147
00148 inline CL_String cl_format(const CL_StringRef &format)
00149 { return format; }
00150
00151 template <class Arg1>
00152 CL_String cl_format(const CL_StringRef &format, Arg1 arg1)
00153 { CL_StringFormat f(format); f.set_arg(1, arg1); return f.get_result(); }
00154
00155 template <class Arg1, class Arg2>
00156 CL_String cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2)
00157 { CL_StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); return f.get_result(); }
00158
00159 template <class Arg1, class Arg2, class Arg3>
00160 CL_String cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
00161 { CL_StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); return f.get_result(); }
00162
00163 template <class Arg1, class Arg2, class Arg3, class Arg4>
00164 CL_String cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
00165 { 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(); }
00166
00167 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
00168 CL_String cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
00169 { 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(); }
00170
00171 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
00172 CL_String cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
00173 { 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(); }
00174
00175 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
00176 CL_String cl_format(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
00177 { 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(); }
00178