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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2