Archived

This forum has been archived. Please start a new discussion on GitHub.

array mapping question

Hi All,

I wonder if it is possible to map a sequence as a pointer to byte in Ice-3.3.

I've read this thread: [HTML]http://www.zeroc.com/forums/help-center/522-slice-array-type-mapping-c.html[/HTML]

According to this thread (which is quite old), arrays are always mapped to vectors. However, in the manual
it states that
[HTML]http://www.zeroc.com/doc/Ice-3.3.1/manual/Cpp.7.7.html[/HTML]
"interface File {
void write(["cpp:array"] Ice::ByteSeq contents);
};
The cpp:array metadata directive instructs the compiler to map the contents parameter to a pair of pointers:
virtual void write(const ::std :: pair < const ::Ice::Byte*,
const ::Ice::Byte*>&,
const ::Ice::Current& = ::Ice::Current()) = 0;
The passed pointers denote the beginning and end of the sequence as a range [first, last) (that is, they use the usual STL semantics for iterators)."

I am little confused. Let say that I have a function, void A(byte *B). Is it possible to define this function in slice as this:

interface AA {
void A(["cpp:array"] Ice::ByteSeq B)
}

--->

class AAI: public AA {
public:
virtual void A(Byte* B);
};

Or should I use vectors?

Thanks,

Haris

Comments

  • bernard
    bernard Jupiter, FL
    Hi Haris,

    Welcome to our forums!

    When you use the "cpp:array" metadata, the parameter is mapped to a pair of pointers: the first pointer points to the beginning of the array, while the second pointer points to one element past the end.

    With your example, slice2cpp generates the following AA abstract base class (on the server side):
    class AA ... {
       virtual void A(const std::pair<const Ice::Byte*, const Ice::Byte*>&,
                         const Ice::Current& = Ice::Current()) = 0;
    

    And just as importantly, on the client-side, the generated code for the corresponding proxy function takes a const std::pair<const Ice::Byte*, const Ice::Byte*>& parameter.

    Your function:
    void A(byte *B)
    

    does not map well to any byte-sequence because it's not clear where the end (or one element past the end) is with just a single pointer.

    Best regards,
    Bernard
  • Thank you very much Bernard.

    haris