Issue 2614: Setting the TypeCode of an Any without setting a value (cxx_revision) Source: (, ) Nature: Uncategorized Issue Severity: Summary: Summary: Consider the following IDL: ---------------------------------------------------------------------- // IDL typedef long MyArray[1000000]; interface I { void set_array(in MyArray array); }; ---------------------------------------------------------------------- Now let"s assume that I want to implement this using the DSI: ---------------------------------------------------------------------- // C++ void I_impl::invoke(ServerRequest_ptr request) throw() { String_var name = request -> op_name(); if(strcmp(name, "set_array") == 0) { NVList_ptr list; orb -> create_list(0, list); Any* any = list -> add(ARG_IN) -> value(); XXX request -> params(list); MyArray_forany arg; *any >>= arg; ... // Do something with arg; return; } else { NVList_ptr list; orb -> create_list(0, list); request -> params(list); Any* any = new Any; *any <<= new BAD_OPERATION(); request -> exception(any); } } ---------------------------------------------------------------------- At the line I marked with XXX, I have to set the TypeCode of the Any. Resolution: Revised Text: Actions taken: April 20, 1999: received issue Discussion: deferred in June 2011 to the next RTF End of Annotations:===== Sender: ml@ooc.ooc.com Date: Tue, 20 Apr 1999 15:57:48 +0000 From: Marc Laukien Organization: Object-Oriented Concepts, Inc. X-Accept-Language: en To: cxx_revision@omg.org CC: issues@omg.org Subject: Setting the TypeCode of an Any without setting a value Hi, Consider the following IDL: ---------------------------------------------------------------------- // IDL typedef long MyArray[1000000]; interface I { void set_array(in MyArray array); }; ---------------------------------------------------------------------- Now let's assume that I want to implement this using the DSI: ---------------------------------------------------------------------- // C++ void I_impl::invoke(ServerRequest_ptr request) throw() { String_var name = request -> op_name(); if(strcmp(name, "set_array") == 0) { NVList_ptr list; orb -> create_list(0, list); Any* any = list -> add(ARG_IN) -> value(); XXX request -> params(list); MyArray_forany arg; *any >>= arg; ... // Do something with arg; return; } else { NVList_ptr list; orb -> create_list(0, list); request -> params(list); Any* any = new Any; *any <<= new BAD_OPERATION(); request -> exception(any); } } ---------------------------------------------------------------------- At the line I marked with XXX, I have to set the TypeCode of the Any. There are three possibilities to do this: 1) Using replace(): any -> replace(_tc_MyArray, 0); 2) Using a dummy value: MyArray dummy; *any <<= MyArray_forany(dummy); 3) Using DynAny. (1) cannot be used anymore, since replace() has been deprecated. (2) means a lot of overhead, since I have to allocate a large array, just to get the type into the any. And (3) is cumbersome. Using Java, it's easy: I can just use the type() modifier on the Any. However, this is not possible in C++, since the type() modifier in the C++ mapping can only be used for setting equivalent TypeCodes, but not for setting a type without a value. Ideally, I would like the type() modifier to have the same semantics in both the C++ and the Java mapping. Since the Java mapping had type() first, this would mean that the current type() in the C++ mapping would have to be renamed. If you think this is not acceptable, because this would break existing code (even though I doubt that there is a lot of code out there that's already using the type() modifier in C++), then we should at least add some other method for setting the type without setting a value. Cheers, Marc -- Marc Laukien Phone: (978) 439 9285 x 245 Object-Oriented Concepts, Inc. FAX: (978) 439 9286 44 Manning Rd. WWW: http://www.ooc.com Billerica, MA 01821 E-Mail: mailto:ml@ooc.com Date: Tue, 20 Apr 1999 10:21:41 -0700 (Pacific Daylight Time) From: Joachim Achtzehnter To: Marc Laukien cc: cxx_revision@omg.org Subject: Re: Setting the TypeCode of an Any without setting a value Sender: joachim@mercury.bc.ca On Tue, 20 Apr 1999, Marc Laukien wrote: > > Ideally, I would like the type() modifier to have the same semantics > in > both the C++ and the Java mapping. Since the Java mapping had type() > first, this would mean that the current type() in the C++ mapping > would have to be renamed. The fact that somebody comes first doesn't imply he was right. :-) > If you think this is not acceptable, because this would break existing > code (even though I doubt that there is a lot of code out there that's > already using the type() modifier in C++), then we should at least add > some other method for setting the type without setting a value. Before we talk about backward compatibility and presumed consistency with other language mappings we should first establish whether the change is desireable or not. > Setting the TypeCode of an Any without setting a value A CORBA any, as far as the logical model is concerned, must always have both a value and a TypeCode, and the two must be consistent. Taking your request literally, therefore, doesn't make sense IMHO. This doesn't necessarily mean that the mechanisms for setting any values/TypeCodes in the C++ mapping are the only way of doing it. But whatever we do, we must always set both value and TypeCode consistently. One can imagine a type() method that sets the TypeCode as specified and at the same time sets the value to an appropriate default. This is probably what really happens in the Java mapping, isn't it? But this may not be any more efficient than assigning this default value explicitly. Joachim -- joachim@kraut.bc.ca (http://www.kraut.bc.ca) joachim@mercury.bc.ca (http://www.mercury.bc.ca) Sender: jon@floorboard.com Date: Tue, 20 Apr 1999 10:22:23 -0700 From: Jonathan Biggar X-Accept-Language: en To: Marc Laukien CC: cxx_revision@omg.org Subject: Re: Setting the TypeCode of an Any without setting a value References: <371CA3FC.F18F9356@ooc.com> Marc Laukien wrote: > At the line I marked with XXX, I have to set the TypeCode of the > Any. There are three possibilities to do this: > > 1) Using replace(): > > any -> replace(_tc_MyArray, 0); > > 2) Using a dummy value: > > MyArray dummy; > *any <<= MyArray_forany(dummy); > > 3) Using DynAny. > > (1) cannot be used anymore, since replace() has been deprecated. (2) > means a lot of overhead, since I have to allocate a large array, > just > to get the type into the any. And (3) is cumbersome. > > Using Java, it's easy: I can just use the type() modifier on the > Any. However, this is not possible in C++, since the type() modifier > in the C++ mapping can only be used for setting equivalent > TypeCodes, > but not for setting a type without a value. > > Ideally, I would like the type() modifier to have the same semantics > in > both the C++ and the Java mapping. Since the Java mapping had type() > first, this would mean that the current type() in the C++ mapping > would have to be renamed. > > If you think this is not acceptable, because this would break > existing > code (even though I doubt that there is a lot of code out there > that's > already using the type() modifier in C++), then we should at least > add > some other method for setting the type without setting a value. I agree this is a problem. I see two ways to fix it: 1. Modify the definition of the type() modifier so that it can change to a non-equivalent typecode if no value has been set yet: CORBA::Any a; a.type(_tc_MyArray); // legal a <<= (CORBA::UShort)0; a.type(_tc_MyArray); // illegal 2. Add a new Any constructor, Any(CORBA::TypeCode_ptr): CORBA::Any a(_tc_MyArray); I could live with either (or both solutions). -- Jon Biggar Floorboard Software jon@floorboard.com jon@biggar.org Date: Tue, 20 Apr 1999 13:39:26 -0400 From: Marc Laukien Organization: Object-Oriented Concepts, Inc. X-Accept-Language: en To: Jonathan Biggar CC: cxx_revision@omg.org Subject: Re: Setting the TypeCode of an Any without setting a value References: <371CA3FC.F18F9356@ooc.com> <371CB7CF.90CC7D2A@floorboard.com> Hi Jon, > 1. Modify the definition of the type() modifier so that it can change > to a non-equivalent typecode if no value has been set yet: > > CORBA::Any a; > > a.type(_tc_MyArray); // legal > > a <<= (CORBA::UShort)0; > a.type(_tc_MyArray); // illegal This would work. However, if we want to have the same semantics for type() in both C++ and Java, then we would also need to change type() in the Java mapping. This could break existing Java code, since at present type() in the Java mapping wipes out any existing value. > 2. Add a new Any constructor, Any(CORBA::TypeCode_ptr): > > CORBA::Any a(_tc_MyArray); This would work as well. However, using this with NVList::add(Flags) would require a temporary any: Any* any = list -> add(ARG_IN) -> value(); *any = Any(_tc_MyArray); With add_value_consume(), I wouldn't need that temporary any, but then I have to provide a meaningless name all the time: Any* any = new Any(_tc_MyArray); any = list -> add_value_consume("whatever", any, ARG_IN); And of course we still wouldn't have alignment with the Java mapping. Cheers, Marc -- Marc Laukien Phone: (978) 439 9285 x 245 Object-Oriented Concepts, Inc. FAX: (978) 439 9286 44 Manning Rd. WWW: http://www.ooc.com Billerica, MA 01821 E-Mail: mailto:ml@ooc.com