📄 dynanyimpl.h
字号:
// -*- Mode: C++; -*-// Package : omniORB// dynAny.h Created on: 11/1998// Author : David Riddoch (djr)//// Copyright (C) 1996-1999 AT&T Laboratories Cambridge//// This file is part of the omniORB library//// The omniORB library is free software; you can redistribute it and/or// modify it under the terms of the GNU Library General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Library General Public License for more details.//// You should have received a copy of the GNU Library General Public// License along with this library; if not, write to the Free// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA////// Description:// Implementation of CORBA::DynAny.///* $Log: dynAnyImpl.h,v $ Revision 1.1.2.3 2001/10/19 11:04:03 dpg1 Avoid confusing (to gcc 2.95) inheritance of refcount functions. Revision 1.1.2.2 2001/10/17 18:51:51 dpg1 Fix inevitable Windows problems. Revision 1.1.2.1 2001/10/17 16:44:05 dpg1 Update DynAny to CORBA 2.5 spec, const Any exception extraction. Revision 1.1.2.1 2001/04/18 17:18:17 sll Big checkin with the brand new internal APIs. These files were relocated and scoped with the omni namespace. Revision 1.5.2.5 2000/11/17 19:09:37 dpg1 Support codeset conversion in any. Revision 1.5.2.4 2000/11/09 12:27:53 dpg1 Huge merge from omni3_develop, plus full long long from omni3_1_develop. Revision 1.5.2.3 2000/10/06 16:40:53 sll Changed to use cdrStream. Revision 1.5.2.2 2000/09/27 17:25:41 sll Changed include/omniORB3 to include/omniORB4. Revision 1.5.2.1 2000/07/17 10:35:41 sll Merged from omni3_develop the diff between omni3_0_0_pre3 and omni3_0_0. Revision 1.6 2000/07/13 15:26:02 dpg1 Merge from omni3_develop for 3.0 release. Revision 1.2.8.3 1999/10/26 20:18:20 sll DynAny no longer do alias expansion on the typecode. In other words, all aliases in the typecode are preserved. Revision 1.2.8.2 1999/09/22 16:15:59 djr Removed MT locking.*/#ifndef __DYNANYIMPL_H__#define __DYNANYIMPL_H__#include <typecode.h>OMNI_NAMESPACE_BEGIN(omni)// Node type constants.#define dt_any 0#define dt_enum 1#define dt_fixed 2#define dt_struct 3#define dt_union 4#define dt_seq 5#define dt_array 6#define dt_disc 7#define dt_enumdisc 8// Forward declarations.class DynAnyImplBase;class DynAnyImpl;class DynEnumImpl;class DynFixedImpl;class DynAnyConstrBase;class DynStructImpl;class DynUnionImpl;class DynSequenceImpl;class DynArrayImpl;inline DynAnyImpl* ToDynAnyImpl (DynamicAny::DynAny_ptr p);inline DynAnyImplBase* ToDynAnyImplBase (DynamicAny::DynAny_ptr p);inline DynAnyConstrBase* ToDynAnyConstrBase(DynamicAny::DynAny_ptr p);inline DynUnionImpl* ToDynUnionImpl (DynamicAny::DynAny_ptr p);// Values used to indicate whether a DynAny is the child of// another DynAny, or the root.#define DYNANY_CHILD 0#define DYNANY_ROOT 1///////////////////////////////////////////////////////////////////////////////////////////////// DynAnyImplBase ///////////////////////////////////////////////////////////////////////////////////////////////////: Functionality common to all DynAny implementations.class DynAnyImplBase : public virtual DynamicAny::DynAny{public: DynAnyImplBase(TypeCode_base* tc, int nodetype, CORBA::Boolean is_root) : OMNIORB_BASE_CTOR(DynamicAny::)DynAny(0), pd_tc(tc), pd_refcount(1), pd_is_root(is_root), pd_destroyed(0) {} // <tc> is consumed. virtual ~DynAnyImplBase(); /******************* * public interface * *******************/ virtual CORBA::TypeCode_ptr type() const; virtual void from_any(const CORBA::Any& value); virtual CORBA::Any* to_any(); virtual void destroy(); /*********** * internal * ***********/ virtual void set_to_initial_value() = 0; // Set the DynAny to the default initial value. virtual int copy_to(cdrMemoryStream& mbs) = 0; // Copies our value into the given stream. Does not flush <mbs>, // but does rewind our buffer first. Returns 0 if we are not // properly initialised. // Concurrency: hold DynAnyImplBase::lock virtual int copy_from(cdrMemoryStream& mbs) = 0; // Copies the value from the given stream into this DynAny, // replacing the old value. Reads from the stream's current // position, and updates the stream's pointers. Returns 0 if there // was a problem reading the value out of the stream. // Concurrency: hold DynAnyImplBase::lock virtual void onDispose(); // Called when the reference count goes to zero. This gives the // node a chance to detach() any children before it is destroyed. // Should be overriden by descendants (which should call their // base-class's implementation). // Concurrency: hold DynAnyImplBase::lock void detach() { pd_is_root = 1; } // Detach this one from its parent - ie. make it a root, so that // when it's reference count goes to zero it will be cleaned up. void attach() { OMNIORB_ASSERT(pd_is_root); pd_is_root = 0; } // Attach to a new parent. virtual void _NP_incrRefCount(); virtual void _NP_decrRefCount(); // Must not hold DynAnyImplBase::refCountLock. TypeCode_base* tc() const { return pd_tc; } TypeCode_base* actualTc() const { return (TypeCode_base*)TypeCode_base::NP_expand(pd_tc); } // Return the typecode. If the typecode is an alias, return the content // type. CORBA::TCKind tckind() const { return actualTc()->NP_kind(); } // Return the TCKind. If the typecode is an alias, return the TCKind of // the content type. cdrMemoryStream pd_buf; // The value held by the DynAny. Basic DynAny values are // always stored in the buffer. For complex types it is stored // in the buffer when convenient - otherwise in sub-components. inline CORBA::Boolean is_root() const { return pd_is_root; } inline CORBA::Boolean destroyed() const { return pd_destroyed; } // Assume reading is atomic. virtual void* _ptrToObjRef(const char* repoId) = 0; static const char* _PD_repoId; // Fake repoId for use by _ptrToObjRefprivate: // TypeCode of the value held. TypeCode_base* pd_tc; // Reference counting and child management. int pd_refcount; CORBA::Boolean pd_is_root; CORBA::Boolean pd_destroyed; static omni_tracedmutex refCountLock;};/////////////////////////////////////////////////////////////////////////////////////////////////// DynAnyImpl /////////////////////////////////////////////////////////////////////////////////////////////////////: Implementation of DynAny for basic types.class DynAnyImpl : public DynAnyImplBase{public: DynAnyImpl(TypeCode_base* tc, int nodetype, CORBA::Boolean is_root=1); virtual ~DynAnyImpl(); /******************* * public interface * *******************/ virtual void assign(DynamicAny::DynAny_ptr dyn_any); virtual DynamicAny::DynAny_ptr copy(); virtual CORBA::Boolean equal(DynamicAny::DynAny_ptr dyn_any); virtual void insert_boolean (CORBA::Boolean value); virtual void insert_octet (CORBA::Octet value); virtual void insert_char (CORBA::Char value); virtual void insert_short (CORBA::Short value); virtual void insert_ushort (CORBA::UShort value); virtual void insert_long (CORBA::Long value); virtual void insert_ulong (CORBA::ULong value);#ifndef NO_FLOAT virtual void insert_float (CORBA::Float value); virtual void insert_double (CORBA::Double value);#endif virtual void insert_string (const char* value); virtual void insert_reference (CORBA::Object_ptr value); virtual void insert_typecode (CORBA::TypeCode_ptr value);#ifdef HAS_LongLong virtual void insert_longlong (CORBA::LongLong value); virtual void insert_ulonglong (CORBA::ULongLong value);#endif #ifdef HAS_LongDouble virtual void insert_longdouble(CORBA::LongDouble value);#endif virtual void insert_wchar (CORBA::WChar value); virtual void insert_wstring (const CORBA::WChar* value); virtual void insert_any (const CORBA::Any& value); virtual void insert_dyn_any (DynamicAny::DynAny_ptr value); virtual CORBA::Boolean get_boolean(); virtual CORBA::Octet get_octet(); virtual CORBA::Char get_char(); virtual CORBA::Short get_short(); virtual CORBA::UShort get_ushort(); virtual CORBA::Long get_long(); virtual CORBA::ULong get_ulong();#ifndef NO_FLOAT virtual CORBA::Float get_float(); virtual CORBA::Double get_double();#endif virtual char* get_string(); virtual CORBA::Object_ptr get_reference(); virtual CORBA::TypeCode_ptr get_typecode();#ifdef HAS_LongLong virtual CORBA::LongLong get_longlong(); virtual CORBA::ULongLong get_ulonglong();#endif #ifdef HAS_LongDouble virtual CORBA::LongDouble get_longdouble();#endif virtual CORBA::WChar get_wchar(); virtual CORBA::WChar* get_wstring(); virtual CORBA::Any* get_any(); virtual DynamicAny::DynAny_ptr get_dyn_any(); virtual void insert_boolean_seq (CORBA::BooleanSeq& value); virtual void insert_octet_seq (CORBA::OctetSeq& value); virtual void insert_char_seq (CORBA::CharSeq& value); virtual void insert_short_seq (CORBA::ShortSeq& value); virtual void insert_ushort_seq (CORBA::UShortSeq& value); virtual void insert_long_seq (CORBA::LongSeq& value); virtual void insert_ulong_seq (CORBA::ULongSeq& value);#ifndef NO_FLOAT virtual void insert_float_seq (CORBA::FloatSeq& value); virtual void insert_double_seq (CORBA::DoubleSeq& value);#endif#ifdef HAS_LongLong virtual void insert_longlong_seq (CORBA::LongLongSeq& value); virtual void insert_ulonglong_seq (CORBA::ULongLongSeq& value);#endif#ifdef HAS_LongDouble virtual void insert_longdouble_seq(CORBA::LongDoubleSeq& value);#endif virtual void insert_wchar_seq (CORBA::WCharSeq& value); virtual CORBA::BooleanSeq* get_boolean_seq(); virtual CORBA::OctetSeq* get_octet_seq(); virtual CORBA::CharSeq* get_char_seq(); virtual CORBA::ShortSeq* get_short_seq(); virtual CORBA::UShortSeq* get_ushort_seq(); virtual CORBA::LongSeq* get_long_seq(); virtual CORBA::ULongSeq* get_ulong_seq();#ifndef NO_FLOAT virtual CORBA::FloatSeq* get_float_seq(); virtual CORBA::DoubleSeq* get_double_seq();#endif#ifdef HAS_LongLong virtual CORBA::LongLongSeq* get_longlong_seq(); virtual CORBA::ULongLongSeq* get_ulonglong_seq();#endif#ifdef HAS_LongDouble virtual CORBA::LongDoubleSeq* get_longdouble_seq();#endif virtual CORBA::WCharSeq* get_wchar_seq(); virtual CORBA::Boolean seek(CORBA::Long index); virtual void rewind(); virtual CORBA::Boolean next(); virtual CORBA::ULong component_count(); virtual DynamicAny::DynAny_ptr current_component(); /**************************** * exposed private interface * ****************************/ virtual int NP_nodetype() const; /*********** * internal * ***********/ virtual void set_to_initial_value(); virtual int copy_to(cdrMemoryStream& mbs); virtual int copy_from(cdrMemoryStream& mbs); CORBA::Boolean isValid() const { return pd_isValid; } // If true it indicates that the value in the internal // buffer is valid. // Must hold DynAnyImplBase::lock. void setValid() { pd_isValid = 1; } void setInvalid() { pd_isValid = 0; } // Must hold DynAnyImplBase::lock. virtual void* _ptrToObjRef(const char* repoId); static const char* _PD_repoId; // Fake repoId for use by _ptrToObjRefprotected: cdrMemoryStream& doWrite(CORBA::TCKind kind) { if( tckind() != kind ) throw DynamicAny::DynAny::TypeMismatch(); pd_buf.rewindPtrs(); setValid(); return pd_buf; } cdrMemoryStream& doRead(CORBA::TCKind kind) { if( tckind() != kind || !isValid()) throw DynamicAny::DynAny::TypeMismatch(); pd_buf.rewindInputPtr(); return pd_buf; }private: CORBA::Boolean pd_isValid;};////////////////////////////////////////////////////////////////////////////////////////////////// DynFixedImpl //////////////////////////////////////////////////////////////////////////////////////////////////class DynFixedImpl : public DynAnyImpl, public DynamicAny::DynFixed{public: DynFixedImpl(TypeCode_base* tc, CORBA::Boolean is_root=1); virtual ~DynFixedImpl(); /******************* * public interface * *******************/ virtual DynamicAny::DynAny_ptr copy(); virtual char* get_value(); virtual CORBA::Boolean set_value(const char* val); /**************************** * exposed private interface * ****************************/ virtual int NP_nodetype() const; /*********** * internal * ***********/ virtual void set_to_initial_value(); TypeCode_fixed* actualTc() const { return (TypeCode_fixed*) DynAnyImplBase::actualTc(); } virtual void _NP_incrRefCount(); virtual void _NP_decrRefCount(); // Must not hold DynAnyImplBase::refCountLock. virtual void* _ptrToObjRef(const char* repoId);private:};/////////////////////////////////////////////////////////////////////////////////////////////////// DynEnumImpl //////////////////////////////////////////////////////////////////////////////////////////////////class DynEnumImpl : public DynAnyImpl, public DynamicAny::DynEnum{public: DynEnumImpl(TypeCode_base* tc, CORBA::Boolean is_root=1); virtual ~DynEnumImpl(); /******************* * public interface * *******************/ virtual DynamicAny::DynAny_ptr copy(); virtual char* get_as_string(); virtual void set_as_string(const char* value); virtual CORBA::ULong get_as_ulong(); virtual void set_as_ulong(CORBA::ULong value); /**************************** * exposed private interface * ****************************/ virtual int NP_nodetype() const;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -