(file) Return to Formatter.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2