#ifndef __JLANG__JCLASS__ #define __JLANG__JCLASS__ /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Data structure for primitive types. */ template struct JPrimitive { typedef const T argument_type; enum { is_primitive = true }; }; /** * Data structure for method argument types. */ template struct JArgument { typedef const T& argument_type; enum { is_primitive = false }; }; /** * Specialisations of JArgument for primitive types. */ template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; template<> struct JArgument : public JPrimitive {}; /** * Data structure to check whether given data type is an iterator. */ template struct is_iterator { static T make(); typedef void* buffer[2]; static buffer& test(...); //!< any type template static typename R::iterator_category* test(R); //!< iterator template static void* test(R *); //!< pointer static const bool value = sizeof(test(make())) == sizeof(void *); }; /** * Template for generic class types. */ template struct JClass { typedef typename JArgument::argument_type argument_type; typedef T value_type; typedef value_type& reference_type; typedef value_type* pointer_type; enum { is_primitive = JArgument::is_primitive }; enum { is_reference = false }; enum { is_pointer = false }; enum { is_constant = false }; }; /** * Specialisation of JClass for const class types. */ template struct JClass { typedef typename JArgument::argument_type argument_type; typedef T value_type; typedef const value_type& reference_type; typedef const value_type* pointer_type; enum { is_primitive = JArgument::is_primitive }; enum { is_reference = false }; enum { is_pointer = false }; enum { is_constant = true }; }; /** * Specialisation of JClass for reference class types. */ template struct JClass { typedef T& argument_type; typedef T value_type; typedef value_type& reference_type; typedef value_type* pointer_type; enum { is_primitive = JArgument::is_primitive }; enum { is_reference = true }; enum { is_pointer = false }; enum { is_constant = false }; }; /** * Specialisation of JClass for const reference class types. */ template struct JClass { typedef const T& argument_type; typedef T value_type; typedef const value_type& reference_type; typedef const value_type* pointer_type; enum { is_primitive = JArgument::is_primitive }; enum { is_reference = true }; enum { is_pointer = false }; enum { is_constant = true }; }; /** * Specialisation of JClass for pointer class types. */ template struct JClass { typedef T* argument_type; typedef T value_type; typedef value_type*& reference_type; typedef value_type* pointer_type; enum { is_primitive = JArgument::is_primitive }; enum { is_reference = false }; enum { is_pointer = true }; enum { is_constant = false }; }; /** * Specialisation of JClass for const pointer class types. */ template struct JClass { typedef const T* argument_type; typedef T value_type; typedef const value_type*& reference_type; typedef const value_type* pointer_type; enum { is_primitive = JArgument::is_primitive }; enum { is_reference = false }; enum { is_pointer = true }; enum { is_constant = true }; }; /** * Specialisation of JClass for pointer class types. */ template struct JClass { typedef T*& argument_type; typedef T value_type; typedef value_type*& reference_type; typedef value_type* pointer_type; enum { is_primitive = JArgument::is_primitive }; enum { is_reference = true }; enum { is_pointer = true }; enum { is_constant = false }; }; /** * Specialisation of JClass for const pointer class types. */ template struct JClass { typedef const T*& argument_type; typedef T value_type; typedef const value_type*& reference_type; typedef const value_type* pointer_type; enum { is_primitive = JArgument::is_primitive }; enum { is_reference = true }; enum { is_pointer = true }; enum { is_constant = true }; }; } #endif