ValueLogging.hpp
上传用户:xqtpzdz
上传日期:2022-05-21
资源大小:1764k
文件大小:4k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. /****************License************************************************
  2.  * Vocalocity OpenVXI
  3.  * Copyright (C) 2004-2005 by Vocalocity, Inc. All Rights Reserved.
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  *  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  * Vocalocity, the Vocalocity logo, and VocalOS are trademarks or 
  18.  * registered trademarks of Vocalocity, Inc. 
  19.  * OpenVXI is a trademark of Scansoft, Inc. and used under license 
  20.  * by Vocalocity.
  21.  ***********************************************************************/
  22. #include <iostream>
  23. #include "VXIvalue.h"
  24. static std::basic_ostream<VXIchar>& operator<<(std::basic_ostream<VXIchar>& os,
  25.                                                const VXIValue * val)
  26. {
  27.   if (val == NULL)
  28.     return os << L"NULL";
  29.   VXIchar tmp[256];
  30.   
  31.   switch (VXIValueGetType(val)) {
  32.   case VALUE_BOOLEAN:
  33.     if(VXIBooleanValue(reinterpret_cast<const VXIBoolean*>(val)) == TRUE)
  34.       return os << L"true";
  35.     else
  36.       return os << L"false";
  37.   case VALUE_INTEGER:
  38.     return os << VXIIntegerValue(reinterpret_cast<const VXIInteger*>(val));
  39.   case VALUE_FLOAT: {
  40. #ifdef WIN32
  41.     _snwprintf(tmp, 256, L"%f", VXIFloatValue(reinterpret_cast<const VXIFloat*>(val)));
  42. #else
  43.     swprintf(tmp, 256, L"%f", VXIFloatValue(reinterpret_cast<const VXIFloat*>(val)));
  44. #endif
  45.     return os << tmp;
  46.   }
  47. #if (VXI_CURRENT_VERSION >= 0x00030000)
  48.   case VALUE_DOUBLE:
  49. #ifdef WIN32
  50.     _snwprintf(tmp, 256, L"%f", VXIDoubleValue(reinterpret_cast<const VXIDouble*>(val)));
  51. #else
  52.     swprintf(tmp, 256, L"%f", VXIDoubleValue(reinterpret_cast<const VXIDouble*>(val)));
  53. #endif
  54.     return os << tmp;
  55.   case VALUE_ULONG:
  56.     return os << VXIULongValue(reinterpret_cast<const VXIULong*>(val));
  57. #endif
  58.   case VALUE_STRING:
  59.     return os << VXIStringCStr(reinterpret_cast<const VXIString *>(val));
  60.   case VALUE_VECTOR:
  61.     {
  62.       const VXIVector * v = reinterpret_cast<const VXIVector *>(val);
  63.       const VXIunsigned len = VXIVectorLength(v);
  64.       os << L"{ ";
  65.       for (VXIunsigned i = 0; i < len; ++i) {
  66.         if (i != 0) os << L", ";
  67.         os << VXIVectorGetElement(v, i);
  68.       }
  69.       return os << L" }";
  70.     }
  71.   case VALUE_MAP:
  72.     {
  73.       const VXIMap * m = reinterpret_cast<const VXIMap *>(val);
  74.       const VXIchar * key;
  75.       const VXIValue * value;
  76.       os << L"{ ";
  77.       if (VXIMapNumProperties(m) != 0) {
  78.         VXIMapIterator * i = VXIMapGetFirstProperty(m, &key, &value);
  79.         os << L"(" << key << L", " << value << L")";
  80.         
  81.         while (VXIMapGetNextProperty(i, &key, &value)
  82.                == VXIvalue_RESULT_SUCCESS)
  83.           os << L", (" << key << L", " << value << L")";
  84.         VXIMapIteratorDestroy(&i);
  85.       }
  86.       return os << L" }";
  87.     }
  88.   default:
  89.     break;
  90.   }
  91.   return os << L"(unprintable result)";
  92. }
  93. static std::basic_ostream<VXIchar>& operator<<(std::basic_ostream<VXIchar>& os,
  94.                                                const VXIMap * val)
  95. {
  96.   return os << reinterpret_cast<const VXIValue *>(val);
  97. }