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);
+ _neutronCnt
+ _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:
};
maxon::String ToString(const Filename &val, const maxon::FormatStatement *formatStatement, maxon::Bool checkDatatype=false)
Definition: objectbase.h:2651
Definition: objectbase.h:1371
Definition: string.h:1235
PyObject * other
Definition: dictobject.h:70
#define atom
Definition: graminit.h:72
#define argument
Definition: graminit.h:83
COMPARERESULT
Data type for comparison results.
Definition: compare.h:21
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
return OK
Definition: apibase.h:2690
@ LESS
result is less than
@ INCOMPARABLE
values are incomparable (either a compare function doesn't exist, or we have a partial order)
@ GREATER
result is greater than
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2212
#define FormatString(...)
Definition: string.h:2100
#define MAXON_METHOD
Definition: interfacebase.h:1001
Bool Compare(const T &x, const T &y, GETINT &&getInt)
Definition: sort_paradis.h:24
In a copy-on-write interface also maxon::ObjectInterface::GetHashCode() can be implemented.
{
public:
{
if (!superEqual)
return false;
const ErrorCodeImp*
const error = GetOrNull(
other);
return false;
if (_error !=
error->_error)
return false;
if (_timestamp !=
error->_timestamp)
return false;
return true;
}
{
}
{
_timestamp =
error._timestamp;
}
private:
};
UInt32 GetCrc() const
Definition: crc32c.h:66
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUInt(UInt u)
Definition: crc32c.h:503
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateInt(Int i)
Definition: crc32c.h:543
PyObject * error
Definition: codecs.h:206
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:181
UInt64 UInt
unsigned 32/64 bit int, size depends on the platform
Definition: apibase.h:189
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEqual(PREDICATE &&predicate, const T1 &a, const T2 &b)
Definition: collection.h:102
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();
Definition: object_interface.h:10
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define iferr_return
Definition: resultbase.h:1519
References of a copy-on-write interface are used like this:
hashA =
error.GetHashCode();
hashB = copy.GetHashCode();
Further Reading