InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
K2TypeTraits.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Mat Marcus
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __K2TypeTraits__
25 #define __K2TypeTraits__
26 
27 #include "MetaProgramming.h"
28 
29 #define BOOST_HAS_THREADS
30 
31 #include <boost/shared_ptr.hpp>
32 
33 // ===================================================================================
34 // PODTraits
35 // POD stands for Plain Old Data
36 // ===================================================================================
37 
38 struct base_type { typedef base_type data_type;};
39 struct object_type{ typedef object_type data_type;};
40 
41 
42 template <class T>
43 class PODTraits {
44 public:
45  typedef typename K2Meta::IF<K2Meta::IS_PTR<T>::RET /*|| K2Meta::IS_ENUM<T>::RET*/, base_type, T>::RET::data_type data_type;
46 };
47 
48 
49 #define DECLARE_BASE_TYPE(type) \
50 template <> \
51 class PODTraits<type > { \
52 public: \
53  typedef base_type data_type; \
54 } \
55 
56 #define DECLARE_OBJECT_TYPE(type) \
57 template <> \
58 class PODTraits<type > { \
59 public: \
60  typedef object_type data_type; \
61 }
62 
63 
64 // ===================================================================================
65 // Specializations for common base types
66 // ===================================================================================
67 DECLARE_BASE_TYPE(bool);
68 DECLARE_BASE_TYPE(char);
69 DECLARE_BASE_TYPE(short);
70 DECLARE_BASE_TYPE(int);
71 DECLARE_BASE_TYPE(long);
72 DECLARE_BASE_TYPE(unsigned char);
73 DECLARE_BASE_TYPE(unsigned short);
74 DECLARE_BASE_TYPE(unsigned int);
75 DECLARE_BASE_TYPE(unsigned long);
76 #if defined WINDOWS
77 DECLARE_BASE_TYPE(__int64);
78 DECLARE_BASE_TYPE(unsigned __int64);
79 #else
80 DECLARE_BASE_TYPE(long long);
81 DECLARE_BASE_TYPE(unsigned long long);
82 #endif
83 DECLARE_BASE_TYPE(float);
84 DECLARE_BASE_TYPE(double);
85 DECLARE_BASE_TYPE(long double);
86 
87 DECLARE_BASE_TYPE(const void*);
88 
89 template <typename T> \
91 public: \
92  typedef object_type data_type; \
93 }; \
94 
95 namespace K2Meta {
96 
97 // ----- IS_POD -----
98  template <class T>
99  struct IsPOD {
100  enum {RET = false};
101  };
102 
103  template <>
104  struct IsPOD<base_type> {
105  enum {RET = true};
106  };
107 
108  template <class T>
109  struct IS_POD {
110  enum {RET = IsPOD<typename PODTraits<T>::data_type>::RET};
111  };
112 
113 // ----- IS_POD_PTR -----
114 
115 #if HAS_PARTIAL_SPECIALIZATION
116  template <typename T>
117  struct IS_POD_PTR {
118  enum { RET = false};
119  };
120 
121  template <typename T>
122  struct IS_POD_PTR<const T*> {
123  enum { RET = K2Meta::IS_POD<T>::RET };
124  };
125  template <typename T>
126  struct IS_POD_PTR<T*> {
127  enum { RET = K2Meta::IS_POD<T>::RET };
128  };
129 
130 
131 #else
132  template class IF<1, int, char>; // for VC6.4
133 
134  template <class Q>
135  typename IF<IS_POD<Q>::RET, int, char>::RET IsPODPtr(const Q*);
136 
137  char IsPODPtr(...);
138 
139  template <class Q>
140  struct IS_POD_PTR {
141  static Q q;
142  public:
143  enum { RET = sizeof(IsPODPtr(q)) == sizeof(int) };
144  };
145 #endif
146 } // namespace K2Meta
147 
148 
149  template <typename T>
151  static T CONVERT(T arg) {return arg;}
152  };
153 
154 #endif //__K2TypeTraits__