On this page:
amiThis directive applies to interfaces, classes, and individual operations. It enable code generation for asynchronous method invocation.
|
This directive applies to the deprecated AMI mapping. For the new AMI mapping there is no need for this directive. |
amdThis directive applies to interfaces, classes, and individual operations. It enables code generation for asynchronous method dispatch. (See the relevant language mapping chapter for details.)
deprecatedThis directive allows you to emit a deprecation warning for Slice constructs .
protectedThis directive applies to data members of classes and changes code generation to make these members protected. See class mapping of the relevant language mapping chapter for more information.
UserExceptionThis directive applies only to operations on local interfaces. The metadata directive indicates that the operation can throw any user exception, regardless of its specific definition. (This directive is used for the locate and finished operations on servant locators, which can throw any user exception.)
cpp:array and cpp:range:arrayThese directives apply to sequences. They direct the code generator to create zerocopy APIs for passing sequences as parameters.
cpp:classThis directive applies to structures. It directs the code generator to create a C++ class (instead of a C++ structure) to represent a Slice structure.
cpp:constThis directive applies to operations. It directs the code generator to create a const pure virtual member function for the skeleton class.
cpp:type:wstringThis directive applies to data members of type string as well as to containers, such as structures, classes, and exceptions. It changes the default mapping for strings from std::string to std::wstring.
cpp:header-extThis global directive allows you to use a file extension for C++ header files other than the default .h extension.
cpp:includeThis global directive allows you inject additional #include directives into the generated code. This is useful for custom types.
cpp:virtualThis directive applies to classes. If the directive is present and a class has base classes, the generated C++ class derives virtually from its bases; without this directive, slice2cpp generates the class so it derives non-virtually from its bases.
This directive is useful if you use Slice classes as servants and want to inherit the implementation of operations in the base class in the derived class. For example:
{zcode:slice}
class Base {
int baseOp();
};
["cpp:virtual"]
class Derived extends Base {
string derivedOp();
};
{zcode} |
The metadata directive causes slice2cpp to generate the class definition for Derived using virtual inheritance:
{zcode:cpp}
class Base : virtual public Ice::Object {
// ...
};
class Derived : virtual public Base {
// ...
};
{zcode} |
This allows you to reuse the implementation of baseOp in the servant for Derived using ladder inheritance:
{zcode:cpp}
class BaseI : public virtual Base {
Ice::Int baseOp(const Ice::Current&);
// ...
};
class DerivedI : public virtual Derived, public virtual BaseI {
// Re-use inherited baseOp()
};
{zcode} |
Note that, if you have data member in classes and use virtual inheritance, you need to take care to correctly call base class constructors if you implement your own one-shot constructor. For example:
{zcode:slice}
class Base {
int baseInt;
};
class Derived extends Base {
int derivedInt;
};
{zcode} |
The generated one-shot constructor for Derived initializes both baseInt and derivedInt:
{zcode:cpp}
Derived::Derived(Ice::Int __ice_baseInt, Ice::Int __ice_derivedInt)
: M::Base(__ice_baseInt),
derivedInt(__ice_derivedInt)
{
}
{zcode} |
If you derive your own class from Derived and add a one-shot constructor to your class, you must explicitly call the constructor of all the base classes, including Base. Failure to call the Base constructor will result in Base being default-constructed instead of getting a defined value. For example:
{zcode:cpp}
class DerivedI : public virtual Derived {
public:
DerivedI(int baseInt, int derivedInt, const string& s)
: Base(baseInt), Derived(baseInt, derivedInt), _s(s)
{
}
private:
string _s;
};
{zcode} |
This code correctly initializes the baseInt member of the Base part of the class. Note that the following does not work as intended and leaves the Base part default-constructed (meaning that baseInt is not initialized):
{zcode:cpp}
class DerivedI : public virtual Derived {
public:
DerivedI(int baseInt, int derivedInt, const string& s)
: Derived(baseInt, derivedInt), _s(s)
{
// WRONG: Base::baseInt is not initialized.
}
private:
string _s;
};
{zcode} |
java:packageThis global directive instructs the code generator to place the generated classes into a specific package.
java:getsetThis directive applies to data members and structures, classes, and exceptions. It adds accessor and modifier methods (JavaBean methods) for data members.
java:serializableThis directive allows you to use Ice to transmit serializable Java classes as native objects, without having to define corresponding Slice definitions for these classes.
java:typeThis directive allows to use custom types for sequences and dictionaries.
Note that C# (and other Common Language Runtime languages) are also affected by metadata with a clr: prefix. (See #Metadata Directives for .NET and Mono.)
cs:attributeThis directive can be used both as a global directive and as directive for specific Slice constructs. It injects C# attribute definitions into the generated code. (See C-Sharp Specific Metadata Directives.)
clr:classThis directive applies to Slice structures. It directs the code generator to emit a C# class instead of a structure.
clr:collectionThis directive applies to sequences and dictionaries and maps them to types that are derived from CollectionBase and DictionaryBase, respectively.
clr:generic:List, clr:generic:LinkedList, clr:generic:Queue and clr:generic:StackThese directives apply to sequences and map them to the specified sequence type.
clr:generic:SortedDictionaryThis directive applies to dictionaries and maps them to SortedDictionary.
clr:genericThis directive applies to sequences and allows you map them to custom types.
clr:propertyThis directive applies to Slice structures and classes. It directs the code generator to create C# property definitions for data members.
clr:serializableThis directive allows you to use Ice to transmit serializable CLR classes as native objects, without having to define corresponding Slice definitions for these classes.
objc:prefixThis directive applies to modules and changes the default mapping for modules to use a specified prefix.
python:packageThis global directive instructs the code generator to place the generated code into a specified Python package.
python:seq:default, python:seq:list and python:seq:tupleThese directives allow you to change the mapping for Slice sequences.
freeze:read and freeze:writeThese directives inform a Freeze evictor whether an operation updates the state of an object, so the evictor knows whether it must save an object before evicting it.