|
Codemesh Runtime v3 C++ API Reference
3.9.205
|
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... | |
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:
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.
For the compiler, the test for null is implemented by calling the comparison with xmog_null operator:
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).
| xmog_null::xmog_null | ( | ) |
The default constructor.
It is only used to construct the null instance.
| bool xmog_null::operator! | ( | ) | const |
Logical NOT operator.
This method always returns true.
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.
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.
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.
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.
true.