/*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NTEMPLATE_H
#define NTEMPLATE_H
namespace nux
{
class NString;
// Number of elements in an array.
#define NUX_ARRAY_COUNT( array ) \
( sizeof(array) / sizeof((array)[0]) )
// -----------------------------------------------------------------------------
// Type information.
// -----------------------------------------------------------------------------
// Is void
template struct VoidTraits
{
enum { result = 0 };
};
// Full specialization of template NTraitIsVoid
template <> struct VoidTraits
{
enum { result = 1 };
};
// Is pointer
template struct PointerTraits
{
enum { result = 0 };
};
// Partial specialization
template struct PointerTraits
{
enum { result = 1 };
};
template struct UnicodeCharTraits
{
enum { result = 0 };
};
template <> struct UnicodeCharTraits
{
enum { result = 1 };
};
template struct AnsiCharTraits
{
enum { result = 0 };
};
template <> struct AnsiCharTraits
{
enum { result = 1 };
};
// Base type information for atomic types which pass by value.
template
class TypeTraitsNoConstructor
{
public:
typedef T ConstInitType;
enum { HasConstructor = 0 };
enum { HasDestructor = 0 };
};
// Base type information for constructed types which pass by reference.
template
class TypeTraitsConstructor
{
public:
typedef const T &ConstInitType;
enum { HasConstructor = 1 };
enum { HasDestructor = 1 };
};
// The default behaviour is for types to behave as constructed types.
template
class ConstructorTraits : public TypeTraitsConstructor {};
// Pointers don't have a constructor.
template
class ConstructorTraits: public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template <> class ConstructorTraits : public TypeTraitsNoConstructor {};
template
class NTypeTraits
{
private:
public:
enum { IsVoid = VoidTraits::result };
enum { IsPointer = PointerTraits::result };
enum { NeedsConstructor = ConstructorTraits::HasConstructor };
enum { NeedsDestructor = ConstructorTraits::HasDestructor };
enum { IsAnsiChar = AnsiCharTraits::result };
enum { IsUnicodeChar = UnicodeCharTraits::result };
};
template
struct RemovePointerFromType
{
typedef T type;
};
template
struct RemovePointerFromType
{
typedef T type;
};
template
struct RemovePointerFromType
{
typedef T type;
};
template
struct RemovePointerFromType
{
typedef T type;
};
template
struct RemovePointerFromType
{
typedef T type;
};
}
#endif // NTEMPLATE_H