1 karl 1.21 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.11 //
|
3 karl 1.19 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.16 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.19 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.21 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.11 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.13 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.11 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
|
19 kumpf 1.13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.11 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.13 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.11 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_Formatter_h
33 #define Pegasus_Formatter_h
34
35 #include <Pegasus/Common/Config.h>
36 #include <Pegasus/Common/String.h>
|
37 kumpf 1.14 #include <Pegasus/Common/Linkage.h>
|
38 kumpf 1.23 #ifdef PEGASUS_INTERNALONLY
|
39 mike 1.22 #include <Pegasus/Common/StrLit.h>
|
40 kumpf 1.23 #endif
|
41 mike 1.11
|
42 chuck 1.17 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
43
|
44 mike 1.11 PEGASUS_NAMESPACE_BEGIN
45
|
46 denise.eckstein 1.18 /** <I><B>Experimental Interface</B></I><BR>
|
47 mike 1.11 Formatter is a class to build formatted strings from
48 strings that contain variable defintions. The
49 variable definitions in the strings are of the form
50 $<int>
51
52 where <int> is a single digit integer (0 - 9).
53
54 The variable subsituted may be String, Boolean Integer, Unsigned Integer
55 or real.
56
57 The format subsitution may be escaped by preceding the
58 $ with a \
59
60 usage:
61 Formatter::format (FormatString, variable0,.., variable9)
62
63 Example:
64 <pre>
65 int total = 4;
66 int count = 2;
67 String name = "Output"
68 mike 1.11 String output = Formatter::format(
69 "total $0 average $1 on $2",
70 total,
71 total/count,
72 name);
73 produces the string
74
75 "total 4 average 2 on Output"
76
77 </pre>
78 */
79 class PEGASUS_COMMON_LINKAGE Formatter
80 {
81 public:
82
83 class Arg
84 {
85 public:
86
|
87 mike 1.22 enum Type { VOIDT, STRING, CSTRLIT, BOOLEAN, INTEGER,
88 UINTEGER, LINTEGER, ULINTEGER, REAL };
|
89 mike 1.11
|
90 mike 1.12 Arg() : _type(VOIDT)
|
91 mike 1.11 {
92 }
93
94 Arg(const String& x) : _string(x), _type(STRING)
95 {
96 }
97
98 Arg(const char* x) : _string(x), _type(STRING)
99 {
100 }
101
|
102 kumpf 1.23 #ifdef PEGASUS_INTERNALONLY
|
103 mike 1.22 Arg(const StrLit& x) : _cstrlit(&x), _type(CSTRLIT)
104 {
105 }
|
106 kumpf 1.23 #endif
|
107 mike 1.22
|
108 mike 1.11 Arg(Boolean x) : _boolean(x), _type(BOOLEAN)
109 {
110 }
111
112 Arg(Sint32 x) : _integer(x), _type(INTEGER)
113 {
114 }
115
116 Arg(Uint32 x) : _uinteger(x), _type(UINTEGER)
117 {
118 }
119
120 Arg(Sint64 x) : _lInteger(x), _type(LINTEGER)
121 {
122 }
123
124 Arg(Uint64 x) : _lUInteger(x), _type(ULINTEGER)
125 {
126 }
127 Arg(Real64 x) : _real(x), _type(REAL)
128 {
129 mike 1.11 }
130
131 String toString() const;
|
132 mike 1.22
133 void appendToString(String& out) const;
|
134 chuck 1.15
135 friend class MessageLoader; //l10n
|
136 mike 1.11
137 private:
138
139 String _string;
140
141 union
142 {
143 Sint32 _integer;
144 Uint32 _uinteger;
145 Real64 _real;
146 int _boolean;
147 Sint64 _lInteger;
148 Uint64 _lUInteger;
|
149 kumpf 1.23 #ifdef PEGASUS_INTERNALONLY
|
150 mike 1.22 const StrLit* _cstrlit;
|
151 kumpf 1.23 #else
152 const void* _unused;
153 #endif
|
154 mike 1.11 };
155
156 Type _type;
157 };
|
158 karl 1.20
|
159 mike 1.11 /** Format function for the formatter
160 */
161 static String format(
162 const String& formatString,
|
163 karl 1.20 const Arg& arg0 = Formatter::DEFAULT_ARG,
164 const Arg& arg1 = Formatter::DEFAULT_ARG,
165 const Arg& arg2 = Formatter::DEFAULT_ARG,
166 const Arg& arg3 = Formatter::DEFAULT_ARG,
167 const Arg& arg4 = Formatter::DEFAULT_ARG,
168 const Arg& arg5 = Formatter::DEFAULT_ARG,
169 const Arg& arg6 = Formatter::DEFAULT_ARG,
170 const Arg& arg7 = Formatter::DEFAULT_ARG,
171 const Arg& arg8 = Formatter::DEFAULT_ARG,
172 const Arg& arg9 = Formatter::DEFAULT_ARG);
173
174 static const Formatter::Arg DEFAULT_ARG;
|
175 mike 1.11 };
176
177 PEGASUS_NAMESPACE_END
|
178 chuck 1.17
179 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
|
180 mike 1.11
181 #endif /* Pegasus_Formatter_h */
|