Table of Contents Previous Next
Logo
Server-Side Slice-to-C++ Mapping : 8.5 Parameter Passing
Copyright © 2003-2009 ZeroC, Inc.

8.5 Parameter Passing

For each parameter of a Slice operation, the C++ mapping generates a corresponding parameter for the virtual member function in the skeleton. In addition, every operation has an additional, trailing parameter of type Ice::Current. For example, the name operation of the Node interface has no parameters, but the name member function of the Node skeleton class has a single parameter of type Ice::Current. We explain the purpose of this parameter in Section 32.6 and will ignore it for now.
Parameter passing on the server side follows the rules for the client side:
• in-parameters are passed by value or const reference.
• out-parameters are passed by reference.
• return values are passed by value
To illustrate the rules, consider the following interface that passes string parameters in all possible directions:
module M {
    interface Example {
        string op(string sin, out string sout);
    };
};
The generated skeleton class for this interface looks as follows:
namespace M {
    class Example : virtual public ::Ice::Object {
    public:
        virtual std::string
                    op(const std::string&, std::string&,
                       const Ice::Current& = Ice::Current()) = 0;
        // ...
    };
}
As you can see, there are no surprises here. For example, we could implement op as follows:
std::string
ExampleI::op(const std::string& sin,
                   std::string& sout,
             const Ice::Current&)
{
    cout << sin << endl;        // In parameters are initialized
    sout = "Hello World!";      // Assign out parameter
    return "Done";              // Return a string
}
This code is in no way different from what you would normally write if you were to pass strings to and from a function; the fact that remote procedure calls are involved does not impact on your code in any way. The same is true for parameters of other types, such as proxies, classes, or dictionaries: the parameter passing conventions follow normal C++ rules and do not require special-purpose API calls or memory management.1

1
This is in sharp contrast to the CORBA C++ mapping, which has very complex parameter passing rules that make it all too easy to leak memory or cause undefined behavior.

Table of Contents Previous Next
Logo