1 // -*- Mode: C++; -*- 2 // Package : omniORB 3 // anyStream.h Created on: 2004/06/21 4 // Author : Duncan Grisby 5 // 6 // 7 // Copyright (C) 2004-2011 Apasphere Ltd. 8 // 9 // This file is part of the omniORB library 10 // 11 // The omniORB library is free software; you can redistribute it and/or 12 // modify it under the terms of the GNU Lesser General Public 13 // License as published by the Free Software Foundation; either 14 // version 2.1 of the License, or (at your option) any later version. 15 // 16 // This library is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 // Lesser General Public License for more details. 20 // 21 // You should have received a copy of the GNU Lesser General Public 22 // License along with this library. If not, see http://www.gnu.org/licenses/ 23 // 24 // 25 // Description: 26 // cdrMemoryStream extension used by Anys. 27 // 28 29 #ifndef __OMNI_ANYSTREAM_H__ 30 #define __OMNI_ANYSTREAM_H__ 31 32 #include <omniORB4/omniTypedefs.hh> 33 34 #ifdef _dyn_attr 35 # error "A local CPP macro _dyn_attr has already been defined." 36 #endif 37 38 #if defined(_OMNIORB_DYNAMIC_LIBRARY) 39 # define _dyn_attr 40 #else 41 # define _dyn_attr _OMNIORB_NTDLL_IMPORT 42 #endif 43 44 class cdrAnyMemoryStream : public cdrMemoryStream { 45 public: 46 cdrAnyMemoryStream(); 47 48 cdrAnyMemoryStream(const cdrAnyMemoryStream& s, CORBA::Boolean read_only=0); 49 50 cdrAnyMemoryStream(void* databuffer, CORBA::Boolean release); 51 52 virtual ~cdrAnyMemoryStream(); 53 54 virtual void* ptrToClass(int* cptr); 55 downcast(cdrStream * s)56 static inline cdrAnyMemoryStream* downcast(cdrStream* s) { 57 return (cdrAnyMemoryStream*)s->ptrToClass(&_classid); 58 } 59 static _dyn_attr int _classid; 60 static _dyn_attr cdrAnyMemoryStream* _empty; 61 valueSeq()62 inline omniTypedefs::ValueBaseSeq& valueSeq() 63 { 64 if (pd_values.operator->() == 0) 65 pd_values = new omniTypedefs::ValueBaseSeq; 66 return pd_values; 67 } 68 clearValueSeq()69 inline void clearValueSeq() 70 { 71 pd_values = 0; 72 } 73 hasValues()74 inline _CORBA_Boolean hasValues() 75 { 76 return pd_values.operator->() != 0; 77 } 78 add_ref()79 inline void add_ref() 80 { 81 pd_refCount.inc(); 82 } 83 remove_ref()84 inline void remove_ref() 85 { 86 if (pd_refCount.dec() == 0) 87 delete this; 88 } 89 90 91 private: 92 // ValueTypes inside Anys cannot be stored inside the marshalled 93 // stream like other types, because to do so would not have the 94 // required sharing semantics. Instead, we store a sequence of 95 // values here. Inside the stream, values are stored as a ulong 96 // representing an index into this sequence. The sequence is only 97 // allocated if there are values inside the Any. 98 omniTypedefs::ValueBaseSeq_var pd_values; 99 100 omni_refcount pd_refCount; 101 102 // Not implemented 103 cdrAnyMemoryStream& operator=(const cdrAnyMemoryStream&); 104 }; 105 106 #undef _dyn_attr 107 108 #endif // __OMNI_ANYSTREAM_H__ 109