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