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

  1 mike  1.1 //%2006////////////////////////////////////////////////////////////////////////
  2           //
  3           // 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           // IBM Corp.; EMC Corporation, The Open Group.
  7           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10           // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11           // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12           // EMC Corporation; Symantec Corporation; The Open Group.
 13           //
 14           // Permission is hereby granted, free of charge, to any person obtaining a copy
 15           // 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           // 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           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.1 // 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           // 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           // 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           #include "Print.h"
 35           
 36           PEGASUS_USING_STD;
 37           
 38           PEGASUS_NAMESPACE_BEGIN
 39           
 40           #if defined(PEGASUS_DEBUG)
 41           
 42           struct Ind
 43 mike  1.1 {
 44               Ind(Uint32 n_) : n(n_) { }
 45               Uint32 n;
 46           };
 47           
 48           inline PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const Ind& x)
 49           {
 50               for (Uint32 i = 0; i < x.n; i++)
 51                   os << "    ";
 52           
 53               return os;
 54           }
 55           
 56           static const char* _typeStrings[] =
 57           {
 58               "boolean",
 59               "uint8",
 60               "sint8",
 61               "uint16",
 62               "sint16",
 63               "uint32",
 64 mike  1.1     "sint32",
 65               "uint64",
 66               "sint64",
 67               "real32",
 68               "real64",
 69               "char16",
 70               "string",
 71               "datetime",
 72               "reference",
 73               "object",
 74               "instance"
 75           };
 76           
 77 kumpf 1.2 template<class T>
 78           static void _print(ostream& os, const T& x)
 79 mike  1.1 {
 80 kumpf 1.2     os << x;
 81 mike  1.1 }
 82           
 83 kumpf 1.2 PEGASUS_TEMPLATE_SPECIALIZATION
 84 kumpf 1.3 void _print(ostream& os, const Boolean& x)
 85 mike  1.1 {
 86               os << (x ? "true" : "false");
 87           }
 88           
 89 kumpf 1.2 PEGASUS_TEMPLATE_SPECIALIZATION
 90 kumpf 1.3 void _print(ostream& os, const Uint64& x)
 91 mike  1.1 {
 92               char buf[32];
 93               sprintf(buf, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", x);
 94               os << buf;
 95           }
 96           
 97 kumpf 1.2 PEGASUS_TEMPLATE_SPECIALIZATION
 98 kumpf 1.3 void _print(ostream& os, const Sint64& x)
 99 mike  1.1 {
100               char buf[32];
101               sprintf(buf, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", x);
102               os << buf;
103           }
104           
105 kumpf 1.2 PEGASUS_TEMPLATE_SPECIALIZATION
106 kumpf 1.3 void _print(ostream& os, const Char16& x)
107 mike  1.1 {
108               os << Uint16(x);
109           }
110           
111 kumpf 1.2 PEGASUS_TEMPLATE_SPECIALIZATION
112 kumpf 1.3 void _print(ostream& os, const CIMDateTime& x)
113 mike  1.1 {
114               os << x.toString();
115           }
116           
117           template<class T>
118           struct PrintArray
119           {
120               static void print(ostream& os, const CIMValue& cv)
121               {
122                   Array<T> a;
123                   cv.get(a);
124           
125                   os << "{ ";
126           
127                   for (Uint32 i = 0; i < a.size(); i++)
128                   {
129 kumpf 1.2             _print<T>(os, a[i]);
130 mike  1.1 
131                       if (i + 1 != a.size())
132                           os << ", ";
133                       else
134                           os << " ";
135                   }
136           
137                   os << "}" << endl;
138               }
139           };
140           
141           template<class T>
142           struct PrintScalar
143           {
144               static void print(ostream& os, const CIMValue& cv)
145               {
146                   T x;
147                   cv.get(x);
148 kumpf 1.2         _print<T>(os, x);
149 mike  1.1         os << endl;
150               }
151           };
152           
153           void _printValue(ostream& os, const CIMValue& cv, Uint32 n)
154           {
155               os << Ind(n) << "value=";
156           
157               if (cv.isNull())
158               {
159                   os << "null" << endl;
160               }
161 kumpf 1.2     else if (cv.isArray())
162 mike  1.1     {
163                   switch (cv.getType())
164                   {
165                       case CIMTYPE_BOOLEAN:
166                       {
167                           PrintArray<Boolean>::print(os, cv);
168                           break;
169                       }
170                       case CIMTYPE_UINT8:
171                       {
172                           PrintArray<Uint8>::print(os, cv);
173                           break;
174                       }
175                       case CIMTYPE_SINT8:
176                       {
177                           PrintArray<Sint8>::print(os, cv);
178                           break;
179                       }
180                       case CIMTYPE_UINT16:
181                       {
182                           PrintArray<Uint16>::print(os, cv);
183 mike  1.1                 break;
184                       }
185                       case CIMTYPE_SINT16:
186                       {
187                           PrintArray<Sint16>::print(os, cv);
188                           break;
189                       }
190                       case CIMTYPE_UINT32:
191                       {
192                           PrintArray<Uint32>::print(os, cv);
193                           break;
194                       }
195                       case CIMTYPE_SINT32:
196                       {
197                           PrintArray<Sint32>::print(os, cv);
198                           break;
199                       }
200                       case CIMTYPE_UINT64:
201                       {
202                           PrintArray<Uint64>::print(os, cv);
203                           break;
204 mike  1.1             }
205                       case CIMTYPE_SINT64:
206                       {
207                           PrintArray<Sint64>::print(os, cv);
208                           break;
209                       }
210                       case CIMTYPE_REAL32:
211                       {
212                           PrintArray<Real32>::print(os, cv);
213                           break;
214                       }
215                       case CIMTYPE_REAL64:
216                       {
217                           PrintArray<Real64>::print(os, cv);
218                           break;
219                       }
220                       case CIMTYPE_CHAR16:
221                       {
222                           PrintArray<Char16>::print(os, cv);
223                           break;
224                       }
225 mike  1.1             case CIMTYPE_STRING:
226                       {
227                           PrintArray<String>::print(os, cv);
228                           break;
229                       }
230                       case CIMTYPE_DATETIME:
231                       {
232                           PrintArray<CIMDateTime>::print(os, cv);
233                           break;
234                       }
235                       default:
236                           break;
237                   }
238               }
239               else
240               {
241                   switch (cv.getType())
242                   {
243                       case CIMTYPE_BOOLEAN:
244                       {
245                           PrintScalar<Boolean>::print(os, cv);
246 mike  1.1                 break;
247                       }
248                       case CIMTYPE_UINT8:
249                       {
250                           PrintScalar<Uint8>::print(os, cv);
251                           break;
252                       }
253                       case CIMTYPE_SINT8:
254                       {
255                           PrintScalar<Sint8>::print(os, cv);
256                           break;
257                       }
258                       case CIMTYPE_UINT16:
259                       {
260                           PrintScalar<Uint16>::print(os, cv);
261                           break;
262                       }
263                       case CIMTYPE_SINT16:
264                       {
265                           PrintScalar<Sint16>::print(os, cv);
266                           break;
267 mike  1.1             }
268                       case CIMTYPE_UINT32:
269                       {
270                           PrintScalar<Uint32>::print(os, cv);
271                           break;
272                       }
273                       case CIMTYPE_SINT32:
274                       {
275                           PrintScalar<Sint32>::print(os, cv);
276                           break;
277                       }
278                       case CIMTYPE_UINT64:
279                       {
280                           PrintScalar<Uint64>::print(os, cv);
281                           break;
282                       }
283                       case CIMTYPE_SINT64:
284                       {
285                           PrintScalar<Sint64>::print(os, cv);
286                           break;
287                       }
288 mike  1.1             case CIMTYPE_REAL32:
289                       {
290                           PrintScalar<Real32>::print(os, cv);
291                           break;
292                       }
293                       case CIMTYPE_REAL64:
294                       {
295                           PrintScalar<Real64>::print(os, cv);
296                           break;
297                       }
298                       case CIMTYPE_CHAR16:
299                       {
300                           PrintScalar<Char16>::print(os, cv);
301                           break;
302                       }
303                       case CIMTYPE_STRING:
304                       {
305                           PrintScalar<String>::print(os, cv);
306                           break;
307                       }
308                       case CIMTYPE_DATETIME:
309 mike  1.1             {
310                           PrintScalar<CIMDateTime>::print(os, cv);
311                           break;
312                       }
313                       default:
314                           break;
315                   }
316               }
317           }
318           
319           void PrintValue(PEGASUS_STD(ostream)& os, const CIMValue& x, Uint32 n)
320           {
321               os << Ind(n) << "CIMValue" << endl;
322               os << Ind(n) << "{" << endl;
323               os << Ind(n) << "    type=" << _typeStrings[x.getType()];
324           
325               if (x.isArray())
326                   os << "[]";
327           
328               os << endl;
329           
330 mike  1.1     if (x.getType() == CIMTYPE_INSTANCE)
331               {
332                   if (x.isArray())
333                   {
334                       Array<CIMInstance> a;
335                       x.get(a);
336           
337                       for (Uint32 i = 0; i < a.size(); i++)
338                       {
339                           CIMInstance ci = a[i];
340           
341                           if (ci.isUninitialized())
342                           {
343                               os << Ind(n) << "null" << endl;
344                           }
345                           else
346                           {
347                               PrintInstance(os, ci, n + 1);
348                           }
349                       }
350                   }
351 mike  1.1         else
352                   {
353                       CIMInstance ci;
354                       x.get(ci);
355           
356                       if (ci.isUninitialized())
357                       {
358                           os << Ind(n) << "null" << endl;
359                       }
360                       else
361                       {
362                           PrintInstance(os, ci, n + 1);
363                       }
364                   }
365               }
366               else if (x.getType() == CIMTYPE_OBJECT)
367               {
368                   if (x.isArray())
369                   {
370                       Array<CIMObject> a;
371                       x.get(a);
372 mike  1.1 
373                       for (Uint32 i = 0; i < a.size(); i++)
374                       {
375                           if (a[i].isInstance())
376                           {
377                               CIMInstance ci(a[i]);
378           
379                               if (ci.isUninitialized())
380                               {
381                                   os << Ind(n) << "null" << endl;
382                               }
383                               else
384                               {
385                                   PrintInstance(os, ci, n + 1);
386                               }
387                           }
388                       }
389                   }
390                   else
391                   {
392                       CIMObject co;
393 mike  1.1             x.get(co);
394           
395                       if (co.isInstance())
396                       {
397                           CIMInstance ci(co);
398           
399                           if (ci.isUninitialized())
400                           {
401                               os << Ind(n) << "null" << endl;
402                           }
403                           else
404                           {
405                               PrintInstance(os, ci, n + 1);
406                           }
407                       }
408                   }
409               }
410               else
411               {
412                   _printValue(os, x, n + 1);
413               }
414 mike  1.1 
415               os << Ind(n) << "}" << endl;
416           }
417           
418           static const char* _keyTypes[] =
419           {
420               "boolean",
421               "string",
422               "numeric",
423               "reference",
424           };
425           
426           void _printKeyBinding(
427               PEGASUS_STD(ostream)& os, 
428               const CIMKeyBinding& x, 
429               Uint32 n)
430           {
431               os << Ind(n) << "CIMKeyBinding" << endl;
432               os << Ind(n) << "{" << endl;
433           
434               os << Ind(n) << "    name=" << x.getName().getString() << endl;
435 mike  1.1     os << Ind(n) << "    type=" << _keyTypes[x.getType()] << endl;
436               os << Ind(n) << "    value=" << x.getValue() << endl;
437           
438               os << Ind(n) << "}" << endl;
439           }
440           
441           void PrintObjectPath(
442               PEGASUS_STD(ostream)& os, 
443               const CIMObjectPath& x, 
444               Uint32 n)
445           {
446               os << Ind(n) << "CIMObjectPath" << endl;
447               os << Ind(n) << "{" << endl;
448               os << Ind(n) << "    host=" << x.getHost() << endl;
449               os << Ind(n) << "    namespace=" << x.getNameSpace().getString() << endl;
450               os << Ind(n) << "    classname=" << x.getClassName().getString() << endl;
451               os << Ind(n) << "    keyBindings" << endl;
452               os << Ind(n) << "    {" << endl;
453           
454               const Array<CIMKeyBinding>& a = x.getKeyBindings();
455           
456 mike  1.1     for (Uint32 i = 0; i < a.size(); i++)
457               {
458                   _printKeyBinding(os, a[i], n + 2);
459               }
460           
461               os << Ind(n) << "    }" << endl;
462           
463               os << Ind(n) << "}" << endl;
464           }
465           
466           void PrintProperty(
467               PEGASUS_STD(ostream)& os, 
468               const CIMConstProperty& x, 
469               Uint32 n)
470           {
471               os << Ind(n) << "CIMProperty" << endl;
472               os << Ind(n) << "{" << endl;
473               os << Ind(n) << "    name=" << x.getName().getString() << endl;
474               PrintValue(os, x.getValue(), n + 1);
475               os << Ind(n) << "}" << endl;
476           }
477 mike  1.1 
478           void PrintInstance(
479               PEGASUS_STD(ostream)& os, 
480               const CIMConstInstance& x, 
481               Uint32 n)
482           {
483               os << Ind(n) << "CIMInstance" << endl;
484               os << Ind(n) << "{" << endl;
485               os << Ind(n) << "    class=" << x.getClassName().getString() << endl;
486           
487               PrintObjectPath(os, x.getPath(), n + 1);
488           
489               for (Uint32 i = 0; i < x.getPropertyCount(); i++)
490               {
491                   PrintProperty(os, x.getProperty(i), n + 1);
492               }
493           
494               os << Ind(n) << "}" << endl;
495           }
496           
497           void PEGASUS_COMMON_LINKAGE PrintQualifierDecl(
498 mike  1.1     PEGASUS_STD(ostream)& os, 
499               const CIMConstQualifierDecl& x, 
500               Uint32 n)
501           {
502               os << Ind(n) << "CIMQualifierDecl" << endl;
503               os << Ind(n) << "{" << endl;
504               os << Ind(n) << "    name=" << x.getName().getString() << endl;
505               os << Ind(n) << "    type=" << _typeStrings[x.getType()] << endl;
506               os << Ind(n) << "    scope=" << x.getScope().toString() << endl;
507               os << Ind(n) << "    flavor=" << x.getFlavor().toString() << endl;
508               os << Ind(n) << "    arraySize=" << x.getArraySize() << endl;
509               PrintValue(os, x.getValue(), n + 1);
510               os << Ind(n) << "}" << endl;
511           }
512           
513           #endif /* defined(PEGASUS_DEBUG) */
514           
515           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2