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

  1 martin 1.4 //%LICENSE////////////////////////////////////////////////////////////////
  2            // 
  3            // 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            // 
 10            // 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            // 
 17            // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19            // 
 20            // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21            // 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 mike   1.1 // 
 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            static void _print(ostream& os, const T& x)
 77 mike   1.1 {
 78 kumpf  1.2     os << x;
 79 mike   1.1 }
 80            
 81 kumpf  1.2 PEGASUS_TEMPLATE_SPECIALIZATION
 82 kumpf  1.3 void _print(ostream& os, const Boolean& x)
 83 mike   1.1 {
 84                os << (x ? "true" : "false");
 85            }
 86            
 87 kumpf  1.2 PEGASUS_TEMPLATE_SPECIALIZATION
 88 kumpf  1.3 void _print(ostream& os, const Uint64& x)
 89 mike   1.1 {
 90                char buf[32];
 91                sprintf(buf, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", x);
 92                os << buf;
 93            }
 94            
 95 kumpf  1.2 PEGASUS_TEMPLATE_SPECIALIZATION
 96 kumpf  1.3 void _print(ostream& os, const Sint64& x)
 97 mike   1.1 {
 98                char buf[32];
 99                sprintf(buf, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", x);
100                os << buf;
101            }
102            
103 kumpf  1.2 PEGASUS_TEMPLATE_SPECIALIZATION
104 kumpf  1.3 void _print(ostream& os, const Char16& x)
105 mike   1.1 {
106                os << Uint16(x);
107            }
108            
109 kumpf  1.2 PEGASUS_TEMPLATE_SPECIALIZATION
110 kumpf  1.3 void _print(ostream& os, const CIMDateTime& x)
111 mike   1.1 {
112                os << x.toString();
113            }
114            
115            template<class T>
116            struct PrintArray
117            {
118                static void print(ostream& os, const CIMValue& cv)
119                {
120                    Array<T> a;
121                    cv.get(a);
122            
123                    os << "{ ";
124            
125                    for (Uint32 i = 0; i < a.size(); i++)
126                    {
127 kumpf  1.2             _print<T>(os, a[i]);
128 mike   1.1 
129                        if (i + 1 != a.size())
130                            os << ", ";
131                        else
132                            os << " ";
133                    }
134            
135                    os << "}" << endl;
136                }
137            };
138            
139            template<class T>
140            struct PrintScalar
141            {
142                static void print(ostream& os, const CIMValue& cv)
143                {
144                    T x;
145                    cv.get(x);
146 kumpf  1.2         _print<T>(os, x);
147 mike   1.1         os << endl;
148                }
149            };
150            
151            void _printValue(ostream& os, const CIMValue& cv, Uint32 n)
152            {
153                os << Ind(n) << "value=";
154            
155                if (cv.isNull())
156                {
157                    os << "null" << endl;
158                }
159 kumpf  1.2     else if (cv.isArray())
160 mike   1.1     {
161                    switch (cv.getType())
162                    {
163                        case CIMTYPE_BOOLEAN:
164                        {
165                            PrintArray<Boolean>::print(os, cv);
166                            break;
167                        }
168                        case CIMTYPE_UINT8:
169                        {
170                            PrintArray<Uint8>::print(os, cv);
171                            break;
172                        }
173                        case CIMTYPE_SINT8:
174                        {
175                            PrintArray<Sint8>::print(os, cv);
176                            break;
177                        }
178                        case CIMTYPE_UINT16:
179                        {
180                            PrintArray<Uint16>::print(os, cv);
181 mike   1.1                 break;
182                        }
183                        case CIMTYPE_SINT16:
184                        {
185                            PrintArray<Sint16>::print(os, cv);
186                            break;
187                        }
188                        case CIMTYPE_UINT32:
189                        {
190                            PrintArray<Uint32>::print(os, cv);
191                            break;
192                        }
193                        case CIMTYPE_SINT32:
194                        {
195                            PrintArray<Sint32>::print(os, cv);
196                            break;
197                        }
198                        case CIMTYPE_UINT64:
199                        {
200                            PrintArray<Uint64>::print(os, cv);
201                            break;
202 mike   1.1             }
203                        case CIMTYPE_SINT64:
204                        {
205                            PrintArray<Sint64>::print(os, cv);
206                            break;
207                        }
208                        case CIMTYPE_REAL32:
209                        {
210                            PrintArray<Real32>::print(os, cv);
211                            break;
212                        }
213                        case CIMTYPE_REAL64:
214                        {
215                            PrintArray<Real64>::print(os, cv);
216                            break;
217                        }
218                        case CIMTYPE_CHAR16:
219                        {
220                            PrintArray<Char16>::print(os, cv);
221                            break;
222                        }
223 mike   1.1             case CIMTYPE_STRING:
224                        {
225                            PrintArray<String>::print(os, cv);
226                            break;
227                        }
228                        case CIMTYPE_DATETIME:
229                        {
230                            PrintArray<CIMDateTime>::print(os, cv);
231                            break;
232                        }
233                        default:
234                            break;
235                    }
236                }
237                else
238                {
239                    switch (cv.getType())
240                    {
241                        case CIMTYPE_BOOLEAN:
242                        {
243                            PrintScalar<Boolean>::print(os, cv);
244 mike   1.1                 break;
245                        }
246                        case CIMTYPE_UINT8:
247                        {
248                            PrintScalar<Uint8>::print(os, cv);
249                            break;
250                        }
251                        case CIMTYPE_SINT8:
252                        {
253                            PrintScalar<Sint8>::print(os, cv);
254                            break;
255                        }
256                        case CIMTYPE_UINT16:
257                        {
258                            PrintScalar<Uint16>::print(os, cv);
259                            break;
260                        }
261                        case CIMTYPE_SINT16:
262                        {
263                            PrintScalar<Sint16>::print(os, cv);
264                            break;
265 mike   1.1             }
266                        case CIMTYPE_UINT32:
267                        {
268                            PrintScalar<Uint32>::print(os, cv);
269                            break;
270                        }
271                        case CIMTYPE_SINT32:
272                        {
273                            PrintScalar<Sint32>::print(os, cv);
274                            break;
275                        }
276                        case CIMTYPE_UINT64:
277                        {
278                            PrintScalar<Uint64>::print(os, cv);
279                            break;
280                        }
281                        case CIMTYPE_SINT64:
282                        {
283                            PrintScalar<Sint64>::print(os, cv);
284                            break;
285                        }
286 mike   1.1             case CIMTYPE_REAL32:
287                        {
288                            PrintScalar<Real32>::print(os, cv);
289                            break;
290                        }
291                        case CIMTYPE_REAL64:
292                        {
293                            PrintScalar<Real64>::print(os, cv);
294                            break;
295                        }
296                        case CIMTYPE_CHAR16:
297                        {
298                            PrintScalar<Char16>::print(os, cv);
299                            break;
300                        }
301                        case CIMTYPE_STRING:
302                        {
303                            PrintScalar<String>::print(os, cv);
304                            break;
305                        }
306                        case CIMTYPE_DATETIME:
307 mike   1.1             {
308                            PrintScalar<CIMDateTime>::print(os, cv);
309                            break;
310                        }
311                        default:
312                            break;
313                    }
314                }
315            }
316            
317            void PrintValue(PEGASUS_STD(ostream)& os, const CIMValue& x, Uint32 n)
318            {
319                os << Ind(n) << "CIMValue" << endl;
320                os << Ind(n) << "{" << endl;
321                os << Ind(n) << "    type=" << _typeStrings[x.getType()];
322            
323                if (x.isArray())
324                    os << "[]";
325            
326                os << endl;
327            
328 mike   1.1     if (x.getType() == CIMTYPE_INSTANCE)
329                {
330                    if (x.isArray())
331                    {
332                        Array<CIMInstance> a;
333                        x.get(a);
334            
335                        for (Uint32 i = 0; i < a.size(); i++)
336                        {
337                            CIMInstance ci = a[i];
338            
339                            if (ci.isUninitialized())
340                            {
341                                os << Ind(n) << "null" << endl;
342                            }
343                            else
344                            {
345                                PrintInstance(os, ci, n + 1);
346                            }
347                        }
348                    }
349 mike   1.1         else
350                    {
351                        CIMInstance ci;
352                        x.get(ci);
353            
354                        if (ci.isUninitialized())
355                        {
356                            os << Ind(n) << "null" << endl;
357                        }
358                        else
359                        {
360                            PrintInstance(os, ci, n + 1);
361                        }
362                    }
363                }
364                else if (x.getType() == CIMTYPE_OBJECT)
365                {
366                    if (x.isArray())
367                    {
368                        Array<CIMObject> a;
369                        x.get(a);
370 mike   1.1 
371                        for (Uint32 i = 0; i < a.size(); i++)
372                        {
373                            if (a[i].isInstance())
374                            {
375                                CIMInstance ci(a[i]);
376            
377                                if (ci.isUninitialized())
378                                {
379                                    os << Ind(n) << "null" << endl;
380                                }
381                                else
382                                {
383                                    PrintInstance(os, ci, n + 1);
384                                }
385                            }
386                        }
387                    }
388                    else
389                    {
390                        CIMObject co;
391 mike   1.1             x.get(co);
392            
393                        if (co.isInstance())
394                        {
395                            CIMInstance ci(co);
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                    _printValue(os, x, n + 1);
411                }
412 mike   1.1 
413                os << Ind(n) << "}" << endl;
414            }
415            
416            static const char* _keyTypes[] =
417            {
418                "boolean",
419                "string",
420                "numeric",
421                "reference",
422            };
423            
424            void _printKeyBinding(
425                PEGASUS_STD(ostream)& os, 
426                const CIMKeyBinding& x, 
427                Uint32 n)
428            {
429                os << Ind(n) << "CIMKeyBinding" << endl;
430                os << Ind(n) << "{" << endl;
431            
432                os << Ind(n) << "    name=" << x.getName().getString() << endl;
433 mike   1.1     os << Ind(n) << "    type=" << _keyTypes[x.getType()] << endl;
434                os << Ind(n) << "    value=" << x.getValue() << endl;
435            
436                os << Ind(n) << "}" << endl;
437            }
438            
439            void PrintObjectPath(
440                PEGASUS_STD(ostream)& os, 
441                const CIMObjectPath& x, 
442                Uint32 n)
443            {
444                os << Ind(n) << "CIMObjectPath" << endl;
445                os << Ind(n) << "{" << endl;
446                os << Ind(n) << "    host=" << x.getHost() << endl;
447                os << Ind(n) << "    namespace=" << x.getNameSpace().getString() << endl;
448                os << Ind(n) << "    classname=" << x.getClassName().getString() << endl;
449                os << Ind(n) << "    keyBindings" << endl;
450                os << Ind(n) << "    {" << endl;
451            
452                const Array<CIMKeyBinding>& a = x.getKeyBindings();
453            
454 mike   1.1     for (Uint32 i = 0; i < a.size(); i++)
455                {
456                    _printKeyBinding(os, a[i], n + 2);
457                }
458            
459                os << Ind(n) << "    }" << endl;
460            
461                os << Ind(n) << "}" << endl;
462            }
463            
464            void PrintProperty(
465                PEGASUS_STD(ostream)& os, 
466                const CIMConstProperty& x, 
467                Uint32 n)
468            {
469                os << Ind(n) << "CIMProperty" << endl;
470                os << Ind(n) << "{" << endl;
471                os << Ind(n) << "    name=" << x.getName().getString() << endl;
472                PrintValue(os, x.getValue(), n + 1);
473                os << Ind(n) << "}" << endl;
474            }
475 mike   1.1 
476            void PrintInstance(
477                PEGASUS_STD(ostream)& os, 
478                const CIMConstInstance& x, 
479                Uint32 n)
480            {
481                os << Ind(n) << "CIMInstance" << endl;
482                os << Ind(n) << "{" << endl;
483                os << Ind(n) << "    class=" << x.getClassName().getString() << endl;
484            
485                PrintObjectPath(os, x.getPath(), n + 1);
486            
487                for (Uint32 i = 0; i < x.getPropertyCount(); i++)
488                {
489                    PrintProperty(os, x.getProperty(i), n + 1);
490                }
491            
492                os << Ind(n) << "}" << endl;
493            }
494            
495            void PEGASUS_COMMON_LINKAGE PrintQualifierDecl(
496 mike   1.1     PEGASUS_STD(ostream)& os, 
497                const CIMConstQualifierDecl& x, 
498                Uint32 n)
499            {
500                os << Ind(n) << "CIMQualifierDecl" << endl;
501                os << Ind(n) << "{" << endl;
502                os << Ind(n) << "    name=" << x.getName().getString() << endl;
503                os << Ind(n) << "    type=" << _typeStrings[x.getType()] << endl;
504                os << Ind(n) << "    scope=" << x.getScope().toString() << endl;
505                os << Ind(n) << "    flavor=" << x.getFlavor().toString() << endl;
506                os << Ind(n) << "    arraySize=" << x.getArraySize() << endl;
507                PrintValue(os, x.getValue(), n + 1);
508                os << Ind(n) << "}" << endl;
509            }
510            
511            #endif /* defined(PEGASUS_DEBUG) */
512            
513            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2