null references.
More...
#include <xmog_null.h>
Public Member Functions | |
| bool | operator! () const |
| Logical NOT operator. | |
| bool | operator!= (const xmog_base &_rhs) const |
| Comparison for inequality operator. | |
| bool | operator!= (const xmog_null &_rhs) const |
Comparison for inequality with null operator. | |
| bool | operator== (const xmog_base &_rhs) const |
| Comparison for equality operator. | |
| bool | operator== (const xmog_null &_rhs) const |
Comparison for equality with null operator. | |
| xmog_null () | |
| The default constructor. | |
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).
|
|
The default constructor.
It is only used to construct the |
|
|
Logical NOT operator.
This method always returns
|
|
|
Comparison for inequality operator.
This method is only used when you compare
|
|
|
Comparison for inequality with
This method is only used when you compare two
|
|
|
Comparison for equality operator.
This method is only used when you compare
|
|
|
Comparison for equality with
This method is only used when you compare two
|
1.4.1