~ubuntu-branches/ubuntu/oneiric/nux/oneiric

« back to all changes in this revision

Viewing changes to NuxCore/ObjectType.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-08-25 13:42:45 UTC
  • mfrom: (1.1.27 upstream)
  • Revision ID: james.westby@ubuntu.com-20110825134245-edi1g8cm2iqibae7
Tags: 1.4.0-0ubuntu1
* New upstream version:
  - "scrolling down in a lens brings it back to the top automatically" 
    (lp: #821534)
* debian/rules: updated shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
1
2
/*
2
3
 * Copyright 2010 Inalogic® Inc.
3
4
 *
19
20
 *
20
21
 */
21
22
 
22
 
 
23
23
#ifndef NOBJECTTYPE_H
24
24
#define NOBJECTTYPE_H
25
25
 
 
26
#include <string>
 
27
 
 
28
namespace nux
 
29
{
 
30
// TODO: write a nice is_instance (and is_derived_instance)
 
31
 
 
32
//template <typename T, typename I>
 
33
//bool is_instance(T const&
 
34
 
26
35
struct NObjectType
27
36
{
28
 
  const TCHAR *m_Name;
29
 
  NObjectType *m_Super;
 
37
  const char* name;
 
38
  NObjectType* super;
 
39
 
30
40
  static const NObjectType  Null_Type;
31
41
 
32
42
  NObjectType()
33
 
    :   m_Name (TEXT ("Null_Type") )
34
 
    ,   m_Super (0)
 
43
    : name("Null_Type")
 
44
    , super(nullptr)
35
45
  {
36
46
  }
37
47
 
38
 
  NObjectType (const TCHAR *Name, NObjectType *Super)
39
 
    :   m_Name (Name)
40
 
    ,   m_Super (Super)
 
48
  NObjectType(const char* type_name, NObjectType* super_type)
 
49
    : name(type_name)
 
50
    , super(super_type)
41
51
  {
42
52
  }
43
53
 
53
63
    return !IsObjectType (Type);
54
64
  }
55
65
 
56
 
  //! Return the name of the type.
57
 
  inline const TCHAR              *GetName() const
58
 
  {
59
 
    return m_Name;
60
 
  }
61
 
 
62
66
  //! Return true is this has the same type as the argument type.
63
67
  inline bool IsObjectType (const NObjectType &Type) const
64
68
  {
65
 
    if (this == &Type)
66
 
    {
67
 
      return true;
68
 
    }
69
 
 
70
 
    return false;
 
69
    return this == &Type;
71
70
  }
72
71
 
73
72
  //! Return true if this has the same type as the argument type or is derived from it.
80
79
      if (current_type == &Type)
81
80
        return true;
82
81
 
83
 
      current_type = current_type->m_Super;
 
82
      current_type = current_type->super;
84
83
    }
85
84
 
86
85
    return false;
88
87
 
89
88
  inline unsigned int SubClassDepth() const
90
89
  {
91
 
    const NObjectType *current_type = this;
 
90
    const NObjectType* current_type = this;
92
91
    unsigned int depth = 0;
93
92
 
94
93
    while (current_type)
95
94
    {
96
95
      depth++;
97
 
      current_type = current_type->m_Super;
 
96
      current_type = current_type->super;
98
97
    }
99
98
 
100
99
    return depth;
104
103
#define NUX_DECLARE_OBJECT_TYPE(TypeName, SuperType)                            \
105
104
    public:                                                                 \
106
105
    typedef SuperType SuperObject;                                          \
107
 
    static NObjectType StaticObjectType;                                    \
 
106
    static ::nux::NObjectType StaticObjectType;                         \
108
107
    public:                                                                 \
109
 
    virtual NObjectType& Type() const { return StaticObjectType; }          \
110
 
    NObjectType& GetTypeInfo() const { return StaticObjectType; }
 
108
    virtual ::nux::NObjectType& Type() const { return StaticObjectType; }          \
 
109
    ::nux::NObjectType& GetTypeInfo() const { return StaticObjectType; }
111
110
 
112
111
 
113
112
#define NUX_IMPLEMENT_OBJECT_TYPE(TypeName)                                     \
114
 
    NObjectType TypeName::StaticObjectType(TEXT(#TypeName), &TypeName::SuperObject::StaticObjectType);
115
 
 
116
 
// #define NUX_DECLARE_ROOT_OBJECT_TYPE(TypeName)      NUX_DECLARE_OBJECT_TYPE(TypeName, TypeName)
117
 
// #define NUX_IMPLEMENT_ROOT_OBJECT_TYPE(TypeName)    NUX_IMPLEMENT_OBJECT_TYPE(TypeName)
 
113
    ::nux::NObjectType TypeName::StaticObjectType(#TypeName, &TypeName::SuperObject::StaticObjectType);
118
114
 
119
115
#define NUX_DECLARE_ROOT_OBJECT_TYPE(TypeName)                                  \
120
116
    public:                                                                 \
121
 
    typedef NObjectType SuperObject;                                        \
122
 
    static NObjectType StaticObjectType;                                    \
 
117
    typedef ::nux::NObjectType SuperObject;                                        \
 
118
    static ::nux::NObjectType StaticObjectType;                                    \
123
119
    public:                                                                 \
124
 
    virtual NObjectType& Type() const { return StaticObjectType; }          \
125
 
    NObjectType& GetTypeInfo() const { return StaticObjectType; }
 
120
    virtual ::nux::NObjectType& Type() const { return StaticObjectType; }          \
 
121
    ::nux::NObjectType& GetTypeInfo() const { return StaticObjectType; }
126
122
 
127
123
#define NUX_IMPLEMENT_ROOT_OBJECT_TYPE(TypeName)                                \
128
 
    NObjectType TypeName::StaticObjectType(TEXT(#TypeName), 0);
 
124
    ::nux::NObjectType TypeName::StaticObjectType(#TypeName, 0);
 
125
 
 
126
} // namespace nux
129
127
 
130
128
#endif // NOBJECTTYPE_H
131
129