(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 karl   1.7.4.1 // Build the functions in this file ONLY in debug mode.
 39 mike   1.1     #if defined(PEGASUS_DEBUG)
 40                
 41                struct Ind
 42                {
 43                    Ind(Uint32 n_) : n(n_) { }
 44                    Uint32 n;
 45                };
 46                
 47                inline PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const Ind& x)
 48                {
 49                    for (Uint32 i = 0; i < x.n; i++)
 50                        os << "    ";
 51                
 52                    return os;
 53                }
 54                
 55                static const char* _typeStrings[] =
 56                {
 57                    "boolean",
 58                    "uint8",
 59                    "sint8",
 60 mike   1.1         "uint16",
 61                    "sint16",
 62                    "uint32",
 63                    "sint32",
 64                    "uint64",
 65                    "sint64",
 66                    "real32",
 67                    "real64",
 68                    "char16",
 69                    "string",
 70                    "datetime",
 71                    "reference",
 72                    "object",
 73                    "instance"
 74                };
 75                
 76 kumpf  1.2     template<class T>
 77 mike   1.7     struct Print
 78 mike   1.1     {
 79 mike   1.7         static void func(ostream& os, const T& x)
 80                    {
 81                        os << x;
 82                    }
 83                };
 84 mike   1.1     
 85 kumpf  1.2     PEGASUS_TEMPLATE_SPECIALIZATION
 86 mike   1.7     struct Print<Boolean>
 87 mike   1.1     {
 88 mike   1.7         static void func(ostream& os, const Boolean& x)
 89                    {
 90                        os << (x ? "true" : "false");
 91                    }
 92                };
 93 mike   1.1     
 94 kumpf  1.2     PEGASUS_TEMPLATE_SPECIALIZATION
 95 mike   1.7     struct Print<Uint64>
 96 mike   1.1     {
 97 mike   1.7         static void func(ostream& os, const Uint64& x)
 98                    {
 99                        char buf[32];
100                        sprintf(buf, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", x);
101                        os << buf;
102                    }
103                };
104 mike   1.1     
105 kumpf  1.2     PEGASUS_TEMPLATE_SPECIALIZATION
106 mike   1.7     struct Print<Sint64>
107 mike   1.1     {
108 mike   1.7         static void func(ostream& os, const Sint64& x)
109                    {
110                        char buf[32];
111                        sprintf(buf, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", x);
112                        os << buf;
113                    }
114                };
115 mike   1.1     
116 kumpf  1.2     PEGASUS_TEMPLATE_SPECIALIZATION
117 mike   1.7     struct Print<Uint16>
118 mike   1.1     {
119 mike   1.7         static void func(ostream& os, const Char16& x)
120                    {
121                        os << Uint16(x);
122                    }
123                };
124 mike   1.1     
125 kumpf  1.2     PEGASUS_TEMPLATE_SPECIALIZATION
126 mike   1.7     struct Print<CIMDateTime>
127 mike   1.1     {
128 mike   1.7         static void func(ostream& os, const CIMDateTime& x)
129                    {
130                        os << x.toString();
131                    }
132                };
133 mike   1.1     
134                template<class T>
135                struct PrintArray
136                {
137                    static void print(ostream& os, const CIMValue& cv)
138                    {
139                        Array<T> a;
140                        cv.get(a);
141                
142                        os << "{ ";
143                
144                        for (Uint32 i = 0; i < a.size(); i++)
145                        {
146 mike   1.7                 const T& r = a[i];
147                            Print<T>::func(os, r);
148 mike   1.1     
149                            if (i + 1 != a.size())
150                                os << ", ";
151                            else
152                                os << " ";
153                        }
154                
155                        os << "}" << endl;
156                    }
157                };
158                
159                template<class T>
160                struct PrintScalar
161                {
162                    static void print(ostream& os, const CIMValue& cv)
163                    {
164                        T x;
165                        cv.get(x);
166 mike   1.7             Print<T>::func(os, x);
167 mike   1.1             os << endl;
168                    }
169                };
170                
171                void _printValue(ostream& os, const CIMValue& cv, Uint32 n)
172                {
173                    os << Ind(n) << "value=";
174                
175                    if (cv.isNull())
176                    {
177                        os << "null" << endl;
178                    }
179 kumpf  1.2         else if (cv.isArray())
180 mike   1.1         {
181                        switch (cv.getType())
182                        {
183                            case CIMTYPE_BOOLEAN:
184                            {
185                                PrintArray<Boolean>::print(os, cv);
186                                break;
187                            }
188                            case CIMTYPE_UINT8:
189                            {
190                                PrintArray<Uint8>::print(os, cv);
191                                break;
192                            }
193                            case CIMTYPE_SINT8:
194                            {
195                                PrintArray<Sint8>::print(os, cv);
196                                break;
197                            }
198                            case CIMTYPE_UINT16:
199                            {
200                                PrintArray<Uint16>::print(os, cv);
201 mike   1.1                     break;
202                            }
203                            case CIMTYPE_SINT16:
204                            {
205                                PrintArray<Sint16>::print(os, cv);
206                                break;
207                            }
208                            case CIMTYPE_UINT32:
209                            {
210                                PrintArray<Uint32>::print(os, cv);
211                                break;
212                            }
213                            case CIMTYPE_SINT32:
214                            {
215                                PrintArray<Sint32>::print(os, cv);
216                                break;
217                            }
218                            case CIMTYPE_UINT64:
219                            {
220                                PrintArray<Uint64>::print(os, cv);
221                                break;
222 mike   1.1                 }
223                            case CIMTYPE_SINT64:
224                            {
225                                PrintArray<Sint64>::print(os, cv);
226                                break;
227                            }
228                            case CIMTYPE_REAL32:
229                            {
230                                PrintArray<Real32>::print(os, cv);
231                                break;
232                            }
233                            case CIMTYPE_REAL64:
234                            {
235                                PrintArray<Real64>::print(os, cv);
236                                break;
237                            }
238                            case CIMTYPE_CHAR16:
239                            {
240                                PrintArray<Char16>::print(os, cv);
241                                break;
242                            }
243 mike   1.1                 case CIMTYPE_STRING:
244                            {
245                                PrintArray<String>::print(os, cv);
246                                break;
247                            }
248                            case CIMTYPE_DATETIME:
249                            {
250                                PrintArray<CIMDateTime>::print(os, cv);
251                                break;
252                            }
253                            default:
254                                break;
255                        }
256                    }
257                    else
258                    {
259                        switch (cv.getType())
260                        {
261                            case CIMTYPE_BOOLEAN:
262                            {
263                                PrintScalar<Boolean>::print(os, cv);
264 mike   1.1                     break;
265                            }
266                            case CIMTYPE_UINT8:
267                            {
268                                PrintScalar<Uint8>::print(os, cv);
269                                break;
270                            }
271                            case CIMTYPE_SINT8:
272                            {
273                                PrintScalar<Sint8>::print(os, cv);
274                                break;
275                            }
276                            case CIMTYPE_UINT16:
277                            {
278                                PrintScalar<Uint16>::print(os, cv);
279                                break;
280                            }
281                            case CIMTYPE_SINT16:
282                            {
283                                PrintScalar<Sint16>::print(os, cv);
284                                break;
285 mike   1.1                 }
286                            case CIMTYPE_UINT32:
287                            {
288                                PrintScalar<Uint32>::print(os, cv);
289                                break;
290                            }
291                            case CIMTYPE_SINT32:
292                            {
293                                PrintScalar<Sint32>::print(os, cv);
294                                break;
295                            }
296                            case CIMTYPE_UINT64:
297                            {
298                                PrintScalar<Uint64>::print(os, cv);
299                                break;
300                            }
301                            case CIMTYPE_SINT64:
302                            {
303                                PrintScalar<Sint64>::print(os, cv);
304                                break;
305                            }
306 mike   1.1                 case CIMTYPE_REAL32:
307                            {
308                                PrintScalar<Real32>::print(os, cv);
309                                break;
310                            }
311                            case CIMTYPE_REAL64:
312                            {
313                                PrintScalar<Real64>::print(os, cv);
314                                break;
315                            }
316                            case CIMTYPE_CHAR16:
317                            {
318                                PrintScalar<Char16>::print(os, cv);
319                                break;
320                            }
321                            case CIMTYPE_STRING:
322                            {
323                                PrintScalar<String>::print(os, cv);
324                                break;
325                            }
326                            case CIMTYPE_DATETIME:
327 mike   1.1                 {
328                                PrintScalar<CIMDateTime>::print(os, cv);
329                                break;
330                            }
331                            default:
332                                break;
333                        }
334                    }
335                }
336                
337                void PrintValue(PEGASUS_STD(ostream)& os, const CIMValue& x, Uint32 n)
338                {
339                    os << Ind(n) << "CIMValue" << endl;
340                    os << Ind(n) << "{" << endl;
341                    os << Ind(n) << "    type=" << _typeStrings[x.getType()];
342                
343                    if (x.isArray())
344                        os << "[]";
345                
346                    os << endl;
347                
348 mike   1.1         if (x.getType() == CIMTYPE_INSTANCE)
349                    {
350                        if (x.isArray())
351                        {
352                            Array<CIMInstance> a;
353                            x.get(a);
354                
355                            for (Uint32 i = 0; i < a.size(); i++)
356                            {
357                                CIMInstance ci = a[i];
358                
359                                if (ci.isUninitialized())
360                                {
361                                    os << Ind(n) << "null" << endl;
362                                }
363                                else
364                                {
365                                    PrintInstance(os, ci, n + 1);
366                                }
367                            }
368                        }
369 mike   1.1             else
370                        {
371                            CIMInstance ci;
372                            x.get(ci);
373                
374                            if (ci.isUninitialized())
375                            {
376                                os << Ind(n) << "null" << endl;
377                            }
378                            else
379                            {
380                                PrintInstance(os, ci, n + 1);
381                            }
382                        }
383                    }
384                    else if (x.getType() == CIMTYPE_OBJECT)
385                    {
386                        if (x.isArray())
387                        {
388                            Array<CIMObject> a;
389                            x.get(a);
390 mike   1.1     
391                            for (Uint32 i = 0; i < a.size(); i++)
392                            {
393                                if (a[i].isInstance())
394                                {
395                                    CIMInstance ci(a[i]);
396                
397                                    if (ci.isUninitialized())
398                                    {
399                                        os << Ind(n) << "null" << endl;
400                                    }
401                                    else
402                                    {
403                                        PrintInstance(os, ci, n + 1);
404                                    }
405                                }
406                            }
407                        }
408                        else
409                        {
410                            CIMObject co;
411 mike   1.1                 x.get(co);
412                
413                            if (co.isInstance())
414                            {
415                                CIMInstance ci(co);
416                
417                                if (ci.isUninitialized())
418                                {
419                                    os << Ind(n) << "null" << endl;
420                                }
421                                else
422                                {
423                                    PrintInstance(os, ci, n + 1);
424                                }
425                            }
426                        }
427                    }
428                    else
429                    {
430                        _printValue(os, x, n + 1);
431                    }
432 mike   1.1     
433                    os << Ind(n) << "}" << endl;
434                }
435                
436                static const char* _keyTypes[] =
437                {
438                    "boolean",
439                    "string",
440                    "numeric",
441                    "reference",
442                };
443                
444                void _printKeyBinding(
445 kumpf  1.6         PEGASUS_STD(ostream)& os,
446                    const CIMKeyBinding& x,
447 mike   1.1         Uint32 n)
448                {
449                    os << Ind(n) << "CIMKeyBinding" << endl;
450                    os << Ind(n) << "{" << endl;
451                
452                    os << Ind(n) << "    name=" << x.getName().getString() << endl;
453                    os << Ind(n) << "    type=" << _keyTypes[x.getType()] << endl;
454                    os << Ind(n) << "    value=" << x.getValue() << endl;
455                
456                    os << Ind(n) << "}" << endl;
457                }
458                
459                void PrintObjectPath(
460 kumpf  1.6         PEGASUS_STD(ostream)& os,
461                    const CIMObjectPath& x,
462 mike   1.1         Uint32 n)
463                {
464                    os << Ind(n) << "CIMObjectPath" << endl;
465                    os << Ind(n) << "{" << endl;
466                    os << Ind(n) << "    host=" << x.getHost() << endl;
467                    os << Ind(n) << "    namespace=" << x.getNameSpace().getString() << endl;
468                    os << Ind(n) << "    classname=" << x.getClassName().getString() << endl;
469                    os << Ind(n) << "    keyBindings" << endl;
470                    os << Ind(n) << "    {" << endl;
471                
472                    const Array<CIMKeyBinding>& a = x.getKeyBindings();
473                
474                    for (Uint32 i = 0; i < a.size(); i++)
475                    {
476                        _printKeyBinding(os, a[i], n + 2);
477                    }
478                
479                    os << Ind(n) << "    }" << endl;
480                
481                    os << Ind(n) << "}" << endl;
482                }
483 mike   1.1     
484                void PrintProperty(
485 kumpf  1.6         PEGASUS_STD(ostream)& os,
486                    const CIMConstProperty& x,
487 mike   1.1         Uint32 n)
488                {
489                    os << Ind(n) << "CIMProperty" << endl;
490                    os << Ind(n) << "{" << endl;
491                    os << Ind(n) << "    name=" << x.getName().getString() << endl;
492 karl   1.7.4.1 
493                    os << Ind(n) << "    CIMType=" << cimTypeToString(x.getType());
494                    if (x.isArray())
495                    {
496                        os << " Array";
497                        if (x.getArraySize() != 0)
498                        {
499                            os << ", size=" << x.getArraySize();
500                        }
501                        os << endl;
502                    }
503                    else
504                    {
505                        os << " Scalar" << endl;
506                    }
507                
508 mike   1.1         PrintValue(os, x.getValue(), n + 1);
509                    os << Ind(n) << "}" << endl;
510                }
511                
512                void PrintInstance(
513 kumpf  1.6         PEGASUS_STD(ostream)& os,
514                    const CIMConstInstance& x,
515 mike   1.1         Uint32 n)
516                {
517                    os << Ind(n) << "CIMInstance" << endl;
518                    os << Ind(n) << "{" << endl;
519                    os << Ind(n) << "    class=" << x.getClassName().getString() << endl;
520                
521                    PrintObjectPath(os, x.getPath(), n + 1);
522                
523                    for (Uint32 i = 0; i < x.getPropertyCount(); i++)
524                    {
525                        PrintProperty(os, x.getProperty(i), n + 1);
526                    }
527                
528                    os << Ind(n) << "}" << endl;
529                }
530                
531                void PEGASUS_COMMON_LINKAGE PrintQualifierDecl(
532 kumpf  1.6         PEGASUS_STD(ostream)& os,
533                    const CIMConstQualifierDecl& x,
534 mike   1.1         Uint32 n)
535                {
536                    os << Ind(n) << "CIMQualifierDecl" << endl;
537                    os << Ind(n) << "{" << endl;
538                    os << Ind(n) << "    name=" << x.getName().getString() << endl;
539                    os << Ind(n) << "    type=" << _typeStrings[x.getType()] << endl;
540                    os << Ind(n) << "    scope=" << x.getScope().toString() << endl;
541                    os << Ind(n) << "    flavor=" << x.getFlavor().toString() << endl;
542                    os << Ind(n) << "    arraySize=" << x.getArraySize() << endl;
543                    PrintValue(os, x.getValue(), n + 1);
544                    os << Ind(n) << "}" << endl;
545                }
546                
547 mike   1.7     PEGASUS_COMMON_LINKAGE void PrintParamValue(
548                    PEGASUS_STD(ostream)& os,
549                    const CIMParamValue& x,
550                    Uint32 n)
551                {
552                    os << Ind(n) << "CIMParamValue" << endl;
553                    os << Ind(n) << "{" << endl;
554                    os << Ind(n) << "    name=" << x.getParameterName() << endl;
555                    PrintValue(os, x.getValue(), n + 1);
556                    os << Ind(n) << "}" << endl;
557                }
558                
559                PEGASUS_COMMON_LINKAGE void PrintParamValueArray(
560                    PEGASUS_STD(ostream)& os,
561                    const Array<CIMParamValue>& x,
562                    Uint32 n)
563                {
564                    os << Ind(n) << "Array<CIMParamValue>" << endl;
565                    os << Ind(n) << "{" << endl;
566                
567                    for (Uint32 i = 0; i < x.size(); i++)
568 mike   1.7         {
569                        PrintParamValue(os, x[i], n + 1);
570                    }
571                
572                    os << Ind(n) << "}" << endl;
573                }
574                
575 karl   1.7.4.1 #else  // compile empty functions
576                
577                
578                PEGASUS_COMMON_LINKAGE void PrintValue(
579                    PEGASUS_STD(ostream)& os,
580                    const CIMValue& x,
581                    Uint32 n)
582                {
583                }
584                
585                PEGASUS_COMMON_LINKAGE void PrintProperty(
586                    PEGASUS_STD(ostream)& os,
587                    const CIMConstProperty& x,
588                    Uint32 n)
589                {
590                }
591                
592                PEGASUS_COMMON_LINKAGE void PrintObjectPath(
593                    PEGASUS_STD(ostream)& os,
594                    const CIMObjectPath& x,
595                    Uint32 n)
596 karl   1.7.4.1 {
597                }
598                
599                PEGASUS_COMMON_LINKAGE void PrintInstance(
600                    PEGASUS_STD(ostream)& os,
601                    const CIMConstInstance& cimInstance,
602                    Uint32 n)
603                {
604                }
605                
606                PEGASUS_COMMON_LINKAGE void PrintQualifierDecl(
607                    PEGASUS_STD(ostream)& os,
608                    const CIMConstQualifierDecl& x,
609                    Uint32 n)
610                {
611                }
612                
613                PEGASUS_COMMON_LINKAGE void PrintParamValue(
614                    PEGASUS_STD(ostream)& os, 
615                    const CIMParamValue& x, 
616                    Uint32 n)
617 karl   1.7.4.1 {
618                }
619                
620                PEGASUS_COMMON_LINKAGE void PrintParamValueArray(
621                    PEGASUS_STD(ostream)& os, 
622                    const Array<CIMParamValue>& x, 
623                    Uint32 n)
624                {
625                }
626 mike   1.1     #endif /* defined(PEGASUS_DEBUG) */
627                
628                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2