Table of Contents Previous Next
Logo
The Slice Language : 4.14 Operations on Object
Copyright © 2003-2009 ZeroC, Inc.

4.14 Operations on Object

The Object interface has a number of operations. We cannot define type Object in Slice because Object is a keyword; regardless, here is what (part of) the definition of Object would look like if it were legal:
sequence<string> StrSeq;

interface Object {                      // "Pseudo" Slice!
    idempotent void   ice_ping();
    idempotent bool   ice_isA(string typeID);
    idempotent string ice_id();
    idempotent StrSeq ice_ids();
    // ...
};
Note that, apart from the illegal use of the keyword Object as the interface name, the operation names all contain an underscore. This is deliberate: by putting an underscore into these operation names, it becomes impossible for these built‑in operations to ever clash with a user-defined operation. This means that all Slice interfaces can inherit from Object without name clashes. There are three built‑in operations that are commonly used:
• ice_ping
All interfaces support the ice_ping operation. That operation is useful for debugging because it provides a basic reachability test for an object: if the object exists and a message can successfully be dispatched to the object, ice_ping simply returns without error. If the object cannot be reached or does not exist, ice_ping throws a run-time exception that provides the reason for the failure.
• ice_isA
The ice_isA operation accepts a type identifier (such as the identifier returned by ice_id) and tests whether the target object supports the specified type, returning true if it does. You can use this operation to check whether a target object supports a particular type. For example, referring to Figure 4.7 once more, assume that you are holding a proxy to a target object of type AlarmClock. Table 4.2 illustrates the result of calling ice_isA on that proxy with various arguments. (We assume that all type in Figure 4.7 are defined in a module Times):
Table 4.2. Calling ice_isA on a proxy denoting an object of type AlarmClock.
As expected, ice_isA returns true for ::Times::Clock and ::Times::AlarmClock and also returns true for ::Ice::Object (because all interfaces support that type). Obviously, an AlarmClock supports neither the Radio nor the RadioClock interfaces, so ice_isA returns false for these types.
• ice_id
The ice_id operation returns the type ID (see Section 4.13) of the most-derived type of an interface.
• ice_ids
The ice_ids operation returns a sequence of type IDs that contains all of the type IDs supported by an interface. For example, for the RadioClock interface in Figure 4.7, ice_ids returns a sequence containing the type IDs ::Ice::Object, ::Times::Clock, ::Times::AlarmClock, ::Times::Radio, and ::Times::RadioClock.
Table of Contents Previous Next
Logo