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

  1 martin 1.4 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.5 //
  3 martin 1.4 // Licensed to The Open Group (TOG) under one or more contributor license
  4            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5            // this work for additional information regarding copyright ownership.
  6            // Each contributor licenses this file to you under the OpenPegasus Open
  7            // Source License; you may not use this file except in compliance with the
  8            // License.
  9 martin 1.5 //
 10 martin 1.4 // Permission is hereby granted, free of charge, to any person obtaining a
 11            // copy of this software and associated documentation files (the "Software"),
 12            // to deal in the Software without restriction, including without limitation
 13            // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14            // and/or sell copies of the Software, and to permit persons to whom the
 15            // Software is furnished to do so, subject to the following conditions:
 16 martin 1.5 //
 17 martin 1.4 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.5 //
 20 martin 1.4 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.5 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.4 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23            // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24            // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25            // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26            // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.5 //
 28 martin 1.4 //////////////////////////////////////////////////////////////////////////
 29 mike   1.1 //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #include "Print.h"
 33            
 34            PEGASUS_USING_STD;
 35            
 36            PEGASUS_NAMESPACE_BEGIN
 37            
 38            #if defined(PEGASUS_DEBUG)
 39            
 40            struct Ind
 41            {
 42                Ind(Uint32 n_) : n(n_) { }
 43                Uint32 n;
 44            };
 45            
 46            inline PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const Ind& x)
 47            {
 48                for (Uint32 i = 0; i < x.n; i++)
 49                    os << "    ";
 50 mike   1.1 
 51                return os;
 52            }
 53            
 54            static const char* _typeStrings[] =
 55            {
 56                "boolean",
 57                "uint8",
 58                "sint8",
 59                "uint16",
 60                "sint16",
 61                "uint32",
 62                "sint32",
 63                "uint64",
 64                "sint64",
 65                "real32",
 66                "real64",
 67                "char16",
 68                "string",
 69                "datetime",
 70                "reference",
 71 mike   1.1     "object",
 72                "instance"
 73            };
 74            
 75 kumpf  1.2 template<class T>
 76 thilo.boehm 1.6.4.1 struct Print
 77 mike        1.1     {
 78 thilo.boehm 1.6.4.1     static void func(ostream& os, const T& x)
 79                         {
 80                             os << x;
 81                         }
 82                     };
 83 mike        1.1     
 84 kumpf       1.2     PEGASUS_TEMPLATE_SPECIALIZATION
 85 thilo.boehm 1.6.4.1 struct Print<Boolean>
 86 mike        1.1     {
 87 thilo.boehm 1.6.4.1     static void func(ostream& os, const Boolean& x)
 88                         {
 89                             os << (x ? "true" : "false");
 90                         }
 91                     };
 92 mike        1.1     
 93 kumpf       1.2     PEGASUS_TEMPLATE_SPECIALIZATION
 94 thilo.boehm 1.6.4.1 struct Print<Uint64>
 95 mike        1.1     {
 96 thilo.boehm 1.6.4.1     static void func(ostream& os, const Uint64& x)
 97                         {
 98                             char buf[32];
 99                             sprintf(buf, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", x);
100                             os << buf;
101                         }
102                     };
103 mike        1.1     
104 kumpf       1.2     PEGASUS_TEMPLATE_SPECIALIZATION
105 thilo.boehm 1.6.4.1 struct Print<Sint64>
106 mike        1.1     {
107 thilo.boehm 1.6.4.1     static void func(ostream& os, const Sint64& x)
108                         {
109                             char buf[32];
110                             sprintf(buf, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", x);
111                             os << buf;
112                         }
113                     };
114 mike        1.1     
115 kumpf       1.2     PEGASUS_TEMPLATE_SPECIALIZATION
116 thilo.boehm 1.6.4.1 struct Print<Uint16>
117 mike        1.1     {
118 thilo.boehm 1.6.4.1     static void func(ostream& os, const Char16& x)
119                         {
120                             os << Uint16(x);
121                         }
122                     };
123 mike        1.1     
124 kumpf       1.2     PEGASUS_TEMPLATE_SPECIALIZATION
125 thilo.boehm 1.6.4.1 struct Print<CIMDateTime>
126 mike        1.1     {
127 thilo.boehm 1.6.4.1     static void func(ostream& os, const CIMDateTime& x)
128                         {
129                             os << x.toString();
130                         }
131                     };
132 mike        1.1     
133                     template<class T>
134                     struct PrintArray
135                     {
136                         static void print(ostream& os, const CIMValue& cv)
137                         {
138                             Array<T> a;
139                             cv.get(a);
140                     
141                             os << "{ ";
142                     
143                             for (Uint32 i = 0; i < a.size(); i++)
144                             {
145 thilo.boehm 1.6.4.1             const T& r = a[i];
146                                 Print<T>::func(os, r);
147 mike        1.1     
148                                 if (i + 1 != a.size())
149                                     os << ", ";
150                                 else
151                                     os << " ";
152                             }
153                     
154                             os << "}" << endl;
155                         }
156                     };
157                     
158                     template<class T>
159                     struct PrintScalar
160                     {
161                         static void print(ostream& os, const CIMValue& cv)
162                         {
163                             T x;
164                             cv.get(x);
165 thilo.boehm 1.6.4.1         Print<T>::func(os, x);
166 mike        1.1             os << endl;
167                         }
168                     };
169                     
170                     void _printValue(ostream& os, const CIMValue& cv, Uint32 n)
171                     {
172                         os << Ind(n) << "value=";
173                     
174                         if (cv.isNull())
175                         {
176                             os << "null" << endl;
177                         }
178 kumpf       1.2         else if (cv.isArray())
179 mike        1.1         {
180                             switch (cv.getType())
181                             {
182                                 case CIMTYPE_BOOLEAN:
183                                 {
184                                     PrintArray<Boolean>::print(os, cv);
185                                     break;
186                                 }
187                                 case CIMTYPE_UINT8:
188                                 {
189                                     PrintArray<Uint8>::print(os, cv);
190                                     break;
191                                 }
192                                 case CIMTYPE_SINT8:
193                                 {
194                                     PrintArray<Sint8>::print(os, cv);
195                                     break;
196                                 }
197                                 case CIMTYPE_UINT16:
198                                 {
199                                     PrintArray<Uint16>::print(os, cv);
200 mike        1.1                     break;
201                                 }
202                                 case CIMTYPE_SINT16:
203                                 {
204                                     PrintArray<Sint16>::print(os, cv);
205                                     break;
206                                 }
207                                 case CIMTYPE_UINT32:
208                                 {
209                                     PrintArray<Uint32>::print(os, cv);
210                                     break;
211                                 }
212                                 case CIMTYPE_SINT32:
213                                 {
214                                     PrintArray<Sint32>::print(os, cv);
215                                     break;
216                                 }
217                                 case CIMTYPE_UINT64:
218                                 {
219                                     PrintArray<Uint64>::print(os, cv);
220                                     break;
221 mike        1.1                 }
222                                 case CIMTYPE_SINT64:
223                                 {
224                                     PrintArray<Sint64>::print(os, cv);
225                                     break;
226                                 }
227                                 case CIMTYPE_REAL32:
228                                 {
229                                     PrintArray<Real32>::print(os, cv);
230                                     break;
231                                 }
232                                 case CIMTYPE_REAL64:
233                                 {
234                                     PrintArray<Real64>::print(os, cv);
235                                     break;
236                                 }
237                                 case CIMTYPE_CHAR16:
238                                 {
239                                     PrintArray<Char16>::print(os, cv);
240                                     break;
241                                 }
242 mike        1.1                 case CIMTYPE_STRING:
243                                 {
244                                     PrintArray<String>::print(os, cv);
245                                     break;
246                                 }
247                                 case CIMTYPE_DATETIME:
248                                 {
249                                     PrintArray<CIMDateTime>::print(os, cv);
250                                     break;
251                                 }
252                                 default:
253                                     break;
254                             }
255                         }
256                         else
257                         {
258                             switch (cv.getType())
259                             {
260                                 case CIMTYPE_BOOLEAN:
261                                 {
262                                     PrintScalar<Boolean>::print(os, cv);
263 mike        1.1                     break;
264                                 }
265                                 case CIMTYPE_UINT8:
266                                 {
267                                     PrintScalar<Uint8>::print(os, cv);
268                                     break;
269                                 }
270                                 case CIMTYPE_SINT8:
271                                 {
272                                     PrintScalar<Sint8>::print(os, cv);
273                                     break;
274                                 }
275                                 case CIMTYPE_UINT16:
276                                 {
277                                     PrintScalar<Uint16>::print(os, cv);
278                                     break;
279                                 }
280                                 case CIMTYPE_SINT16:
281                                 {
282                                     PrintScalar<Sint16>::print(os, cv);
283                                     break;
284 mike        1.1                 }
285                                 case CIMTYPE_UINT32:
286                                 {
287                                     PrintScalar<Uint32>::print(os, cv);
288                                     break;
289                                 }
290                                 case CIMTYPE_SINT32:
291                                 {
292                                     PrintScalar<Sint32>::print(os, cv);
293                                     break;
294                                 }
295                                 case CIMTYPE_UINT64:
296                                 {
297                                     PrintScalar<Uint64>::print(os, cv);
298                                     break;
299                                 }
300                                 case CIMTYPE_SINT64:
301                                 {
302                                     PrintScalar<Sint64>::print(os, cv);
303                                     break;
304                                 }
305 mike        1.1                 case CIMTYPE_REAL32:
306                                 {
307                                     PrintScalar<Real32>::print(os, cv);
308                                     break;
309                                 }
310                                 case CIMTYPE_REAL64:
311                                 {
312                                     PrintScalar<Real64>::print(os, cv);
313                                     break;
314                                 }
315                                 case CIMTYPE_CHAR16:
316                                 {
317                                     PrintScalar<Char16>::print(os, cv);
318                                     break;
319                                 }
320                                 case CIMTYPE_STRING:
321                                 {
322                                     PrintScalar<String>::print(os, cv);
323                                     break;
324                                 }
325                                 case CIMTYPE_DATETIME:
326 mike        1.1                 {
327                                     PrintScalar<CIMDateTime>::print(os, cv);
328                                     break;
329                                 }
330                                 default:
331                                     break;
332                             }
333                         }
334                     }
335                     
336                     void PrintValue(PEGASUS_STD(ostream)& os, const CIMValue& x, Uint32 n)
337                     {
338                         os << Ind(n) << "CIMValue" << endl;
339                         os << Ind(n) << "{" << endl;
340                         os << Ind(n) << "    type=" << _typeStrings[x.getType()];
341                     
342                         if (x.isArray())
343                             os << "[]";
344                     
345                         os << endl;
346                     
347 mike        1.1         if (x.getType() == CIMTYPE_INSTANCE)
348                         {
349                             if (x.isArray())
350                             {
351                                 Array<CIMInstance> a;
352                                 x.get(a);
353                     
354                                 for (Uint32 i = 0; i < a.size(); i++)
355                                 {
356                                     CIMInstance ci = a[i];
357                     
358                                     if (ci.isUninitialized())
359                                     {
360                                         os << Ind(n) << "null" << endl;
361                                     }
362                                     else
363                                     {
364                                         PrintInstance(os, ci, n + 1);
365                                     }
366                                 }
367                             }
368 mike        1.1             else
369                             {
370                                 CIMInstance ci;
371                                 x.get(ci);
372                     
373                                 if (ci.isUninitialized())
374                                 {
375                                     os << Ind(n) << "null" << endl;
376                                 }
377                                 else
378                                 {
379                                     PrintInstance(os, ci, n + 1);
380                                 }
381                             }
382                         }
383                         else if (x.getType() == CIMTYPE_OBJECT)
384                         {
385                             if (x.isArray())
386                             {
387                                 Array<CIMObject> a;
388                                 x.get(a);
389 mike        1.1     
390                                 for (Uint32 i = 0; i < a.size(); i++)
391                                 {
392                                     if (a[i].isInstance())
393                                     {
394                                         CIMInstance ci(a[i]);
395                     
396                                         if (ci.isUninitialized())
397                                         {
398                                             os << Ind(n) << "null" << endl;
399                                         }
400                                         else
401                                         {
402                                             PrintInstance(os, ci, n + 1);
403                                         }
404                                     }
405                                 }
406                             }
407                             else
408                             {
409                                 CIMObject co;
410 mike        1.1                 x.get(co);
411                     
412                                 if (co.isInstance())
413                                 {
414                                     CIMInstance ci(co);
415                     
416                                     if (ci.isUninitialized())
417                                     {
418                                         os << Ind(n) << "null" << endl;
419                                     }
420                                     else
421                                     {
422                                         PrintInstance(os, ci, n + 1);
423                                     }
424                                 }
425                             }
426                         }
427                         else
428                         {
429                             _printValue(os, x, n + 1);
430                         }
431 mike        1.1     
432                         os << Ind(n) << "}" << endl;
433                     }
434                     
435                     static const char* _keyTypes[] =
436                     {
437                         "boolean",
438                         "string",
439                         "numeric",
440                         "reference",
441                     };
442                     
443                     void _printKeyBinding(
444 kumpf       1.6         PEGASUS_STD(ostream)& os,
445                         const CIMKeyBinding& x,
446 mike        1.1         Uint32 n)
447                     {
448                         os << Ind(n) << "CIMKeyBinding" << endl;
449                         os << Ind(n) << "{" << endl;
450                     
451                         os << Ind(n) << "    name=" << x.getName().getString() << endl;
452                         os << Ind(n) << "    type=" << _keyTypes[x.getType()] << endl;
453                         os << Ind(n) << "    value=" << x.getValue() << endl;
454                     
455                         os << Ind(n) << "}" << endl;
456                     }
457                     
458                     void PrintObjectPath(
459 kumpf       1.6         PEGASUS_STD(ostream)& os,
460                         const CIMObjectPath& x,
461 mike        1.1         Uint32 n)
462                     {
463                         os << Ind(n) << "CIMObjectPath" << endl;
464                         os << Ind(n) << "{" << endl;
465                         os << Ind(n) << "    host=" << x.getHost() << endl;
466                         os << Ind(n) << "    namespace=" << x.getNameSpace().getString() << endl;
467                         os << Ind(n) << "    classname=" << x.getClassName().getString() << endl;
468                         os << Ind(n) << "    keyBindings" << endl;
469                         os << Ind(n) << "    {" << endl;
470                     
471                         const Array<CIMKeyBinding>& a = x.getKeyBindings();
472                     
473                         for (Uint32 i = 0; i < a.size(); i++)
474                         {
475                             _printKeyBinding(os, a[i], n + 2);
476                         }
477                     
478                         os << Ind(n) << "    }" << endl;
479                     
480                         os << Ind(n) << "}" << endl;
481                     }
482 mike        1.1     
483                     void PrintProperty(
484 kumpf       1.6         PEGASUS_STD(ostream)& os,
485                         const CIMConstProperty& x,
486 mike        1.1         Uint32 n)
487                     {
488                         os << Ind(n) << "CIMProperty" << endl;
489                         os << Ind(n) << "{" << endl;
490                         os << Ind(n) << "    name=" << x.getName().getString() << endl;
491                         PrintValue(os, x.getValue(), n + 1);
492                         os << Ind(n) << "}" << endl;
493                     }
494                     
495                     void PrintInstance(
496 kumpf       1.6         PEGASUS_STD(ostream)& os,
497                         const CIMConstInstance& x,
498 mike        1.1         Uint32 n)
499                     {
500                         os << Ind(n) << "CIMInstance" << endl;
501                         os << Ind(n) << "{" << endl;
502                         os << Ind(n) << "    class=" << x.getClassName().getString() << endl;
503                     
504                         PrintObjectPath(os, x.getPath(), n + 1);
505                     
506                         for (Uint32 i = 0; i < x.getPropertyCount(); i++)
507                         {
508                             PrintProperty(os, x.getProperty(i), n + 1);
509                         }
510                     
511                         os << Ind(n) << "}" << endl;
512                     }
513                     
514                     void PEGASUS_COMMON_LINKAGE PrintQualifierDecl(
515 kumpf       1.6         PEGASUS_STD(ostream)& os,
516                         const CIMConstQualifierDecl& x,
517 mike        1.1         Uint32 n)
518                     {
519                         os << Ind(n) << "CIMQualifierDecl" << endl;
520                         os << Ind(n) << "{" << endl;
521                         os << Ind(n) << "    name=" << x.getName().getString() << endl;
522                         os << Ind(n) << "    type=" << _typeStrings[x.getType()] << endl;
523                         os << Ind(n) << "    scope=" << x.getScope().toString() << endl;
524                         os << Ind(n) << "    flavor=" << x.getFlavor().toString() << endl;
525                         os << Ind(n) << "    arraySize=" << x.getArraySize() << endl;
526                         PrintValue(os, x.getValue(), n + 1);
527                         os << Ind(n) << "}" << endl;
528                     }
529                     
530 thilo.boehm 1.6.4.1 PEGASUS_COMMON_LINKAGE void PrintParamValue(
531                         PEGASUS_STD(ostream)& os,
532                         const CIMParamValue& x,
533                         Uint32 n)
534                     {
535                         os << Ind(n) << "CIMParamValue" << endl;
536                         os << Ind(n) << "{" << endl;
537                         os << Ind(n) << "    name=" << x.getParameterName() << endl;
538                         PrintValue(os, x.getValue(), n + 1);
539                         os << Ind(n) << "}" << endl;
540                     }
541                     
542                     PEGASUS_COMMON_LINKAGE void PrintParamValueArray(
543                         PEGASUS_STD(ostream)& os,
544                         const Array<CIMParamValue>& x,
545                         Uint32 n)
546                     {
547                         os << Ind(n) << "Array<CIMParamValue>" << endl;
548                         os << Ind(n) << "{" << endl;
549                     
550                         for (Uint32 i = 0; i < x.size(); i++)
551 thilo.boehm 1.6.4.1     {
552                             PrintParamValue(os, x[i], n + 1);
553                         }
554                     
555                         os << Ind(n) << "}" << endl;
556                     }
557                     
558 mike        1.1     #endif /* defined(PEGASUS_DEBUG) */
559                     
560                     PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2