#ifndef __JLANG__JENUMERATION__ #define __JLANG__JENUMERATION__ #include #include "JLang/JAssert.hh" #include "JLang/JType.hh" #include "JLang/JTypeID.hh" #include "JLang/JTypeList.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Test presence of data type identifier in labelled type list. */ template struct JHasID { static const bool value = (JTypeID::ID == ID); }; /** * Recursive test of presence data type identifier in labelled type list. */ template struct JHasID, ID> { static const bool value = (JHasID::value || JHasID::value); }; /** * Enumeration of single data type. */ template struct JEnumeration { /** * Get label of given data type. * * \param type data type * \return label */ static inline JLabel_t getLabel(const JType& type) { return JLabel_t(JTypeID::ID, JTypeID::getName(), JTypeID::getVersion()); } /** * Get label of given object. * * \param object object * \return label */ static inline JLabel_t getLabel(const T& object) { return getLabel(JType()); } /** * Print enumeration. * * \param out output stream * \return output stream */ static std::ostream& print(std::ostream& out) { out << getLabel(JType()) << std::endl; return out; } }; /** * Enumeration of multiple data types. * * The uniqueness of each data type and identifier in the type list is verified; * failure causes a compiler error. */ template struct JEnumeration< JTypeList > : public JEnumeration, public JEnumeration, public virtual JAssert ::value && !JHasID ::ID>::value> { using JEnumeration::getLabel; using JEnumeration::getLabel; /** * Print enumeration. * * \param out output stream * \return output stream */ static std::ostream& print(std::ostream& out) { JEnumeration::print(out); JEnumeration::print(out); return out; } }; /** * Terminator class of recursive JEnumeration class. */ template struct JEnumeration< JTypeList > : public JEnumeration {}; } #endif