#ifndef __JLANG__JMULTIEQUALS__
#define __JLANG__JMULTIEQUALS__
#include "JLang/JNullType.hh"
#include "JLang/JTypeList.hh"
#include "JLang/JType.hh"
/**
* \author mdejong
*/
namespace JLANG {}
namespace JPP { using namespace JLANG; }
namespace JLANG {
/**
* Template definition of auxiliary base class for data structures
* composed of multiple base classes with equality evaluations capabilities.
*
* The data type JType_t should have the corresponding operator:
*
* bool operator==(const JType_t& first, const JType_t& second);
*
* This class uses in-class friend operators (see Barton-Nackman trick).
*
* This class implements the operators == != .
*/
template
struct JMultiEquals {
/**
* Equal operator.
*
* \param first first object
* \param second second object
* \return true if two objects are equal; else false
*/
friend bool operator==(const JClass_t& first,
const JClass_t& second)
{
return static_cast(first) == static_cast(second);
}
/**
* Not equal operator.
*
* \param first first object
* \param second second object
* \return true if two objects are not equal; else false
*/
friend bool operator!=(const JClass_t& first,
const JClass_t& second)
{
return static_cast(first) != static_cast(second);
}
};
/**
* Template specialisation of auxiliary base class for data structures
* composed of multiple base classes with equality evaluations capabilities.
*
* Each data type T in the type list should have the corresponding operator:
*
* bool operator==(const T& first, const T& second);
*
* This class uses in-class friend operators (see Barton-Nackman trick).
*
* This class implements the operators == != .
*/
template
struct JMultiEquals > {
protected:
typedef JTypeList JTypelist_t;
/**
* Equals method for composite data types.
*
* \param first first object
* \param second second object
* \param type type
* \return true if two objects are equal; else false
*/
template
static inline bool eq(const JClass_t& first,
const JClass_t& second,
const JType >& type)
{
return (static_cast(first) ==
static_cast(second) &&
eq(first, second, JType()));
}
/**
* Equals method for composite data types.
*
* \param first first object
* \param second second object
* \param type type
* \return true if two objects are equal; else false
*/
template
static inline bool eq(const JClass_t& first,
const JClass_t& second,
const JType >& type)
{
return (static_cast(first) ==
static_cast(second));
}
public:
/**
* Equal operator.
*
* \param first first object
* \param second second object
* \return true if two objects are equal; else false
*/
friend bool operator==(const JClass_t& first,
const JClass_t& second)
{
return eq(first, second, JType());
}
/**
* Not equal operator.
*
* \param first first object
* \param second second object
* \return true if two objects are not equal; else false
*/
friend bool operator!=(const JClass_t& first,
const JClass_t& second)
{
return !eq(first, second, JType());
}
};
}
#endif