Codemesh Runtime v3 C++ API Reference  3.9.205
Public Member Functions | List of all members
xmog_null Class Reference

A type representing null references. More...

#include <xmog_null.h>

Public Member Functions

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

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::xmog_null ( )

The default constructor.

It is only used to construct the null instance.

Member Function Documentation

◆ operator!()

bool xmog_null::operator! ( ) const

Logical NOT operator.

This method always returns true.

Returns
true.

◆ operator!=() [1/2]

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.

◆ operator!=() [2/2]

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.

◆ operator==() [1/2]

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.

◆ operator==() [2/2]

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:
xmog_null
A type representing null references.
Definition: xmog_null.h:53

Copyright (c) 1999-2020 by Codemesh, Inc., ALL RIGHTS RESERVED.