Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

xmog_null Class Reference

A type representing null references. More...

#include <xmog_null.h>

List of all members.

Public Member Functions

 xmog_null ()
 The default constructor.
bool operator== (const xmog_null &_rhs) const
 Comparison for equality with null operator.
bool operator== (const xmog_base &_rhs) const
 Comparison for equality operator.
bool operator!= (const xmog_null &_rhs) const
 Comparison for inequality with null operator.
bool operator!= (const xmog_base &_rhs) const
 Comparison for inequality operator.
bool operator! () const
 Logical NOT operator.


Detailed Description

A type representing null references.

This type's only purpose is to act as a unique type representing a null reference. In Java, you have the reserved word null, which represents a reference to nothing. C++ has a similar concept via the NULL macro. NULL is typically a preprocessor definition that looks something like this:

      #define NULL   (void*)0

NULL is only useful when you're dealing with C++ pointers, not when you're dealing with objects or object references.

To allow the proxy classes to be used in the same way as the underlying Java types, we provide what amounts to a global variable called null and each generated proxy type provides constructors or operators that can deal with this null instance.

To illustrate how this works, we'll look at a code snippet and then analyze in detail what that snippet looks like to the C++ compiler. The first snippet is code that you might write in your C++ application.

      javax::naming::InitialContext    ictx;
      java::lang::Object               ctx = ictx.lookup( "myapp/bos/payment" );
   
      if( ctx != null )
      {
         //do what you're supposed to do with the looked up object
      }

For the compiler, the test for null is implemented by calling the comparison with xmog_null operator:

      bool    java::lang::Object::operator != ( const xmog_null & _rhs ) const;

But where does the argument value null come from? null is a static variable that is defined in every compilation unit that includes the xmog_null.h header file. Think of it as a global singleton (while this is technically incorrect because there are many instances, it gives you the right idea).


Constructor & Destructor Documentation

xmog_null::xmog_null  ) 
 

The default constructor.

It is only used to construct the null instance.


Member Function Documentation

bool xmog_null::operator!  )  const
 

Logical NOT operator.

This method always returns true.

Returns:
true.

bool xmog_null::operator!= const xmog_base _rhs  )  const
 

Comparison for inequality operator.

This method is only used when you compare null with a proxy instance. It returns false if the proxy instance dose not refer to a Java object.

Returns:
false if the proxy instance dose not refer to a Java object, true otherwise.

bool xmog_null::operator!= const xmog_null _rhs  )  const
 

Comparison for inequality with null operator.

This method is only used when you compare two null instances. It always returns false.

Returns:
false.

bool xmog_null::operator== const xmog_base _rhs  )  const
 

Comparison for equality operator.

This method is only used when you compare null with a proxy instance. It returns true if the proxy instance dose not refer to a Java object.

Returns:
true if the proxy instance dose not refer to a Java object, false otherwise.

bool xmog_null::operator== const xmog_null _rhs  )  const
 

Comparison for equality with null operator.

This method is only used when you compare two null instances. It always returns true.

Returns:
true.


The documentation for this class was generated from the following file:
Generated on Wed May 31 14:01:34 2006 for Shared Codemesh Runtime Library API Reference by  doxygen 1.4.1