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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2