About
The maxon::ObjectInterface interface is the base of all interfaces. It defines the most basic functionality of all interface based objects. A custom implementation can (re)implement the methods of this interface.
- Note
- Every component can also implement various basic functions, see Default Functions.
Methods
These functions of the maxon::ObjectInterface interface are marked with MAXON_METHOD. They can be implemented in any interface based on maxon::ObjectInterface and are added to the reference class.
General Functions:
Comparison and Identity:
- Note
- The hash values returned by maxon::ObjectInterface::GetHashCode() should be used for hash tables etc. They should not be used for security related tasks e.g. storing password hashes.
-
For interfaces of the type MAXON_REFERENCE_NORMAL the hash value is based on the pointer; the method is not called. Only for copy-on-write interfaces the method is called.
-
It is advised to call the
super
function within maxon::ObjectInterface::IsEqual()
etc. since a component may be reused in an unpredicted context.
Functions
These function are marked with MAXON_FUNCTION. They cannot be implemented in a component but can be used in an implementation and in the reference class.
Component classes and interfaces:
Utility:
Internal
This function can only be used inside an implementation:
Implementation
{
public:
{
_protonCnt = protonCnt; _neutronCnt = neutronCnt; _electronCnt = electronCnt;
}
{
protonCnt = _protonCnt; neutronCnt = _neutronCnt; electronCnt = _electronCnt;
}
{
_protonCnt = 1;
_electronCnt = 1;
_neutronCnt = 0;
}
{
return superCompare;
const AtomImpl*
const atom =
GetOrNull(other);
if (!atom)
+ _neutronCnt
+ _electronCnt;
+ atom->_neutronCnt
+ atom->_electronCnt;
if (sum < sumOther)
if (sum > sumOther)
}
{
return FormatString(
"Protons: @, Neutrons: @, Electrons: @", _protonCnt, _neutronCnt, _electronCnt);
}
{
_protonCnt = atom._protonCnt;
_neutronCnt = atom._neutronCnt;
_electronCnt = atom._electronCnt;
}
private:
};
In a copy-on-write interface also maxon::ObjectInterface::GetHashCode() can be implemented.
{
public:
{
if (!superEqual)
return false;
const ErrorCodeImp*
const error =
GetOrNull(other);
if (!error)
return false;
if (_error != error->_error)
return false;
if (_timestamp != error->_timestamp)
return false;
return true;
}
{
}
{
_error = error._error;
_timestamp = error._timestamp;
}
private:
};
Usage
Basic methods of maxon::ObjectInterface are simply used with the reference object:
const AtomRef hydrogen = componentClass.Create()
iferr_return;
const AtomRef oxygen = componentClass.Create()
iferr_return;
if (hydrogen.IsEqual(oxygen) == false)
const maxon::UInt hashHydrogen = hydrogen.GetHashCode();
if (!hydrogen.IsInstanceOf<AtomInterface>())
References of a copy-on-write interface are used like this:
ErrorCode error = ErrorComponentClass.Create()
iferr_return;
ErrorCode copy = error;
hashA = error.GetHashCode();
hashB = copy.GetHashCode();
Further Reading