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

  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 mike  1.22 #include <Pegasus/Common/StrLit.h>
 41 chuck 1.17 
 42 mike  1.11 PEGASUS_NAMESPACE_BEGIN
 43            
 44 kumpf 1.25 /**
 45 mike  1.11     Formatter is a class to build formatted strings from
 46                strings that contain variable defintions.  The
 47                variable definitions in the strings are of the form
 48                $<int>
 49                
 50                where <int> is a single digit integer (0 - 9).
 51                
 52                The variable subsituted may be String, Boolean Integer, Unsigned Integer
 53                or  real.
 54                
 55                The format subsitution may be escaped by preceding the
 56                $ with a \
 57                
 58                usage:
 59                Formatter::format (FormatString, variable0,.., variable9)
 60                
 61                Example:
 62                <pre>
 63                int total = 4;
 64                int count = 2;
 65                String name = "Output"
 66 mike  1.11     String output = Formatter::format(
 67            			"total $0 average $1 on $2", 
 68            			total,
 69            			total/count,
 70            			name);
 71                produces the string
 72            	 
 73                  "total 4 average 2 on Output"
 74                
 75                </pre>
 76            */
 77            class PEGASUS_COMMON_LINKAGE Formatter
 78            {
 79            public:
 80            
 81                class Arg
 82                {
 83                public:
 84            
 85 mike  1.22 	enum Type { VOIDT, STRING, CSTRLIT, BOOLEAN, INTEGER, 
 86            	    UINTEGER, LINTEGER, ULINTEGER, REAL };
 87 mike  1.11 
 88 mike  1.12 	Arg() : _type(VOIDT)
 89 mike  1.11 	{
 90            	}
 91            
 92            	Arg(const String& x) : _string(x), _type(STRING)
 93            	{
 94            	}
 95            
 96            	Arg(const char* x) : _string(x), _type(STRING)
 97            	{
 98            	}
 99            
100 mike  1.22 	Arg(const StrLit& x) : _cstrlit(&x), _type(CSTRLIT)
101            	{
102            	}
103            
104 mike  1.11 	Arg(Boolean x) : _boolean(x), _type(BOOLEAN)
105            	{
106            	}
107            
108            	Arg(Sint32 x) : _integer(x), _type(INTEGER)
109            	{
110            	}
111            
112            	Arg(Uint32 x) : _uinteger(x), _type(UINTEGER)
113            	{
114            	}
115            
116            	Arg(Sint64 x) : _lInteger(x), _type(LINTEGER)
117            	{
118            	}
119            
120            	Arg(Uint64 x) : _lUInteger(x), _type(ULINTEGER)
121            	{
122            	}
123            	Arg(Real64 x) : _real(x), _type(REAL)
124            	{
125 mike  1.11 	}
126            
127            	String toString() const;
128 mike  1.22 
129            	void appendToString(String& out) const;
130 chuck 1.15 	
131            	friend class MessageLoader;  //l10n
132 mike  1.11 
133                private:
134            
135            	String _string;
136            
137            	union
138            	{
139            	    Sint32 _integer;
140            	    Uint32 _uinteger;
141            	    Real64 _real;
142            	    int _boolean;
143            	    Sint64 _lInteger;
144            	    Uint64 _lUInteger;
145 mike  1.22 	    const StrLit* _cstrlit;
146 mike  1.11 	};
147            
148            	Type _type;
149                };
150 karl  1.20 
151 mike  1.11     /**	 Format function for the formatter
152                */
153                static String format(
154            	const String& formatString,
155 karl  1.20 	const Arg& arg0 = Formatter::DEFAULT_ARG,
156            	const Arg& arg1 = Formatter::DEFAULT_ARG,
157            	const Arg& arg2 = Formatter::DEFAULT_ARG,
158            	const Arg& arg3 = Formatter::DEFAULT_ARG,
159            	const Arg& arg4 = Formatter::DEFAULT_ARG,
160            	const Arg& arg5 = Formatter::DEFAULT_ARG,
161            	const Arg& arg6 = Formatter::DEFAULT_ARG,
162            	const Arg& arg7 = Formatter::DEFAULT_ARG,
163            	const Arg& arg8 = Formatter::DEFAULT_ARG,
164            	const Arg& arg9 = Formatter::DEFAULT_ARG);
165            
166                static const Formatter::Arg DEFAULT_ARG;
167 mike  1.11 };
168            
169            PEGASUS_NAMESPACE_END
170 chuck 1.17 
171 mike  1.11 #endif /* Pegasus_Formatter_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2