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

  1 karl  1.21 //%2005////////////////////////////////////////////////////////////////////////
  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 mike  1.11 //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 kumpf 1.13 // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 mike  1.11 // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18            // 
 19 kumpf 1.13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 mike  1.11 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 kumpf 1.13 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 mike  1.11 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 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 denise.eckstein 1.18 /** <I><B>Experimental Interface</B></I><BR>
 44 mike            1.11     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                          int total = 4;
 63                          int count = 2;
 64                          String name = "Output"
 65 mike            1.11     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                      
 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 karl            1.20 
143 mike            1.11     /**	 Format function for the formatter
144                          */
145                          static String format(
146                      	const String& formatString,
147 karl            1.20 	const Arg& arg0 = Formatter::DEFAULT_ARG,
148                      	const Arg& arg1 = Formatter::DEFAULT_ARG,
149                      	const Arg& arg2 = Formatter::DEFAULT_ARG,
150                      	const Arg& arg3 = Formatter::DEFAULT_ARG,
151                      	const Arg& arg4 = Formatter::DEFAULT_ARG,
152                      	const Arg& arg5 = Formatter::DEFAULT_ARG,
153                      	const Arg& arg6 = Formatter::DEFAULT_ARG,
154                      	const Arg& arg7 = Formatter::DEFAULT_ARG,
155                      	const Arg& arg8 = Formatter::DEFAULT_ARG,
156                      	const Arg& arg9 = Formatter::DEFAULT_ARG);
157                      
158                          static const Formatter::Arg DEFAULT_ARG;
159 mike            1.11 };
160                      
161                      PEGASUS_NAMESPACE_END
162 chuck           1.17 
163                      #endif /*  PEGASUS_USE_EXPERIMENTAL_INTERFACES */
164 mike            1.11 
165                      #endif /* Pegasus_Formatter_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2