Oracle Coherence for C++ API
Release 3.7.1.0

E22845-01

Method Class Reference

#include <coherence/lang/Method.hpp>

Inherits AnnotatedElement.

Inherited by TypedMethod.

List of all members.


Detailed Description

Method represents a method within a managed class.

To be of general use these Methods must also be registered with the corresponding Class object during Class registration. Once registered the Method can be found at runtime as follows:

 Method::View vMethodName = SystemClassLoader::getInstance()
     ->loadByName("Person")->getMethod("getName");

And then finally applied:

 Object::View vo = getPersonFromSomewhere();
 std::cout << vMethodName->invoke(vo) << std::endl;

Author:
mf 2011.02.24
Since:
Coherence 3.7.1
See also:
TypedMethod for registration helpers and examples
 

Public Types

enum  Modifier { modifier_instance, modifier_static, modifier_mutable, modifier_const }
 Modifier defines the various reflectable Method modifiers. More...
typedef spec::Handle Handle
 Method Handle definition.
typedef spec::View View
 Method View definition.
typedef spec::Holder Holder
 Method Holder definition.
typedef TypedHandle
< const Class
ClassView
 Forward declaration of Class::View.

Public Member Functions

virtual String::View getName () const
 Return the method name.
virtual int32_t getModifiers () const =0
 Return the method modifiers.
virtual ObjectArray::View getParameterTypes () const =0
 Return an array of Class::Views representing the method parameter types.
virtual ClassView getReturnType () const =0
 Return the Class::View representing the method's return type, or NULL for void.
virtual ClassView getDeclaringClass () const =0
 Return the Class::View representing the class in which the method is declared.
virtual Object::Holder invoke (Object::Holder oh, ObjectArray::View vaArgs=NULL) const =0
 Execute the method.
virtual Method::Handle annotate (Annotation::View vAnnontation)
 Add the specified Annotation to the element.
virtual void toStream (std::ostream &out) const
 Output a human-readable description of this Object to the given stream.

coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toStream method, to output Objects. If a managed String object is desired, the COH_TO_STRING macro can be used to build up a String from streamable contents.

 Object::View vKey   = ...
 Object::View vValue = ...
 std::cout << vKey << " = " << vValue << std::endl;

 String::Handle hs = COH_TO_STRING(vKey << " = " << vValue);

Parameters:
 out the stream used to output the description
virtual bool equals (Object::View vThat) const
 Return true iff the specified Object is "equal" to this Object.

This method implements an equivalence relation on Objects:

  • It is reflexive: for any non-null handle h, h->equals(h) must return true.
  • It is symmetric: for any non-null handles h1 and h2, h1->equals(h2) should return true if and only if h2->equals(h1) returns true.
  • It is transitive: for any non-null handles h1, h2, and h3, if h1->equals(h2) returns true and h2->equals(h3) returns true, then h1->equals(h3) should return true.
  • It is consistent: for any non-null handles h1 and h2, multiple invocations of h1->equals(h2) consistently return true or consistently return false, provided no information used in comparisons on the objects is modified.
  • If the supplied handle is NULL then false must be returned.

The default implementation is a reference equality comparison.

Parameters:
 v the Object::View to compare against, may be NULL
Returns:
true iff the given handle references an Object that is "equal" to this Object
See also:
equals(Object::View v1, Object::View v2)
virtual size32_t hashCode () const
 Return a hash code value for the Object.

This method is supported for the benefit of hash-based containers.

The general contract of hashCode is:

  • Whenever it is invoked on the same Object more than once during an execution of an application, the hashCode method must consistently return the same value, provided no information used in equals comparisons on the object is modified. This value need not remain consistent from one execution of an application to another execution of the same application.
  • If two Objects are equal according to the equals method, then calling the hashCode method on each of the two Objects must produce the same value.
  • It is not required that if two Objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct results. However, the programmer should be aware that producing distinct results for unequal objects may improve the performance of hash-based containers.

The default implementation is identity based.

Returns:
a hash code value for this Object

Protected Member Functions

 Method (String::View vsName)
 Construct a Method of the specified name.

Protected Attributes

FinalView< Stringm_vsName
 The Method name.

Member Enumeration Documentation

enum Modifier

Modifier defines the various reflectable Method modifiers.

Enumerator:
modifier_instance  modifier_instance indicates that the method is an instance method.
modifier_static  modifier_static indicates that the method is static.
modifier_mutable  modifier_mutable indicates that the method is non-const.
modifier_const  modifier_const indicates that the method is const.


Member Function Documentation

virtual int32_t getModifiers (  )  const [pure virtual]

Return the method modifiers.

Returns:
the method modifiers

Implemented in TypedMethod.

virtual ObjectArray::View getParameterTypes (  )  const [pure virtual]

Return an array of Class::Views representing the method parameter types.

Returns:
the parameter types

Implemented in TypedMethod.

virtual ClassView getReturnType (  )  const [pure virtual]

Return the Class::View representing the method's return type, or NULL for void.

Returns:
the return type

Implemented in TypedMethod.

virtual ClassView getDeclaringClass (  )  const [pure virtual]

Return the Class::View representing the class in which the method is declared.

Returns:
the declaring class

Implemented in TypedMethod.

virtual Object::Holder invoke ( Object::Holder  oh,
    ObjectArray::View  vaArgs = NULL 
  )    const [pure virtual]

Execute the method.

Parameters:
 oh the object on which to invoke the method
 vaArgs the parameters, or NULL if the method takes none.
Returns:
the method return value, or NULL if the method has a void return

Implemented in TypedMethod.

virtual Method::Handle annotate ( Annotation::View  vAnnontation  )  [virtual]

Add the specified Annotation to the element.

Parameters:
 vAnnontation the annotation
Returns:
this object


The documentation for this class was generated from the following file:
Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.