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