typecode.cc
来自「编译工具」· CC 代码 · 共 2,713 行 · 第 1/5 页
CC
2,713 行
// -*- Mode: C++; -*-// Package : omniORB// typecode.cc Created on: 03/09/98// Author : James Weatherall (jnw)//// 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 the CORBA::TypeCode psuedo object///* * $Log: typecode.cc,v $ * Revision 1.38.2.32 2005/04/10 22:37:39 dgrisby * Bug prevented creation of alias to incomplete type. Reported by Renzo * Tomaselli. * * Revision 1.38.2.31 2004/10/17 22:29:06 dgrisby * WChar TypeCode unmarshalling was missing. Thanks Luke Deller. * * Revision 1.38.2.30 2003/03/10 11:13:52 dgrisby * BAD_PARAM with invalid fixed limits. * * Revision 1.38.2.29 2003/03/05 15:26:54 dgrisby * Missing Fixed typecode unmarshal. Thanks Renzo Tomaselli. * * Revision 1.38.2.28 2002/12/18 15:59:15 dgrisby * Proper clean-up of recursive TypeCodes. * * Revision 1.38.2.27 2002/12/10 17:17:07 dgrisby * Yet another indirection problem. * * Revision 1.38.2.26 2002/12/05 12:22:22 dgrisby * More indirection problems. * * Revision 1.38.2.25 2002/09/06 14:35:55 dgrisby * Work around long long literal bug in MSVC. * * Revision 1.38.2.24 2002/02/25 11:17:12 dpg1 * Use tracedmutexes everywhere. * * Revision 1.38.2.23 2002/01/16 11:31:57 dpg1 * Race condition in use of registerNilCorbaObject/registerTrackedObject. * (Reported by Teemu Torma). * * Revision 1.38.2.22 2001/11/01 12:04:56 dpg1 * Don't return void in void function. * * Revision 1.38.2.21 2001/10/29 17:42:36 dpg1 * Support forward-declared structs/unions, ORB::create_recursive_tc(). * * Revision 1.38.2.20 2001/10/17 16:44:03 dpg1 * Update DynAny to CORBA 2.5 spec, const Any exception extraction. * * Revision 1.38.2.19 2001/09/24 10:41:09 dpg1 * Minor codes for Dynamic library and omniORBpy. * * Revision 1.38.2.18 2001/09/19 17:26:45 dpg1 * Full clean-up after orb->destroy(). * * Revision 1.38.2.17 2001/08/29 13:41:03 dpg1 * jnw's fix for compilers with variable sizeof(enum) * * Revision 1.38.2.16 2001/08/17 17:09:16 sll * Modularise ORB configuration parameters. * * Revision 1.38.2.15 2001/08/17 13:47:30 dpg1 * Small bug fixes. * * Revision 1.38.2.14 2001/07/25 13:39:46 dpg1 * Missing wstring case in TypeCode unmarshalling. * * Revision 1.38.2.13 2001/06/13 20:10:04 sll * Minor update to make the ORB compiles with MSVC++. * * Revision 1.38.2.12 2001/06/08 17:12:10 dpg1 * Merge all the bug fixes from omni3_develop. * * Revision 1.38.2.11 2001/04/19 09:14:12 sll * Scoped where appropriate with the omni namespace. * * Revision 1.38.2.10 2001/03/13 10:32:06 dpg1 * Fixed point support. * * Revision 1.38.2.9 2000/12/05 17:41:00 dpg1 * New cdrStream functions to marshal and unmarshal raw strings. * * Revision 1.38.2.8 2000/11/22 14:39:01 dpg1 * Missed out PR_wstring_tc() function. * * Revision 1.38.2.7 2000/11/20 14:40:04 sll * Added TypeCode::PR_wstring_tc(CORBA::ULong bound). * * Revision 1.38.2.6 2000/11/17 19:09:38 dpg1 * Support codeset conversion in any. * * Revision 1.38.2.5 2000/11/09 12:27:54 dpg1 * Huge merge from omni3_develop, plus full long long from omni3_1_develop. * * Revision 1.38.2.4 2000/11/03 19:07:32 sll * Use new marshalling functions for byte, octet and char. Use get_octet_array * instead of get_char_array. * * Revision 1.38.2.3 2000/10/06 16:40:54 sll * Changed to use cdrStream. * * Revision 1.38.2.2 2000/09/27 17:25:44 sll * Changed include/omniORB3 to include/omniORB4. * * Revision 1.38.2.1 2000/07/17 10:35:42 sll * Merged from omni3_develop the diff between omni3_0_0_pre3 and omni3_0_0. * * Revision 1.39 2000/07/13 15:26:02 dpg1 * Merge from omni3_develop for 3.0 release. * * Revision 1.33.6.10 2000/06/27 16:23:25 sll * Merged OpenVMS port. * * Revision 1.33.6.9 2000/03/20 15:09:30 djr * Fixed signed/unsigned mismatch. * * Revision 1.33.6.8 2000/02/21 10:59:13 djr * Another TypeCode_union w aliased discriminator fix. * * Revision 1.33.6.7 2000/02/17 14:43:57 djr * Another fix for TypeCode_union when discriminator tc contains an alias. * * Revision 1.33.6.6 2000/02/15 13:43:42 djr * Fixed bug in create_union_tc() -- problem if discriminator was an alias. * * Revision 1.33.6.5 1999/10/29 13:18:12 djr * Changes to ensure mutexes are constructed when accessed. * * Revision 1.33.6.4 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.33.6.3 1999/10/14 17:31:31 djr * Minor corrections. * * Revision 1.33.6.2 1999/10/14 16:22:01 djr * Implemented logging when system exceptions are thrown. * * Revision 1.33.6.1 1999/09/22 14:26:37 djr * Major rewrite of orbcore to support POA. * * Revision 1.32 1999/08/20 11:41:12 djr * Yet another TypeCode alias-expand bug. * * Revision 1.31 1999/08/06 16:55:17 sll * Added missing break statement in extractLabel. This bug affects enum * discriminator. * * Revision 1.30 1999/07/05 09:29:34 sll * member_label should return an octet if it is the default member. * * Revision 1.29 1999/07/01 10:27:38 djr * Fixed NP_aliasExpand(). * Added omg.org to a few IR repo IDs. * * Revision 1.28 1999/06/22 15:02:07 sll * Corrected bug in TypeCode_alias::NP_extendedEqual. * * Revision 1.27 1999/06/18 21:00:22 sll * Updated to CORBA 2.3 mapping. * * Revision 1.26 1999/05/25 17:54:48 sll * Added check for invalid arguments using magic numbers. * Perform casting of integer label values in union members. * * Revision 1.25 1999/04/21 13:24:57 djr * Fixed bug in generation of typecode alignment tables. * * Revision 1.24 1999/03/19 15:15:39 djr * Now accept indirections to fundamental TypeCodes. Option to accept * misaligned indirections. * * Revision 1.23 1999/03/11 16:25:59 djr * Updated copyright notice * * Revision 1.22 1999/03/04 09:54:24 djr * Disabled cached parameter lists - they have a bug. * * Revision 1.22 1999/02/26 09:57:51 djr * Disabled cached parameter lists, as they have a bug. * * Revision 1.21 1999/02/23 11:46:07 djr * Fixed bugs in size calculation for TypeCodes. * * Revision 1.21 1999/02/22 09:32:34 djr * Bug in size calculation for array and sequence TypeCodes. * * Revision 1.20 1999/02/18 15:51:23 djr * Option to not use indirections in on-the-wire TypeCodes. * * Revision 1.19 1999/02/12 11:52:12 djr * Typecodes for arrays were marshalled/unmarshalled incorrectly. * * Revision 1.18 1999/02/09 17:45:34 djr * Fixed bug in TypeCode_alignTable generation for structures and exceptions. * * Revision 1.17 1999/02/08 18:55:45 djr * Fixed bug in marshalling of TypeCodes for sequences. The sequence * bound and the content TypeCode were marshalled in the wrong order. * * Revision 1.16 1999/01/18 13:54:51 djr * Fixed bugs in implementation of unions. * * Revision 1.15 1999/01/11 15:45:23 djr * New implementation. * * Revision 1.14 1998/09/03 17:38:23 sll * CORBA::TypeCode::_nil() called the wrong ctor when compiled with DEC cxx * 5.5. fixed. * * Revision 1.13 1998/08/19 15:46:03 sll * operator<<= (CORBA::DefinitionKind,NetBufferedStream&) and friends are now * defined in the global scope. Previously they are defined in namespace COR * if the compiler support for namespace is used. * * Revision 1.12 1998/08/15 14:33:47 sll * Added NEED_DUMMY_RETURN macros to avoid better compiler to complain about * unreachable code. * Moved from CORBA.h inline member functions and operators. * * Revision 1.11 1998/08/14 13:55:01 sll * Added pragma hdrstop to control pre-compile header if the compiler feature * is available. * * Revision 1.10 1998/08/11 11:48:49 sll * Extended workaround in CORBA::TypeCode::_nil() to cover up to DEC Cxx * v5.5-015. * * Revision 1.9 1998/08/05 18:01:12 sll * Fixed bugs caused by typos in TypeCode::TypeCode(TCKind,ULong) and * TypeCode::_nil(). * * Revision 1.8 1998/04/18 10:11:17 sll * Corrected signature of one TypeCode ctor. * * Revision 1.7 1998/04/08 16:07:50 sll * Minor change to help some compiler to find the right TypeCode ctor. * * Revision 1.6 1998/04/08 14:07:26 sll * Added workaround in CORBA::TypeCode::_nil() for a bug in DEC Cxx v5.5. * * Revision 1.5 1998/04/07 19:40:53 sll * Moved inline member functions to this module. * * Revision 1.4 1998/03/17 12:52:19 sll * Corrected typo. * * Revision 1.3 1998/03/17 12:12:31 ewc * Bug fix to NP_aliasExpand() *// Revision 1.2 1998/02/20 14:45:43 ewc// Changed to compile with aCC on HPUX//// Revision 1.1 1998/01/27 15:41:24 ewc// Initial revision// */#include <omniORB4/CORBA.h>#include <omniORB4/objTracker.h>#ifdef HAS_pch#pragma hdrstop#endif#include <typecode.h>#include <tcParser.h>#include <orbParameters.h>#include <omniORB4/linkHacks.h>OMNI_FORCE_LINK(dynamicLib);OMNI_USING_NAMESPACE(omni)// CORBA::TypeCode - core class function implementation//// NOTE : internally, the TypeCode implementation implicitly assumes that no// content typecode is _ever_ CORBA::TypeCode::_nil().// To support this assumption cleanly, the visible CORBA::TypeCode()// interface must check any typecodes passed to it and raise// CORBA::BAD_TYPECODE if a _nil() value is encountered.///////////////////////////////////////////////////////////////////////////////////////////////// CORBA::TypeCode ////////////////////////////////////////////////////////////////////////////////////////////////#if !defined(OMNIORB_NO_EXCEPTION_LOGGING) && defined(__DECCXX) && __DECCXX_VER > 60000000// Compaq C++ 6.x needs dummy return if function is called to throw an// exception.#ifndef NEED_DUMMY_RETURN#define NEED_DUMMY_RETURN#endif#endifCORBA::TypeCode::~TypeCode() { pd_magic = 0;}CORBA::TCKindCORBA::TypeCode::kind() const{ return TypeCode_indirect::strip(ToConstTcBase_Checked(this))->NP_kind();}CORBA::BooleanCORBA::TypeCode::equal(CORBA::TypeCode_ptr TCp) const{ if (!PR_is_valid(TCp)) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidTypeCode, CORBA::COMPLETED_NO); return ToConstTcBase_Checked(this) ->NP_equal(ToTcBase_Checked(TCp),0,0);}CORBA::BooleanCORBA::TypeCode::equivalent(CORBA::TypeCode_ptr TCp) const{ if (!PR_is_valid(TCp)) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidTypeCode, CORBA::COMPLETED_NO); return ToConstTcBase_Checked(this) ->NP_equal(ToTcBase_Checked(TCp),1,0);}CORBA::TypeCode_ptrCORBA::TypeCode::get_compact_typecode() const{ TypeCode_base* tp = (TypeCode_base*)ToConstTcBase_Checked(this); return tp->NP_compactTc();}const char*CORBA::TypeCode::id() const{ return ToConstTcBase_Checked(this)->NP_id();}const char*CORBA::TypeCode::name() const{ return ToConstTcBase_Checked(this)->NP_name();}CORBA::ULongCORBA::TypeCode::member_count() const{ return ToConstTcBase_Checked(this)->NP_member_count();}const char*CORBA::TypeCode::member_name(CORBA::ULong index) const{ return ToConstTcBase_Checked(this)->NP_member_name(index);}CORBA::TypeCode_ptrCORBA::TypeCode::member_type(CORBA::ULong i) const{ return TypeCode_collector::duplicateRef(ToConstTcBase_Checked(this) ->NP_member_type(i));}CORBA::Any*CORBA::TypeCode::member_label(CORBA::ULong i) const{ return ToConstTcBase_Checked(this)->NP_member_label(i);}CORBA::TypeCode_ptrCORBA::TypeCode::discriminator_type() const{ return TypeCode_collector::duplicateRef(ToConstTcBase_Checked(this) ->NP_discriminator_type());}CORBA::LongCORBA::TypeCode::default_index() const{ return ToConstTcBase_Checked(this)->NP_default_index();}CORBA::ULongCORBA::TypeCode::length() const{ return ToConstTcBase_Checked(this)->NP_length();}CORBA::TypeCode_ptrCORBA::TypeCode::content_type() const{ return TypeCode_collector::duplicateRef(ToConstTcBase_Checked(this) ->NP_content_type());}CORBA::UShortCORBA::TypeCode::fixed_digits() const{ return ToConstTcBase_Checked(this)->NP_fixed_digits();}CORBA::ShortCORBA::TypeCode::fixed_scale() const{ return ToConstTcBase_Checked(this)->NP_fixed_scale();}CORBA::LongCORBA::TypeCode::param_count() const{ return ToConstTcBase_Checked(this)->NP_param_count();}CORBA::Any*CORBA::TypeCode::parameter(Long index) const{ return ToConstTcBase_Checked(this)->NP_parameter(index);}// Static TypeCode member functionsCORBA::TypeCode_ptrCORBA::TypeCode::_duplicate(CORBA::TypeCode_ptr t){ if (!PR_is_valid(t)) OMNIORB_THROW(BAD_PARAM,BAD_PARAM_InvalidTypeCode,CORBA::COMPLETED_NO); if (CORBA::is_nil(t)) return t; return TypeCode_collector::duplicateRef(ToTcBase(t));}OMNI_NAMESPACE_BEGIN(omni)//// The nil TypeCode is derived from neither CORBA::Object or// omniTrackedObject. We use a holder object to ensure it is deleted// on exit.//class omniNilTypeCodeHolder : public omniTrackedObject {public: inline omniNilTypeCodeHolder(CORBA::TypeCode_ptr nil) : pd_nil(nil) {} virtual ~omniNilTypeCodeHolder() { delete pd_nil; }private: CORBA::TypeCode_ptr pd_nil;};OMNI_NAMESPACE_END(omni)CORBA::TypeCode_ptrCORBA::TypeCode::_nil(){ static TypeCode* _the_nil_ptr = 0; if( !_the_nil_ptr ) { omni::nilRefLock().lock(); if( !_the_nil_ptr ) { _the_nil_ptr = new TypeCode; registerTrackedObject(new omniNilTypeCodeHolder(_the_nil_ptr)); } omni::nilRefLock().unlock(); } return _the_nil_ptr;}// omniORB marshalling routinesvoidCORBA::TypeCode::marshalTypeCode(TypeCode_ptr obj,cdrStream &s){ TypeCode_offsetTable otbl; TypeCode_marshaller::marshal(ToTcBase_Checked(obj), s, &otbl);}CORBA::TypeCode_ptrCORBA::TypeCode::unmarshalTypeCode(cdrStream &s){ TypeCode_offsetTable otbl; TypeCode_base* tc = TypeCode_marshaller::unmarshal(s, &otbl); TypeCode_collector::markLoopMembers(tc); return tc;}CORBA::BooleanCORBA::TypeCode::NP_is_nil() const{ return 1;}// Complex TypeCode constructors// These routines are the omniORB-specific constructors for complex typecodes.// CORBA-compliant applications should only ever access these through the ORB// interface. These functions are for the use of omniORB stubs & libraries.// NB: The reference count of the returned TypeCode_ptr is always 1, unless// the TypeCode structure contains recursive references.#if 0CORBA::TypeCode_ptrCORBA::TypeCode::NP_struct_tc(const char* id, const char* name, const CORBA::StructMemberSeq& members){ const CORBA::ULong memberCount = members.length(); for( CORBA::ULong i = 0; i < memberCount; i++ ) if ( !PR_is_valid(members[i].type) || CORBA::is_nil(members[i].type)) OMNIORB_THROW(BAD_TYPECODE, BAD_TYPECODE_TypeCodeIsNil, CORBA::COMPLETED_NO); return new TypeCode_struct(id, name, members);}CORBA::TypeCode_ptrCORBA::TypeCode::NP_union_tc(const char* id, const char* name, CORBA::TypeCode_ptr discriminator_type, const CORBA::UnionMemberSeq& members){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?