1 mike 1.1 //BEGIN_LICENSE
2 //
3 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 // DEALINGS IN THE SOFTWARE.
19 //
20 //END_LICENSE
21 //BEGIN_HISTORY
22 mike 1.1 //
23 // Author: Mike Brasher
24 //
|
41 karl 1.2 Formatter is a class to build formatted strings from
42 strings that contain variable defintions. The
43 variable definitions in the strings are of the form
44 $<int>
45
46 where <int> is a single digit integer (0 - 9).
47
48 The variable subsituted my be String, Integer, or real.
49
50 The format subsitution may be escaped by preceding the
51 $ with a \
52
53 usage:
54 Formatter::format (FormatString, variable0,.., variable9)
55
56 Example:
57 <pre>
58 int total = 4;
59 int count = 2;
60 String name = "Output"
61 String output = Formatter::format(
62 karl 1.2 "total $0 average $1 on $2",
63 total,
64 total/count,
65 name);
66 produces the string
67
68 "total 4 average 2 on Output"
69
70 </pre>
|
71 mike 1.1 */
72 class PEGASUS_COMMON_LINKAGE Formatter
73 {
74 public:
75
76 class Arg
77 {
78 public:
79
80 enum Type { VOID, STRING, INTEGER, REAL };
81
82 Arg() : _type(VOID)
83 {
84 }
85
86 Arg(const String& x) : _string(x), _type(STRING)
87 {
88 }
89
90 Arg(const char* x) : _string(x), _type(STRING)
91 {
92 mike 1.1 }
93
94 Arg(Sint32 x) : _integer(x), _type(INTEGER)
95 {
96 }
97
98 Arg(Real64 x) : _real(x), _type(REAL)
99 {
100 }
101
102 Type _type;
103
104 String toString() const;
105
106 private:
107
108 String _string;
109
110 union
111 {
112 Sint32 _integer;
113 mike 1.1 Real64 _real;
114 };
115 };
|
118 mike 1.1 static String format(
119 const String& formatString,
120 const Arg& arg0 = Arg(),
121 const Arg& arg1 = Arg(),
122 const Arg& arg2 = Arg(),
123 const Arg& arg3 = Arg(),
124 const Arg& arg4 = Arg(),
125 const Arg& arg5 = Arg(),
126 const Arg& arg6 = Arg(),
127 const Arg& arg7 = Arg(),
128 const Arg& arg8 = Arg(),
129 const Arg& arg9 = Arg());
130 };
131
132 PEGASUS_NAMESPACE_END
133
134 #endif /* Pegasus_Formatter_h */
|