1 // -*- Mode: C++; -*-
2 // Package : omniORB
3 // dynAny.h Created on: 11/1998
4 // Author : David Riddoch (djr)
5 //
6 // Copyright (C) 2003-2005 Apasphere Ltd
7 // Copyright (C) 1996-1999 AT&T Laboratories Cambridge
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 // Implementation of CORBA::DynAny.
27 //
28
29 #ifndef __DYNANYIMPL_H__
30 #define __DYNANYIMPL_H__
31
32 #include <typecode.h>
33 #include <omniORB4/anyStream.h>
34
35 OMNI_NAMESPACE_BEGIN(omni)
36
37 // Node type constants.
38 #define dt_any 0
39 #define dt_enum 1
40 #define dt_fixed 2
41 #define dt_struct 3
42 #define dt_union 4
43 #define dt_seq 5
44 #define dt_array 6
45 #define dt_disc 7
46 #define dt_enumdisc 8
47 #define dt_value 9
48 #define dt_value_box 10
49
50
51 // Forward declarations.
52 class DynAnyImplBase;
53 class DynAnyImpl;
54 class DynEnumImpl;
55 class DynFixedImpl;
56 class DynAnyConstrBase;
57 class DynStructImpl;
58 class DynUnionImpl;
59 class DynSequenceImpl;
60 class DynArrayImpl;
61 class DynValueImpl;
62 class DynValueBoxImpl;
63
64 inline DynAnyImpl* ToDynAnyImpl (DynamicAny::DynAny_ptr p);
65 inline DynAnyImplBase* ToDynAnyImplBase (DynamicAny::DynAny_ptr p);
66 inline DynAnyConstrBase* ToDynAnyConstrBase(DynamicAny::DynAny_ptr p);
67 inline DynUnionImpl* ToDynUnionImpl (DynamicAny::DynAny_ptr p);
68
69 // Values used to indicate whether a DynAny is the child of
70 // another DynAny, or the root.
71 #define DYNANY_CHILD 0
72 #define DYNANY_ROOT 1
73
74
75 //////////////////////////////////////////////////////////////////////
76 /////////////////////////// DynAnyImplBase ///////////////////////////
77 //////////////////////////////////////////////////////////////////////
78
79 //: Functionality common to all DynAny implementations.
80
81 class DynAnyImplBase : public virtual DynamicAny::DynAny
82 {
83 public:
DynAnyImplBase(TypeCode_base * tc,int nodetype,CORBA::Boolean is_root)84 DynAnyImplBase(TypeCode_base* tc, int nodetype, CORBA::Boolean is_root)
85 : OMNIORB_BASE_CTOR(DynamicAny::)DynAny(0),
86 pd_tc(tc), pd_refcount(1), pd_is_root(is_root), pd_destroyed(0)
87 {}
88 // <tc> is consumed.
89
90 virtual ~DynAnyImplBase();
91
92 /*******************
93 * public interface *
94 *******************/
95 virtual CORBA::TypeCode_ptr type() const;
96
97 virtual void from_any(const CORBA::Any& value);
98 virtual CORBA::Any* to_any();
99 virtual void destroy();
100
101 /***********
102 * internal *
103 ***********/
104
105 virtual void set_to_initial_value() = 0;
106 // Set the DynAny to the default initial value.
107
108 virtual int copy_to(cdrAnyMemoryStream& mbs) = 0;
109 // Copies our value into the given stream. Does not flush <mbs>,
110 // but does rewind our buffer first. Returns 0 if we are not
111 // properly initialised.
112 // Concurrency: hold DynAnyImplBase::lock
113
114 virtual int copy_from(cdrAnyMemoryStream& mbs) = 0;
115 // Copies the value from the given stream into this DynAny,
116 // replacing the old value. Reads from the stream's current
117 // position, and updates the stream's pointers. Returns 0 if there
118 // was a problem reading the value out of the stream.
119 // Concurrency: hold DynAnyImplBase::lock
120
121 virtual void onDispose();
122 // Called when the reference count goes to zero. This gives the
123 // node a chance to detach() any children before it is destroyed.
124 // Should be overriden by descendants (which should call their
125 // base-class's implementation).
126 // Concurrency: hold DynAnyImplBase::lock
127
detach()128 void detach() { pd_is_root = 1; }
129 // Detach this one from its parent - ie. make it a root, so that
130 // when it's reference count goes to zero it will be cleaned up.
131
attach()132 void attach() { OMNIORB_ASSERT(pd_is_root); pd_is_root = 0; }
133 // Attach to a new parent.
134
135 virtual void _NP_incrRefCount();
136 virtual void _NP_decrRefCount();
137 // Must not hold DynAnyImplBase::refCountLock.
138
tc()139 TypeCode_base* tc() const { return pd_tc; }
140
actualTc()141 TypeCode_base* actualTc() const {
142 return (TypeCode_base*)TypeCode_base::NP_expand(pd_tc);
143 }
144 // Return the typecode. If the typecode is an alias, return the content
145 // type.
146
tckind()147 CORBA::TCKind tckind() const { return actualTc()->NP_kind(); }
148 // Return the TCKind. If the typecode is an alias, return the TCKind of
149 // the content type.
150
151
152 cdrAnyMemoryStream pd_buf;
153 // The value held by the DynAny. Basic DynAny values are
154 // always stored in the buffer. For complex types it is stored
155 // in the buffer when convenient - otherwise in sub-components.
156
is_root()157 inline CORBA::Boolean is_root() const { return pd_is_root; }
destroyed()158 inline CORBA::Boolean destroyed() const { return pd_destroyed; }
159 // Assume reading is atomic.
160
161 virtual void* _ptrToObjRef(const char* repoId) = 0;
162
163 static const char* _PD_repoId;
164 // Fake repoId for use by _ptrToObjRef
165
166 private:
167 // TypeCode of the value held.
168 TypeCode_base* pd_tc;
169
170 // Reference counting and child management.
171 int pd_refcount;
172 CORBA::Boolean pd_is_root;
173 CORBA::Boolean pd_destroyed;
174
175 static omni_tracedmutex refCountLock;
176 };
177
178 //////////////////////////////////////////////////////////////////////
179 ///////////////////////////// DynAnyImpl /////////////////////////////
180 //////////////////////////////////////////////////////////////////////
181
182 //: Implementation of DynAny for basic types.
183
184 class DynAnyImpl : public DynAnyImplBase
185 {
186 public:
187 DynAnyImpl(TypeCode_base* tc, int nodetype, CORBA::Boolean is_root=1);
188 virtual ~DynAnyImpl();
189
190 /*******************
191 * public interface *
192 *******************/
193 virtual void assign(DynamicAny::DynAny_ptr dyn_any);
194 virtual DynamicAny::DynAny_ptr copy();
195 virtual CORBA::Boolean equal(DynamicAny::DynAny_ptr dyn_any);
196
197 virtual void insert_boolean (CORBA::Boolean value);
198 virtual void insert_octet (CORBA::Octet value);
199 virtual void insert_char (CORBA::Char value);
200 virtual void insert_short (CORBA::Short value);
201 virtual void insert_ushort (CORBA::UShort value);
202 virtual void insert_long (CORBA::Long value);
203 virtual void insert_ulong (CORBA::ULong value);
204 #ifndef NO_FLOAT
205 virtual void insert_float (CORBA::Float value);
206 virtual void insert_double (CORBA::Double value);
207 #endif
208 virtual void insert_string (const char* value);
209 virtual void insert_reference (CORBA::Object_ptr value);
210 virtual void insert_typecode (CORBA::TypeCode_ptr value);
211 #ifdef HAS_LongLong
212 virtual void insert_longlong (CORBA::LongLong value);
213 virtual void insert_ulonglong (CORBA::ULongLong value);
214 #endif
215 #ifdef HAS_LongDouble
216 virtual void insert_longdouble(CORBA::LongDouble value);
217 #endif
218 virtual void insert_wchar (CORBA::WChar value);
219 virtual void insert_wstring (const CORBA::WChar* value);
220 virtual void insert_any (const CORBA::Any& value);
221 virtual void insert_dyn_any (DynamicAny::DynAny_ptr value);
222 virtual void insert_val (CORBA::ValueBase* value);
223 virtual void insert_abstract (CORBA::AbstractBase_ptr value);
224
225 virtual CORBA::Boolean get_boolean();
226 virtual CORBA::Octet get_octet();
227 virtual CORBA::Char get_char();
228 virtual CORBA::Short get_short();
229 virtual CORBA::UShort get_ushort();
230 virtual CORBA::Long get_long();
231 virtual CORBA::ULong get_ulong();
232 #ifndef NO_FLOAT
233 virtual CORBA::Float get_float();
234 virtual CORBA::Double get_double();
235 #endif
236 virtual char* get_string();
237 virtual CORBA::Object_ptr get_reference();
238 virtual CORBA::TypeCode_ptr get_typecode();
239 #ifdef HAS_LongLong
240 virtual CORBA::LongLong get_longlong();
241 virtual CORBA::ULongLong get_ulonglong();
242 #endif
243 #ifdef HAS_LongDouble
244 virtual CORBA::LongDouble get_longdouble();
245 #endif
246 virtual CORBA::WChar get_wchar();
247 virtual CORBA::WChar* get_wstring();
248 virtual CORBA::Any* get_any();
249 virtual DynamicAny::DynAny_ptr get_dyn_any();
250 virtual CORBA::ValueBase* get_val();
251 virtual CORBA::AbstractBase_ptr get_abstract();
252
253 virtual void insert_boolean_seq (CORBA::BooleanSeq& value);
254 virtual void insert_octet_seq (CORBA::OctetSeq& value);
255 virtual void insert_char_seq (CORBA::CharSeq& value);
256 virtual void insert_short_seq (CORBA::ShortSeq& value);
257 virtual void insert_ushort_seq (CORBA::UShortSeq& value);
258 virtual void insert_long_seq (CORBA::LongSeq& value);
259 virtual void insert_ulong_seq (CORBA::ULongSeq& value);
260 #ifndef NO_FLOAT
261 virtual void insert_float_seq (CORBA::FloatSeq& value);
262 virtual void insert_double_seq (CORBA::DoubleSeq& value);
263 #endif
264 #ifdef HAS_LongLong
265 virtual void insert_longlong_seq (CORBA::LongLongSeq& value);
266 virtual void insert_ulonglong_seq (CORBA::ULongLongSeq& value);
267 #endif
268 #ifdef HAS_LongDouble
269 virtual void insert_longdouble_seq(CORBA::LongDoubleSeq& value);
270 #endif
271 virtual void insert_wchar_seq (CORBA::WCharSeq& value);
272
273 virtual CORBA::BooleanSeq* get_boolean_seq();
274 virtual CORBA::OctetSeq* get_octet_seq();
275 virtual CORBA::CharSeq* get_char_seq();
276 virtual CORBA::ShortSeq* get_short_seq();
277 virtual CORBA::UShortSeq* get_ushort_seq();
278 virtual CORBA::LongSeq* get_long_seq();
279 virtual CORBA::ULongSeq* get_ulong_seq();
280 #ifndef NO_FLOAT
281 virtual CORBA::FloatSeq* get_float_seq();
282 virtual CORBA::DoubleSeq* get_double_seq();
283 #endif
284 #ifdef HAS_LongLong
285 virtual CORBA::LongLongSeq* get_longlong_seq();
286 virtual CORBA::ULongLongSeq* get_ulonglong_seq();
287 #endif
288 #ifdef HAS_LongDouble
289 virtual CORBA::LongDoubleSeq* get_longdouble_seq();
290 #endif
291 virtual CORBA::WCharSeq* get_wchar_seq();
292
293 virtual CORBA::Boolean seek(CORBA::Long index);
294 virtual void rewind();
295 virtual CORBA::Boolean next();
296 virtual CORBA::ULong component_count();
297 virtual DynamicAny::DynAny_ptr current_component();
298
299 /****************************
300 * exposed private interface *
301 ****************************/
302 virtual int NP_nodetype() const;
303
304 /***********
305 * internal *
306 ***********/
307 virtual void set_to_initial_value();
308 virtual int copy_to(cdrAnyMemoryStream& mbs);
309 virtual int copy_from(cdrAnyMemoryStream& mbs);
310
isValid()311 CORBA::Boolean isValid() const { return pd_isValid; }
312 // If true it indicates that the value in the internal
313 // buffer is valid.
314 // Must hold DynAnyImplBase::lock.
315
setValid()316 void setValid() { pd_isValid = 1; }
setInvalid()317 void setInvalid() { pd_isValid = 0; }
318 // Must hold DynAnyImplBase::lock.
319
320 virtual void* _ptrToObjRef(const char* repoId);
321
322 static const char* _PD_repoId;
323 // Fake repoId for use by _ptrToObjRef
324
325 protected:
doWrite(CORBA::TCKind kind)326 cdrAnyMemoryStream& doWrite(CORBA::TCKind kind) {
327 if( tckind() != kind ) throw DynamicAny::DynAny::TypeMismatch();
328 pd_buf.rewindPtrs();
329 setValid();
330 return pd_buf;
331 }
332
doRead(CORBA::TCKind kind)333 cdrAnyMemoryStream& doRead(CORBA::TCKind kind) {
334 if( tckind() != kind || !isValid())
335 throw DynamicAny::DynAny::TypeMismatch();
336 pd_buf.rewindInputPtr();
337 return pd_buf;
338 }
339
340 private:
341 CORBA::Boolean pd_isValid;
342 };
343
344 //////////////////////////////////////////////////////////////////////
345 //////////////////////////// DynFixedImpl ////////////////////////////
346 //////////////////////////////////////////////////////////////////////
347
348 class DynFixedImpl : public DynAnyImpl,
349 public DynamicAny::DynFixed
350 {
351 public:
352 DynFixedImpl(TypeCode_base* tc, CORBA::Boolean is_root=1);
353 virtual ~DynFixedImpl();
354
355 /*******************
356 * public interface *
357 *******************/
358 virtual DynamicAny::DynAny_ptr copy();
359
360 virtual char* get_value();
361 virtual CORBA::Boolean set_value(const char* val);
362
363 /****************************
364 * exposed private interface *
365 ****************************/
366 virtual int NP_nodetype() const;
367
368 /***********
369 * internal *
370 ***********/
371 virtual void set_to_initial_value();
actualTc()372 TypeCode_fixed* actualTc() const {
373 return (TypeCode_fixed*) DynAnyImplBase::actualTc();
374 }
375
376 virtual void _NP_incrRefCount();
377 virtual void _NP_decrRefCount();
378 // Must not hold DynAnyImplBase::refCountLock.
379
380 virtual void* _ptrToObjRef(const char* repoId);
381
382 private:
383 };
384
385 //////////////////////////////////////////////////////////////////////
386 ///////////////////////////// DynEnumImpl ////////////////////////////
387 //////////////////////////////////////////////////////////////////////
388
389 class DynEnumImpl : public DynAnyImpl,
390 public DynamicAny::DynEnum
391 {
392 public:
393 DynEnumImpl(TypeCode_base* tc, CORBA::Boolean is_root=1);
394 virtual ~DynEnumImpl();
395
396 /*******************
397 * public interface *
398 *******************/
399 virtual DynamicAny::DynAny_ptr copy();
400
401 virtual char* get_as_string();
402 virtual void set_as_string(const char* value);
403 virtual CORBA::ULong get_as_ulong();
404 virtual void set_as_ulong(CORBA::ULong value);
405
406 /****************************
407 * exposed private interface *
408 ****************************/
409 virtual int NP_nodetype() const;
410
411 /***********
412 * internal *
413 ***********/
414 virtual void set_to_initial_value();
actualTc()415 TypeCode_enum* actualTc() const {
416 return (TypeCode_enum*) DynAnyImplBase::actualTc();
417 }
418
419 virtual void _NP_incrRefCount();
420 virtual void _NP_decrRefCount();
421 // Must not hold DynAnyImplBase::refCountLock.
422
423 virtual void* _ptrToObjRef(const char* repoId);
424 };
425
426
427 //////////////////////////////////////////////////////////////////////
428 ////////////////////////// DynAnyConstrBase //////////////////////////
429 //////////////////////////////////////////////////////////////////////
430
431 //: Base class for constructed type DynAny's.
432
433 class DynAnyConstrBase : public DynAnyImplBase
434 {
435 public:
436 DynAnyConstrBase(TypeCode_base* tc, int nodetype, CORBA::Boolean is_root);
437 ~DynAnyConstrBase();
438
439 /*******************
440 * public interface *
441 *******************/
442 virtual void assign(DynamicAny::DynAny_ptr dyn_any);
443 virtual CORBA::Boolean equal(DynamicAny::DynAny_ptr dyn_any);
444
445 virtual void insert_boolean (CORBA::Boolean value);
446 virtual void insert_octet (CORBA::Octet value);
447 virtual void insert_char (CORBA::Char value);
448 virtual void insert_short (CORBA::Short value);
449 virtual void insert_ushort (CORBA::UShort value);
450 virtual void insert_long (CORBA::Long value);
451 virtual void insert_ulong (CORBA::ULong value);
452 #ifndef NO_FLOAT
453 virtual void insert_float (CORBA::Float value);
454 virtual void insert_double (CORBA::Double value);
455 #endif
456 virtual void insert_string (const char* value);
457 virtual void insert_reference (CORBA::Object_ptr value);
458 virtual void insert_typecode (CORBA::TypeCode_ptr value);
459 #ifdef HAS_LongLong
460 virtual void insert_longlong (CORBA::LongLong value);
461 virtual void insert_ulonglong (CORBA::ULongLong value);
462 #endif
463 #ifdef HAS_LongDouble
464 virtual void insert_longdouble(CORBA::LongDouble value);
465 #endif
466 virtual void insert_wchar (CORBA::WChar value);
467 virtual void insert_wstring (const CORBA::WChar* value);
468 virtual void insert_any (const CORBA::Any& value);
469 virtual void insert_dyn_any (DynamicAny::DynAny_ptr value);
470 virtual void insert_val (CORBA::ValueBase* value);
471 virtual void insert_abstract (CORBA::AbstractBase_ptr value);
472
473 virtual CORBA::Boolean get_boolean();
474 virtual CORBA::Octet get_octet();
475 virtual CORBA::Char get_char();
476 virtual CORBA::Short get_short();
477 virtual CORBA::UShort get_ushort();
478 virtual CORBA::Long get_long();
479 virtual CORBA::ULong get_ulong();
480 #ifndef NO_FLOAT
481 virtual CORBA::Float get_float();
482 virtual CORBA::Double get_double();
483 #endif
484 virtual char* get_string();
485 virtual CORBA::Object_ptr get_reference();
486 virtual CORBA::TypeCode_ptr get_typecode();
487 #ifdef HAS_LongLong
488 virtual CORBA::LongLong get_longlong();
489 virtual CORBA::ULongLong get_ulonglong();
490 #endif
491 #ifdef HAS_LongDouble
492 virtual CORBA::LongDouble get_longdouble();
493 #endif
494 virtual CORBA::WChar get_wchar();
495 virtual CORBA::WChar* get_wstring();
496 virtual CORBA::Any* get_any();
497 virtual DynamicAny::DynAny_ptr get_dyn_any();
498 virtual CORBA::ValueBase* get_val();
499 virtual CORBA::AbstractBase_ptr get_abstract();
500
501 virtual void insert_boolean_seq (CORBA::BooleanSeq& value);
502 virtual void insert_octet_seq (CORBA::OctetSeq& value);
503 virtual void insert_char_seq (CORBA::CharSeq& value);
504 virtual void insert_short_seq (CORBA::ShortSeq& value);
505 virtual void insert_ushort_seq (CORBA::UShortSeq& value);
506 virtual void insert_long_seq (CORBA::LongSeq& value);
507 virtual void insert_ulong_seq (CORBA::ULongSeq& value);
508 #ifndef NO_FLOAT
509 virtual void insert_float_seq (CORBA::FloatSeq& value);
510 virtual void insert_double_seq (CORBA::DoubleSeq& value);
511 #endif
512 #ifdef HAS_LongLong
513 virtual void insert_longlong_seq (CORBA::LongLongSeq& value);
514 virtual void insert_ulonglong_seq (CORBA::ULongLongSeq& value);
515 #endif
516 #ifdef HAS_LongDouble
517 virtual void insert_longdouble_seq(CORBA::LongDoubleSeq& value);
518 #endif
519 virtual void insert_wchar_seq (CORBA::WCharSeq& value);
520
521 virtual CORBA::BooleanSeq* get_boolean_seq();
522 virtual CORBA::OctetSeq* get_octet_seq();
523 virtual CORBA::CharSeq* get_char_seq();
524 virtual CORBA::ShortSeq* get_short_seq();
525 virtual CORBA::UShortSeq* get_ushort_seq();
526 virtual CORBA::LongSeq* get_long_seq();
527 virtual CORBA::ULongSeq* get_ulong_seq();
528 #ifndef NO_FLOAT
529 virtual CORBA::FloatSeq* get_float_seq();
530 virtual CORBA::DoubleSeq* get_double_seq();
531 #endif
532 #ifdef HAS_LongLong
533 virtual CORBA::LongLongSeq* get_longlong_seq();
534 virtual CORBA::ULongLongSeq* get_ulonglong_seq();
535 #endif
536 #ifdef HAS_LongDouble
537 virtual CORBA::LongDoubleSeq* get_longdouble_seq();
538 #endif
539 virtual CORBA::WCharSeq* get_wchar_seq();
540
541 virtual CORBA::Boolean seek(CORBA::Long index);
542 virtual void rewind();
543 virtual CORBA::Boolean next();
544 virtual CORBA::ULong component_count();
545 virtual DynamicAny::DynAny_ptr current_component();
546
547 /***********
548 * internal *
549 ***********/
550 virtual void set_to_initial_value();
551 virtual int copy_to(cdrAnyMemoryStream& mbs);
552 virtual int copy_from(cdrAnyMemoryStream& mbs);
553 virtual void onDispose();
554
555 static const char* _PD_repoId;
556 // Fake repoId for use by _ptrToObjRef
557
558 protected:
559 void setNumComponents(unsigned n);
560 // May be called by derived classes to set/change the number of
561 // components.
562 // Concurrency: hold DynAnyImplBase::lock (unless called from
563 // a constructor)
564
565 virtual TypeCode_base* nthComponentTC(unsigned n) = 0;
566 // Returns the TypeCode of the n'th component. Overriden by descendants.
567 // This does not return a new reference - so it should not be
568 // released. <n> MUST be in the range [0..pd_n_components).
569 // Must hold DynAnyImplBase::lock.
570
currentKind()571 CORBA::TCKind currentKind() {
572 return TypeCode_base::NP_expand(nthComponentTC(pd_curr_index))->NP_kind();
573 }
574 // Return the alias expanded CORBA::TCKind of the current component.
575 // There MUST be a valid current component.
576 // Must hold DynAnyImplBase::lock.
577
canAppendComponent(unsigned i)578 CORBA::Boolean canAppendComponent(unsigned i) const {
579 return i == pd_n_really_in_buf && i == pd_n_in_buf && i < pd_first_in_comp;
580 }
581 // True if the given component can be appended to <pd_buf>.
582 // The result is only valid if <i> is in range.
583 // Must hold DynAnyImplBase::lock.
584
writeCurrent(CORBA::TCKind kind)585 cdrAnyMemoryStream& writeCurrent(CORBA::TCKind kind) {
586 if( pd_curr_index < 0 )
587 throw DynamicAny::DynAny::InvalidValue();
588 if( currentKind() != kind )
589 throw DynamicAny::DynAny::TypeMismatch();
590 if( canAppendComponent(pd_curr_index) ) {
591 pd_n_in_buf++;
592 pd_n_really_in_buf++;
593 return pd_buf;
594 } else {
595 DynAnyImpl* cc = ToDynAnyImpl(getCurrent());
596 cc->pd_buf.rewindPtrs();
597 cc->setValid();
598 return cc->pd_buf;
599 }
600 }
601 // Helper function for writing primitive values into the current
602 // component. It returns a reference to the buffer which the value
603 // should be inserted into. If the value can be appended to <pd_buf>,
604 // then <pd_buf> is returned, otherwise it is the buffer of the
605 // child DynAny.
606 // Checks also the there is a current component, and that its type
607 // is the same as the value being inserted.
608 // Must hold DynAnyImplBase::lock.
609
readCurrent(CORBA::TCKind kind)610 cdrAnyMemoryStream& readCurrent(CORBA::TCKind kind) {
611 if( pd_curr_index < 0 )
612 throw DynamicAny::DynAny::InvalidValue();
613 if( currentKind() != kind )
614 throw DynamicAny::DynAny::TypeMismatch();
615 if( pd_curr_index < (int)pd_n_in_buf ) {
616 if( pd_read_index != pd_curr_index ) seekTo(pd_curr_index);
617 pd_read_index++;
618 return pd_buf;
619 }
620 else if( pd_curr_index >= (int)pd_first_in_comp ) {
621 DynAnyImpl* cc = ToDynAnyImpl(getCurrent());
622 if( !cc->isValid() ) throw DynamicAny::DynAny::InvalidValue();
623 cc->pd_buf.rewindInputPtr();
624 return cc->pd_buf;
625 }
626 else throw DynamicAny::DynAny::InvalidValue();
627 #ifdef NEED_DUMMY_RETURN
628 return pd_buf;
629 #endif
630 }
631 // Helper function for reading a primitive value from the current
632 // component. Returns a reference to the buffer from which the
633 // value may be extracted. It checks that <pd_curr_index> is valid,
634 // and the component is of the type expected.
635 // Must hold DynAnyImplBase::lock.
636
637 public:
638 enum SeqLocation { SEQ_HERE, SEQ_COMPONENT };
639
640 protected:
641 virtual SeqLocation prepareSequenceWrite(CORBA::TCKind kind,
642 CORBA::ULong len) = 0;
643 // Used by insert_..._seq functions. Check if a sequence with the
644 // specified kind and length can be inserted, and prepare for the
645 // write. Returns SEQ_HERE if it can be inserted in this DynAny's
646 // <pd_buf>, SEQ_COMPONENT if it can be inserted in the current
647 // component. Throws InvalidValue if no current component or wrong
648 // length, TypeMismatch if the kind is wrong.
649
650 virtual SeqLocation prepareSequenceRead(CORBA::TCKind kind) = 0;
651 // Used by get_..._seq functions. Check if a sequence with the
652 // specified kind can be read. Returns SEQ_HERE if this DynAny is a
653 // sequence or array of the specified kind, SEQ_COMPONENT if the
654 // current component is a sequence or array of the specified kind.
655 // If there is a current component but it's not a sequence of the
656 // right kind, throws TypeMismatch; if there is no current
657 // component, throws InvalidValue.
658
getCurrent()659 DynAnyImplBase* getCurrent() {
660 if( pd_curr_index < (int)pd_first_in_comp )
661 createComponent(pd_curr_index);
662 return pd_components[pd_curr_index];
663 }
664 // If not already there, puts the current component (and those
665 // following it) into <pd_components>, and returns it. There
666 // must be a current component.
667 // Must hold DynAnyImplBase::lock.
668
669 void createComponent(unsigned n);
670 // If it does not already exist, create a DynAny for the n'th
671 // component. Ensures also that DynAny's are created for all
672 // components following that one.
673 // Requires n < pd_n_components.
674 // Must hold DynAnyImplBase::lock.
675
676 void seekTo(unsigned n);
677 // Seek the internal buffer so as to read the i'th component.
678 // Does not throw any exceptions.
679 // Requires n < pd_n_in_buf.
680 // Must hold DynAnyImplBase::lock.
681
682 int component_to_any(unsigned i, CORBA::Any& a);
683 // Copy the i'th component into <a>. Returns 0 if that
684 // component is not properly initialised.
685 // Does not throw any exceptions.
686 // Requires i < pd_n_components.
687 // Must hold DynAnyImplBase::lock.
688
689 int component_from_any(unsigned i, const CORBA::Any& a);
690 // Sets the value of the i'th component to that in <a>.
691 // Returns 0 if the value in the Any is of the wrong
692 // type, or the Any has not been initialised.
693 // Does not throw any exceptions.
694 // Requires i < pd_n_components.
695 // Must hold DynAnyImplBase::lock.
696
697 omnivector<DynAnyImplBase*> pd_components;
698 // Sequence of pointers to components that are not stored in <pd_buf>.
699 // The length of this sequence is always equal to pd_n_components.
700
701 unsigned pd_n_components;
702 // The total number of components this value has.
703
704 unsigned pd_n_in_buf;
705 // Components in the range [0..pd_n_in_buf) are in <pd_buf>.
706 // pd_n_in_buf <= pd_first_in_comp.
707
708 unsigned pd_n_really_in_buf;
709 // The number of components which have actually been written into
710 // <pd_buf>. This value may be greater than <pd_n_components> or
711 // <pd_first_in_comp>.
712
713 unsigned pd_first_in_comp;
714 // Components in the range [pd_first_in_comp..pd_n_components)
715 // are in pd_components. Thus those in the range
716 // [pd_n_in_buf..pd_first_in_comp) are not yet defined.
717
718 int pd_curr_index;
719 // The index of the 'current component'. If this is -1 then
720 // there is no current component. If there are zero components
721 // then this is always -1.
722
723 int pd_read_index;
724 // The index of the component that the buffer's read marker is
725 // pointing at. So if pd_curr_index == pd_read_index, and the
726 // component is in the buffer, then it can be read out.
727 };
728
729
730
731 //////////////////////////////////////////////////////////////////////
732 //////////////////////////// DynStructImpl ///////////////////////////
733 //////////////////////////////////////////////////////////////////////
734
735 //: DynAny for structure and exception types.
736
737 class DynStructImpl : public DynAnyConstrBase,
738 public DynamicAny::DynStruct
739 {
740 public:
741 DynStructImpl(TypeCode_base* tc, CORBA::Boolean is_root=1);
742 virtual ~DynStructImpl();
743
744 /*******************
745 * public interface *
746 *******************/
747 virtual DynamicAny::DynAny_ptr copy();
748
749 virtual char* current_member_name();
750 virtual CORBA::TCKind current_member_kind();
751 virtual DynamicAny::NameValuePairSeq* get_members();
752 virtual void set_members(const DynamicAny::NameValuePairSeq& value);
753 virtual DynamicAny::NameDynAnyPairSeq* get_members_as_dyn_any();
754 virtual void set_members_as_dyn_any(const DynamicAny::NameDynAnyPairSeq& value);
755
756 /****************************
757 * exposed private interface *
758 ****************************/
759 virtual int NP_nodetype() const;
760
761 /***********
762 * internal *
763 ***********/
764 virtual TypeCode_base* nthComponentTC(unsigned n);
765 // Overrides DynAnyConstrBase
766
767 virtual SeqLocation prepareSequenceWrite(CORBA::TCKind kind,
768 CORBA::ULong len);
769 virtual SeqLocation prepareSequenceRead(CORBA::TCKind kind);
770
771 virtual void _NP_incrRefCount();
772 virtual void _NP_decrRefCount();
773 // Must not hold DynAnyImplBase::refCountLock.
774
775 virtual void* _ptrToObjRef(const char* repoId);
776 };
777
778
779
780 //////////////////////////////////////////////////////////////////////
781 /////////////////////////// DynUnionDisc /////////////////////////////
782 //////////////////////////////////////////////////////////////////////
783
784 //: DynAny for the discriminator of a union.
785 // Behaves like a DynAnyImpl, but catches any updates, and informs
786 // the union (which this is the discriminator of) so that it may
787 // update its member appropriately.
788
789 class DynUnionDisc : public DynAnyImpl {
790 public:
DynUnionDisc(TypeCode_base * tc,int nodetype,DynUnionImpl * un)791 DynUnionDisc(TypeCode_base* tc, int nodetype, DynUnionImpl* un)
792 : DynAnyImpl(tc, nodetype, DYNANY_CHILD),
793 pd_union(un) {}
794 virtual ~DynUnionDisc();
795
796 /*******************
797 * public interface *
798 *******************/
799 virtual void assign(DynamicAny::DynAny_ptr dyn_any);
800
801 virtual void insert_boolean (CORBA::Boolean value);
802 virtual void insert_octet (CORBA::Octet value);
803 virtual void insert_char (CORBA::Char value);
804 virtual void insert_short (CORBA::Short value);
805 virtual void insert_ushort (CORBA::UShort value);
806 virtual void insert_long (CORBA::Long value);
807 virtual void insert_ulong (CORBA::ULong value);
808 #ifndef NO_FLOAT
809 virtual void insert_float (CORBA::Float value);
810 virtual void insert_double (CORBA::Double value);
811 #endif
812 virtual void insert_string (const char* value);
813 virtual void insert_reference (CORBA::Object_ptr value);
814 virtual void insert_typecode (CORBA::TypeCode_ptr value);
815 #ifdef HAS_LongLong
816 virtual void insert_longlong (CORBA::LongLong value);
817 virtual void insert_ulonglong (CORBA::ULongLong value);
818 #endif
819 #ifdef HAS_LongDouble
820 virtual void insert_longdouble(CORBA::LongDouble value);
821 #endif
822 virtual void insert_wchar (CORBA::WChar value);
823 virtual void insert_wstring (const CORBA::WChar* value);
824 virtual void insert_any (const CORBA::Any& value);
825 virtual void insert_dyn_any (DynamicAny::DynAny_ptr value);
826 virtual void insert_val (CORBA::ValueBase* value);
827 virtual void insert_abstract (CORBA::AbstractBase_ptr value);
828
829 /****************************
830 * exposed private interface *
831 ****************************/
832 virtual int NP_nodetype() const;
833
834 /***********
835 * internal *
836 ***********/
837 void set_to_initial_value();
838
detach()839 void detach() {
840 pd_union = 0;
841 DynAnyImpl::detach();
842 }
843 virtual void set_value(TypeCode_union::Discriminator v);
844 // Must NOT hold DynAnyImplBase::lock.
845
846 protected:
847 DynUnionImpl* pd_union;
848 // Pointer to the parent union, or 0 if detached.
849 };
850
851 //////////////////////////////////////////////////////////////////////
852 ///////////////////////// DynUnionEnumDisc ///////////////////////////
853 //////////////////////////////////////////////////////////////////////
854
855 //: DynAny for the (enum) discriminator of a union.
856
857 class DynUnionEnumDisc : public DynUnionDisc,
858 public DynamicAny::DynEnum
859 {
860 public:
861 DynUnionEnumDisc(TypeCode_base* tc, DynUnionImpl* un);
862 virtual ~DynUnionEnumDisc();
863
864 /*******************
865 * public interface *
866 *******************/
867 virtual DynamicAny::DynAny_ptr copy();
868
869 virtual char* get_as_string();
870 virtual void set_as_string(const char* value);
871 virtual CORBA::ULong get_as_ulong();
872 virtual void set_as_ulong(CORBA::ULong value);
873
874 /****************************
875 * exposed private interface *
876 ****************************/
877 virtual int NP_nodetype() const;
878
879 /***********
880 * internal *
881 ***********/
882 void set_to_initial_value();
883 virtual void set_value(TypeCode_union::Discriminator v);
884 // Must NOT hold DynAnyImplBase::lock.
885
actualTc()886 TypeCode_enum* actualTc() const {
887 return (TypeCode_enum*) DynAnyImplBase::actualTc();
888 }
889
890 virtual void _NP_incrRefCount();
891 virtual void _NP_decrRefCount();
892 // Must not hold DynAnyImplBase::refCountLock.
893
894 virtual void* _ptrToObjRef(const char* repoId);
895 };
896
897 //////////////////////////////////////////////////////////////////////
898 /////////////////////////// DynUnionImpl /////////////////////////////
899 //////////////////////////////////////////////////////////////////////
900
901 class DynUnionImpl : public DynAnyImplBase,
902 public DynamicAny::DynUnion
903 {
904 public:
905 DynUnionImpl(TypeCode_base* tc, CORBA::Boolean is_root=1);
906 virtual ~DynUnionImpl();
907
908 /*******************
909 * public interface *
910 *******************/
911 virtual void assign(DynamicAny::DynAny_ptr dyn_any);
912 virtual DynamicAny::DynAny_ptr copy();
913 virtual CORBA::Boolean equal(DynamicAny::DynAny_ptr dyn_any);
914
915 virtual void insert_boolean (CORBA::Boolean value);
916 virtual void insert_octet (CORBA::Octet value);
917 virtual void insert_char (CORBA::Char value);
918 virtual void insert_short (CORBA::Short value);
919 virtual void insert_ushort (CORBA::UShort value);
920 virtual void insert_long (CORBA::Long value);
921 virtual void insert_ulong (CORBA::ULong value);
922 #ifndef NO_FLOAT
923 virtual void insert_float (CORBA::Float value);
924 virtual void insert_double (CORBA::Double value);
925 #endif
926 virtual void insert_string (const char* value);
927 virtual void insert_reference (CORBA::Object_ptr value);
928 virtual void insert_typecode (CORBA::TypeCode_ptr value);
929 #ifdef HAS_LongLong
930 virtual void insert_longlong (CORBA::LongLong value);
931 virtual void insert_ulonglong (CORBA::ULongLong value);
932 #endif
933 #ifdef HAS_LongDouble
934 virtual void insert_longdouble(CORBA::LongDouble value);
935 #endif
936 virtual void insert_wchar (CORBA::WChar value);
937 virtual void insert_wstring (const CORBA::WChar* value);
938 virtual void insert_any (const CORBA::Any& value);
939 virtual void insert_dyn_any (DynamicAny::DynAny_ptr value);
940 virtual void insert_val (CORBA::ValueBase* value);
941 virtual void insert_abstract (CORBA::AbstractBase_ptr value);
942
943 virtual CORBA::Boolean get_boolean();
944 virtual CORBA::Octet get_octet();
945 virtual CORBA::Char get_char();
946 virtual CORBA::Short get_short();
947 virtual CORBA::UShort get_ushort();
948 virtual CORBA::Long get_long();
949 virtual CORBA::ULong get_ulong();
950 #ifndef NO_FLOAT
951 virtual CORBA::Float get_float();
952 virtual CORBA::Double get_double();
953 #endif
954 virtual char* get_string();
955 virtual CORBA::Object_ptr get_reference();
956 virtual CORBA::TypeCode_ptr get_typecode();
957 #ifdef HAS_LongLong
958 virtual CORBA::LongLong get_longlong();
959 virtual CORBA::ULongLong get_ulonglong();
960 #endif
961 #ifdef HAS_LongDouble
962 virtual CORBA::LongDouble get_longdouble();
963 #endif
964 virtual CORBA::WChar get_wchar();
965 virtual CORBA::WChar* get_wstring();
966 virtual CORBA::Any* get_any();
967 virtual DynamicAny::DynAny_ptr get_dyn_any();
968 virtual CORBA::ValueBase* get_val();
969 virtual CORBA::AbstractBase_ptr get_abstract();
970
971 virtual void insert_boolean_seq (CORBA::BooleanSeq& value);
972 virtual void insert_octet_seq (CORBA::OctetSeq& value);
973 virtual void insert_char_seq (CORBA::CharSeq& value);
974 virtual void insert_short_seq (CORBA::ShortSeq& value);
975 virtual void insert_ushort_seq (CORBA::UShortSeq& value);
976 virtual void insert_long_seq (CORBA::LongSeq& value);
977 virtual void insert_ulong_seq (CORBA::ULongSeq& value);
978 #ifndef NO_FLOAT
979 virtual void insert_float_seq (CORBA::FloatSeq& value);
980 virtual void insert_double_seq (CORBA::DoubleSeq& value);
981 #endif
982 #ifdef HAS_LongLong
983 virtual void insert_longlong_seq (CORBA::LongLongSeq& value);
984 virtual void insert_ulonglong_seq (CORBA::ULongLongSeq& value);
985 #endif
986 #ifdef HAS_LongDouble
987 virtual void insert_longdouble_seq(CORBA::LongDoubleSeq& value);
988 #endif
989 virtual void insert_wchar_seq (CORBA::WCharSeq& value);
990
991 virtual CORBA::BooleanSeq* get_boolean_seq();
992 virtual CORBA::OctetSeq* get_octet_seq();
993 virtual CORBA::CharSeq* get_char_seq();
994 virtual CORBA::ShortSeq* get_short_seq();
995 virtual CORBA::UShortSeq* get_ushort_seq();
996 virtual CORBA::LongSeq* get_long_seq();
997 virtual CORBA::ULongSeq* get_ulong_seq();
998 #ifndef NO_FLOAT
999 virtual CORBA::FloatSeq* get_float_seq();
1000 virtual CORBA::DoubleSeq* get_double_seq();
1001 #endif
1002 #ifdef HAS_LongLong
1003 virtual CORBA::LongLongSeq* get_longlong_seq();
1004 virtual CORBA::ULongLongSeq* get_ulonglong_seq();
1005 #endif
1006 #ifdef HAS_LongDouble
1007 virtual CORBA::LongDoubleSeq* get_longdouble_seq();
1008 #endif
1009 virtual CORBA::WCharSeq* get_wchar_seq();
1010
1011 virtual CORBA::Boolean seek(CORBA::Long index);
1012 virtual void rewind();
1013 virtual CORBA::Boolean next();
1014 virtual CORBA::ULong component_count();
1015 virtual DynamicAny::DynAny_ptr current_component();
1016
1017 virtual DynamicAny::DynAny_ptr get_discriminator();
1018 virtual void set_discriminator(DynamicAny::DynAny_ptr d);
1019 virtual void set_to_default_member();
1020 virtual void set_to_no_active_member();
1021 virtual CORBA::Boolean has_no_active_member();
1022 virtual CORBA::TCKind discriminator_kind();
1023 virtual DynamicAny::DynAny_ptr member();
1024 virtual char* member_name();
1025 virtual CORBA::TCKind member_kind();
1026 virtual CORBA::Boolean is_set_to_default_member();
1027
1028 /****************************
1029 * exposed private interface *
1030 ****************************/
1031 virtual int NP_nodetype() const;
1032
1033 virtual void _NP_incrRefCount();
1034 virtual void _NP_decrRefCount();
1035 // Must not hold DynAnyImplBase::refCountLock.
1036
1037 virtual void* _ptrToObjRef(const char* repoId);
1038
1039 static const char* _PD_repoId;
1040 // Fake repoId for use by _ptrToObjRef
1041
1042 /***********
1043 * internal *
1044 ***********/
1045 virtual void set_to_initial_value();
1046 virtual int copy_to(cdrAnyMemoryStream& mbs);
1047 virtual int copy_from(cdrAnyMemoryStream& mbs);
1048 virtual void onDispose();
1049
1050 void discriminatorHasChanged();
1051 // If necassary detaches the old member, and creates a new member
1052 // of the appropriate type.
1053
NP_disc_value()1054 inline TypeCode_union::Discriminator NP_disc_value() const {
1055 return pd_disc_value;
1056 }
NP_disc_index()1057 inline CORBA::Long NP_disc_index() const {
1058 return pd_member ? pd_disc_index : -1;
1059 }
1060
actualTc()1061 TypeCode_union* actualTc() const {
1062 return (TypeCode_union*) DynAnyImplBase::actualTc();
1063 }
1064
1065 private:
writeCurrent(CORBA::TCKind kind)1066 cdrAnyMemoryStream& writeCurrent(CORBA::TCKind kind) {
1067 switch( pd_curr_index ) {
1068 case 0:
1069 if( kind != pd_disc_kind ) throw DynamicAny::DynAny::TypeMismatch();
1070 pd_disc->pd_buf.rewindPtrs();
1071 pd_disc->setValid();
1072 return pd_disc->pd_buf;
1073 case 1:
1074 if( pd_member_kind != kind ) throw DynamicAny::DynAny::TypeMismatch();
1075 pd_member->pd_buf.rewindPtrs();
1076 // Must be a DynAnyImpl ...
1077 ToDynAnyImpl(pd_member)->setValid();
1078 return pd_member->pd_buf;
1079 default:
1080 throw DynamicAny::DynAny::InvalidValue();
1081 }
1082 #ifdef NEED_DUMMY_RETURN
1083 return pd_buf;
1084 #endif
1085 }
1086
readCurrent(CORBA::TCKind kind)1087 cdrAnyMemoryStream& readCurrent(CORBA::TCKind kind) {
1088 switch( pd_curr_index ) {
1089 case 0:
1090 if( kind != pd_disc_kind || !pd_disc->isValid() )
1091 throw DynamicAny::DynAny::TypeMismatch();
1092 pd_disc->pd_buf.rewindInputPtr();
1093 return pd_disc->pd_buf;
1094 case 1:
1095 // If !pd_member, then pd_member_kind == tk_null.
1096 if( pd_member_kind != kind || !ToDynAnyImpl(pd_member)->isValid() )
1097 throw DynamicAny::DynAny::TypeMismatch();
1098 pd_member->pd_buf.rewindInputPtr();
1099 return pd_member->pd_buf;
1100 default:
1101 throw DynamicAny::DynAny::InvalidValue();
1102 }
1103 #ifdef NEED_DUMMY_RETURN
1104 return pd_buf;
1105 #endif
1106 }
1107
detachMember()1108 void detachMember() {
1109 if( pd_member ) {
1110 pd_member->detach();
1111 pd_member->destroy();
1112 pd_member->_NP_decrRefCount();
1113 pd_member = 0;
1114 pd_member_kind = CORBA::tk_null;
1115 }
1116 }
1117
1118 /*
1119 ** DynUnionImpl does not use an internal buffer to store the value.
1120 ** Instead an instance of a DynAny is created for each of the
1121 ** discriminator and the member value.
1122 */
1123
1124 DynUnionDisc* pd_disc;
1125 TypeCode_base* pd_disc_type;
1126 CORBA::TCKind pd_disc_kind;
1127 TypeCode_union::Discriminator pd_disc_value;
1128 CORBA::Long pd_disc_index; // invalid if !pd_member
1129
1130 DynAnyImplBase* pd_member; // may be 0
1131 CORBA::TCKind pd_member_kind; // tk_null if !pd_member
1132
1133 int pd_curr_index; // -1, 0 or 1
1134 };
1135
1136 //////////////////////////////////////////////////////////////////////
1137 ///////////////////////// DynSequenceImpl ////////////////////////////
1138 //////////////////////////////////////////////////////////////////////
1139
1140 class DynSequenceImpl : public DynAnyConstrBase,
1141 public DynamicAny::DynSequence
1142 {
1143 public:
1144 DynSequenceImpl(TypeCode_base* tc, CORBA::Boolean is_root=1);
1145 virtual ~DynSequenceImpl();
1146
1147 /*******************
1148 * public interface *
1149 *******************/
1150 virtual DynamicAny::DynAny_ptr copy();
1151
1152 virtual CORBA::ULong get_length();
1153 virtual void set_length (CORBA::ULong len);
1154 virtual DynamicAny::AnySeq* get_elements();
1155 virtual void set_elements(const DynamicAny::AnySeq& value);
1156 virtual DynamicAny::DynAnySeq* get_elements_as_dyn_any();
1157 virtual void set_elements_as_dyn_any(const DynamicAny::DynAnySeq& value);
1158
1159 /****************************
1160 * exposed private interface *
1161 ****************************/
1162 virtual int NP_nodetype() const;
1163
1164 virtual void _NP_incrRefCount();
1165 virtual void _NP_decrRefCount();
1166 // Must not hold DynAnyImplBase::refCountLock.
1167
1168 virtual void* _ptrToObjRef(const char* repoId);
1169
1170 /***********
1171 * internal *
1172 ***********/
1173 virtual int copy_to(cdrAnyMemoryStream& mbs);
1174 virtual int copy_from(cdrAnyMemoryStream& mbs);
1175 virtual TypeCode_base* nthComponentTC(unsigned n);
1176 // Overrides DynAnyConstrBase
1177
1178 virtual SeqLocation prepareSequenceWrite(CORBA::TCKind kind,
1179 CORBA::ULong len);
1180
1181 virtual SeqLocation prepareSequenceRead(CORBA::TCKind kind);
1182
1183 private:
1184 CORBA::ULong pd_bound; // 0 if unbounded sequence, bound otherwise
1185 };
1186
1187
1188 //////////////////////////////////////////////////////////////////////
1189 /////////////////////////// DynArrayImpl /////////////////////////////
1190 //////////////////////////////////////////////////////////////////////
1191
1192 class DynArrayImpl : public DynAnyConstrBase,
1193 public DynamicAny::DynArray
1194 {
1195 public:
1196 DynArrayImpl(TypeCode_base* tc, CORBA::Boolean is_root=1);
1197 virtual ~DynArrayImpl();
1198
1199 /*******************
1200 * public interface *
1201 *******************/
1202 virtual DynamicAny::DynAny_ptr copy();
1203
1204 virtual DynamicAny::AnySeq* get_elements();
1205 virtual void set_elements(const DynamicAny::AnySeq& value);
1206 virtual DynamicAny::DynAnySeq* get_elements_as_dyn_any();
1207 virtual void set_elements_as_dyn_any(const DynamicAny::DynAnySeq& value);
1208
1209 /****************************
1210 * exposed private interface *
1211 ****************************/
1212 virtual int NP_nodetype() const;
1213
1214 virtual void _NP_incrRefCount();
1215 virtual void _NP_decrRefCount();
1216 // Must not hold DynAnyImplBase::refCountLock.
1217
1218 virtual void* _ptrToObjRef(const char* repoId);
1219
1220 /***********
1221 * internal *
1222 ***********/
1223 virtual TypeCode_base* nthComponentTC(unsigned n);
1224 // Overrides DynAnyConstrBase
1225
1226 virtual SeqLocation prepareSequenceWrite(CORBA::TCKind kind,
1227 CORBA::ULong len);
1228
1229 virtual SeqLocation prepareSequenceRead(CORBA::TCKind kind);
1230 private:
1231 };
1232
1233
1234 //////////////////////////////////////////////////////////////////////
1235 //////////////////////////// DynValueImpl ////////////////////////////
1236 //////////////////////////////////////////////////////////////////////
1237
1238 //: DynAny for valuetypes
1239
1240 class DynValueImpl : public DynAnyConstrBase,
1241 public DynamicAny::DynValue
1242 {
1243 public:
1244 DynValueImpl(TypeCode_base* tc, CORBA::Boolean is_root=1);
1245 virtual ~DynValueImpl();
1246
1247 /*******************
1248 * public interface *
1249 *******************/
1250 virtual DynamicAny::DynAny_ptr copy();
1251
1252 virtual CORBA::Boolean is_null();
1253 virtual void set_to_null();
1254 virtual void set_to_value();
1255
1256 virtual char* current_member_name();
1257 virtual CORBA::TCKind current_member_kind();
1258 virtual DynamicAny::NameValuePairSeq* get_members();
1259 virtual void set_members(const DynamicAny::NameValuePairSeq& value);
1260 virtual DynamicAny::NameDynAnyPairSeq* get_members_as_dyn_any();
1261 virtual void set_members_as_dyn_any(const DynamicAny::NameDynAnyPairSeq& value);
1262
1263 /****************************
1264 * exposed private interface *
1265 ****************************/
1266 virtual int NP_nodetype() const;
1267
1268 /***********
1269 * internal *
1270 ***********/
1271 virtual void set_to_initial_value();
1272 virtual int copy_to(cdrAnyMemoryStream& mbs);
1273 virtual int copy_from(cdrAnyMemoryStream& mbs);
1274 virtual TypeCode_base* nthComponentTC(unsigned n);
1275 // Overrides DynAnyConstrBase
1276
1277 virtual SeqLocation prepareSequenceWrite(CORBA::TCKind kind,
1278 CORBA::ULong len);
1279 virtual SeqLocation prepareSequenceRead(CORBA::TCKind kind);
1280
1281 virtual void _NP_incrRefCount();
1282 virtual void _NP_decrRefCount();
1283 // Must not hold DynAnyImplBase::refCountLock.
1284
1285 virtual void* _ptrToObjRef(const char* repoId);
1286
1287 private:
1288 omniTypedefs::TypeCodeSeq pd_componentTCs;
1289 CORBA::StringSeq pd_componentNames;
1290 CORBA::Boolean pd_null;
1291 };
1292
1293
1294
1295 //////////////////////////////////////////////////////////////////////
1296 //////////////////////////// DynValueBoxImpl /////////////////////////
1297 //////////////////////////////////////////////////////////////////////
1298
1299 //: DynAny for valueboxes
1300
1301 class DynValueBoxImpl : public DynAnyConstrBase,
1302 public DynamicAny::DynValueBox
1303 {
1304 public:
1305 DynValueBoxImpl(TypeCode_base* tc, CORBA::Boolean is_root=1);
1306 virtual ~DynValueBoxImpl();
1307
1308 /*******************
1309 * public interface *
1310 *******************/
1311 virtual DynamicAny::DynAny_ptr copy();
1312
1313 virtual CORBA::Boolean is_null();
1314 virtual void set_to_null();
1315 virtual void set_to_value();
1316
1317 virtual CORBA::Any* get_boxed_value();
1318 virtual void set_boxed_value(const CORBA::Any& value);
1319 virtual DynamicAny::DynAny_ptr get_boxed_value_as_dyn_any();
1320 virtual void set_boxed_value_as_dyn_any(DynamicAny::DynAny_ptr value);
1321
1322 /****************************
1323 * exposed private interface *
1324 ****************************/
1325 virtual int NP_nodetype() const;
1326
1327 /***********
1328 * internal *
1329 ***********/
1330 virtual void set_to_initial_value();
1331 virtual int copy_to(cdrAnyMemoryStream& mbs);
1332 virtual int copy_from(cdrAnyMemoryStream& mbs);
1333 virtual TypeCode_base* nthComponentTC(unsigned n);
1334 // Overrides DynAnyConstrBase
1335
1336 virtual SeqLocation prepareSequenceWrite(CORBA::TCKind kind,
1337 CORBA::ULong len);
1338 virtual SeqLocation prepareSequenceRead(CORBA::TCKind kind);
1339
1340 virtual void _NP_incrRefCount();
1341 virtual void _NP_decrRefCount();
1342 // Must not hold DynAnyImplBase::refCountLock.
1343
1344 virtual void* _ptrToObjRef(const char* repoId);
1345
1346 private:
1347 CORBA::Boolean pd_null;
1348 };
1349
1350
1351 //////////////////////////////////////////////////////////////////////
1352 ////////////////////////////// Narrowing /////////////////////////////
1353 //////////////////////////////////////////////////////////////////////
1354
1355 // <p> must not be nil.
ToDynAnyImplBase(DynamicAny::DynAny_ptr p)1356 inline DynAnyImplBase* ToDynAnyImplBase(DynamicAny::DynAny_ptr p)
1357 {
1358 DynAnyImplBase* daib =
1359 (DynAnyImplBase*)p->_ptrToObjRef(DynAnyImplBase::_PD_repoId);
1360 OMNIORB_ASSERT(daib);
1361 return daib;
1362 }
1363
1364 // <p> must not be nil.
ToDynAnyImpl(DynamicAny::DynAny_ptr p)1365 inline DynAnyImpl* ToDynAnyImpl(DynamicAny::DynAny_ptr p)
1366 {
1367 DynAnyImpl* dai = (DynAnyImpl*)p->_ptrToObjRef(DynAnyImpl::_PD_repoId);
1368 OMNIORB_ASSERT(dai);
1369 return dai;
1370 }
1371
1372 // <p> must not be nil.
ToDynAnyConstrBase(DynamicAny::DynAny_ptr p)1373 inline DynAnyConstrBase* ToDynAnyConstrBase(DynamicAny::DynAny_ptr p)
1374 {
1375 DynAnyConstrBase* dacb = (DynAnyConstrBase*)p->
1376 _ptrToObjRef(DynAnyConstrBase::_PD_repoId);
1377 OMNIORB_ASSERT(dacb);
1378 return dacb;
1379 }
1380
1381 // <p> must not be nil.
ToDynUnionImpl(DynamicAny::DynAny_ptr p)1382 inline DynUnionImpl* ToDynUnionImpl(DynamicAny::DynAny_ptr p)
1383 {
1384 DynUnionImpl* daui = (DynUnionImpl*)p->
1385 _ptrToObjRef(DynUnionImpl::_PD_repoId);
1386 OMNIORB_ASSERT(daui);
1387 return daui;
1388 }
1389
1390 //////////////////////////////////////////////////////////////////////
1391 /////////////////////////// DynAnyFactoryImpl ////////////////////////
1392 //////////////////////////////////////////////////////////////////////
1393
1394 class DynAnyFactoryImpl : public DynamicAny::DynAnyFactory
1395 {
1396 public:
DynAnyFactoryImpl()1397 DynAnyFactoryImpl() :
1398 OMNIORB_BASE_CTOR(DynamicAny::)DynAnyFactory(0), pd_refCount(1) {}
1399
1400 virtual ~DynAnyFactoryImpl();
1401
1402 // IDL defined functions
1403 virtual DynamicAny::DynAny_ptr
1404 create_dyn_any(const CORBA::Any& value);
1405
1406 virtual DynamicAny::DynAny_ptr
1407 create_dyn_any_from_type_code(CORBA::TypeCode_ptr type);
1408
1409 // Internals
1410 virtual void* _ptrToObjRef(const char* repoId);
1411
1412 virtual void _NP_incrRefCount();
1413 virtual void _NP_decrRefCount();
1414
1415 static DynamicAny::DynAnyFactory_ptr theFactory();
1416
1417 private:
1418 int pd_refCount;
1419 };
1420
1421
1422 OMNI_NAMESPACE_END(omni)
1423
1424 #endif // __DYNANYIMPL_H__
1425