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

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. #ifndef _VALUE_HPP
  23. #define _VALUE_HPP
  24. // Forward declarations, required because we mask out the struct definitions
  25. // in VXIvalue.h with the define below
  26. class VXIValue;
  27. class VXIBoolean;
  28. class VXIInteger;
  29. class VXIFloat;
  30. class VXIPtr;
  31. class VXIString;
  32. class VXIContent;
  33. class VXIMap;
  34. class VXIVector;
  35. class VXIMapIterator;
  36. class VXIContentData;
  37. class VXIDouble;
  38. class VXIULong;
  39. class VXILong;
  40. #define VXIVALUE_REAL_STRUCTS
  41. #include "VXIvalue.h"
  42. #ifndef WIN32
  43. extern "C" struct VXItrdMutex;
  44. #endif
  45. /**
  46.  * VXIValue base class
  47.  */
  48. class VXIValue {
  49.  public:
  50.   // Constructor and destructor
  51.   VXIValue (VXIvalueType t) : type(t) { }
  52.   virtual ~VXIValue( ) { }
  53.   // Get the value type
  54.   VXIvalueType GetType( ) const { return type; }
  55.  private:
  56.   VXIvalueType type;
  57. };
  58. /**
  59.  * Basic VXIValue based data types
  60.  */
  61. class VXIBoolean : public VXIValue {
  62.  public:
  63.   // Constructor and destructor
  64.   VXIBoolean (VXIbool v) : VXIValue (VALUE_BOOLEAN), value(v) { }
  65.   virtual ~VXIBoolean( ) { }
  66.   // Get the value
  67.   VXIbool GetValue( ) const { return value; }
  68.  private:
  69.   VXIbool  value;
  70. };
  71. class VXIInteger : public VXIValue {
  72.  public:
  73.   // Constructor and destructor
  74.   VXIInteger (VXIint32 v) : VXIValue (VALUE_INTEGER), value(v) { }
  75.   virtual ~VXIInteger( ) { }
  76.   // Get the value
  77.   VXIint32 GetValue( ) const { return value; }
  78.  private:
  79.   VXIint32  value;
  80. };
  81. class VXIULong : public VXIValue {
  82.  public:
  83.   // Constructor and destructor
  84.   VXIULong (VXIulong v) : VXIValue (VALUE_ULONG), value(v) { }
  85.   virtual ~VXIULong( ) { }
  86.   // Get the value
  87.   VXIulong GetValue( ) const { return value; }
  88.  private:
  89.   VXIulong  value;
  90. };
  91. class VXILong : public VXIValue {
  92.  public:
  93.   // Constructor and destructor
  94.   VXILong (VXIlong v) : VXIValue (VALUE_LONG), value(v) { }
  95.   virtual ~VXILong( ) { }
  96.   // Get the value
  97.   VXIlong GetValue( ) const { return value; }
  98.  private:
  99.   VXIlong  value;
  100. };
  101. class VXIFloat : public VXIValue {
  102.  public:
  103.   // Constructor and destructor
  104.   VXIFloat (VXIflt32 v) : VXIValue (VALUE_FLOAT), value(v) { }
  105.   virtual ~VXIFloat( ) { }
  106.   // Get the value
  107.   VXIflt32 GetValue( ) const { return value; }
  108.  private:
  109.   VXIflt32  value;
  110. };
  111. class VXIDouble : public VXIValue {
  112.  public:
  113.   // Constructor and destructor
  114.   VXIDouble (VXIflt64 v) : VXIValue (VALUE_DOUBLE), value(v) { }
  115.   virtual ~VXIDouble( ) { }
  116.   // Get the value
  117.   VXIflt64 GetValue( ) const { return value; }
  118.  private:
  119.   VXIflt64  value;
  120. };
  121. class VXIPtr : public VXIValue {
  122.  public:
  123.   // Constructor and destructor
  124.   VXIPtr (VXIptr v) : VXIValue (VALUE_PTR), value(v) { }
  125.   virtual ~VXIPtr( ) { }
  126.   // Get the value
  127.   VXIptr GetValue( ) const { return value; }
  128.  private:
  129.   VXIptr        value;
  130. };
  131. // Helper class for VXIContent, non-public
  132. class VXIContentData {
  133.  public:
  134.   // Constructors and destructor
  135.   VXIContentData (const VXIchar  *ct,
  136.   VXIbyte        *c,
  137.   VXIulong        csb,
  138.   void          (*Destroy)(VXIbyte **content, void *userData),
  139.           void          (*GetValue)(void *userData, const VXIbyte *currcontent, const VXIbyte **realcontent, VXIulong* realcontentSizeBytes),
  140.   void           *ud);
  141.   virtual ~VXIContentData( );
  142.   // Add and remove references
  143.   static void AddRef  (VXIContentData *data);
  144.   static void Release (VXIContentData **data);
  145.  void RetrieveContent( const VXIchar **type, const VXIbyte **content, VXIulong* contentsize ) const;
  146.   // Get the data
  147.   void* GetUserData() const { return userData; }
  148.   const VXIulong  GetContentSizeBytes( ) const { return contentSizeBytes; }
  149.   void SetTransferEncoding(const VXIchar* e);
  150.   const VXIchar* GetTransferEncoding() const { return contentTransfer; }
  151. private:
  152.   const VXIchar  *GetContentType( ) const { return contentType; }
  153.   const VXIbyte  *GetContent( ) const { return content; }
  154.   const VXIchar  *GetContentTransferEncoding( ) const { return contentTransfer; }
  155.  private:
  156.   // Disabled copy constructor and assignment operator
  157.   VXIContentData (const VXIContent &c);
  158.   VXIContent &operator= (const VXIContent &c);
  159.  private:
  160. #ifdef WIN32
  161.   long         refCount;
  162. #else
  163.   VXItrdMutex *mutex;
  164.   VXIulong     refCount;
  165. #endif
  166.   VXIchar     *contentType;
  167.   VXIchar     *contentTransfer;
  168.   VXIbyte     *content;
  169.   VXIulong     contentSizeBytes;
  170.   void       (*Destroy)(VXIbyte **content, void *userData);
  171.   void       (*GetValue)(void *userData, const VXIbyte *currcontent, const VXIbyte **realcontent, VXIulong* realcontentSizeBytes);
  172.   void        *userData;
  173. };
  174. class VXIContent : public VXIValue {
  175.  public:
  176.   // Constructors and destructor
  177.   VXIContent (const VXIchar  *contentType,
  178.       VXIbyte        *content,
  179.       VXIulong        contentSizeBytes,
  180.       void          (*Destroy)(VXIbyte **content, void *userData),
  181.           void          (*GetValue)(void *userData, const VXIbyte *currcontent, const VXIbyte **realcontent, VXIulong* realcontentSizeBytes),
  182.       void           *userData) : 
  183.     VXIValue(VALUE_CONTENT), details(NULL) {
  184.     details = new VXIContentData (contentType, content, contentSizeBytes,
  185.   Destroy, GetValue, userData); }
  186.   VXIContent (const VXIContent &c) : 
  187.     VXIValue(VALUE_CONTENT), details(c.details) { 
  188.     VXIContentData::AddRef (details); }
  189.   virtual ~VXIContent( ) { VXIContentData::Release (&details); }
  190.   void RetrieveContent( const VXIchar **type, const VXIbyte **content, VXIulong* contentsize ) const{
  191.     if( details )
  192.       details->RetrieveContent(type,content,contentsize);
  193.   }
  194.   VXIbool IsValid() {
  195.     return (details != NULL );
  196.   }
  197.   void* GetUserData() const{
  198.     if( details )
  199.       return details->GetUserData();
  200.     return NULL;
  201.   }
  202.   void SetTransferEncoding( const VXIchar* e ) const{
  203.     if( details )
  204.       details->SetTransferEncoding(e);
  205.   }
  206.   const VXIchar* GetTransferEncoding() const{
  207.     if( details )
  208.       return details->GetTransferEncoding();
  209.     return NULL;
  210.   }
  211.   VXIulong GetContentSizeBytes( ) const {
  212.     if( details )
  213.       return details->GetContentSizeBytes();
  214.     return 0;
  215.   }
  216.   // Assignment operator
  217.   VXIContent &operator= (const VXIContent &c) {
  218.     if ( &c != this ) {
  219.       VXIContentData::Release (&details);
  220.       details = c.details;
  221.       VXIContentData::AddRef (details);
  222.     }
  223.     return *this;
  224.   }
  225.  private:
  226.   VXIContentData  *details;
  227. };
  228. #endif  /* include guard */