1 | #pragma once
|
---|
2 |
|
---|
3 | #include <string>
|
---|
4 | #include <vector>
|
---|
5 |
|
---|
6 | #include <boost/foreach.hpp>
|
---|
7 |
|
---|
8 | #include <jenga/include/common/BoostXmlSupport.h>
|
---|
9 |
|
---|
10 | #include <windows.h>
|
---|
11 | #include "BasicFixed.h"
|
---|
12 |
|
---|
13 | class CClass;
|
---|
14 |
|
---|
15 | class Type{
|
---|
16 | int basicType;
|
---|
17 | union{
|
---|
18 | LONG_PTR index;
|
---|
19 | const CClass *pClass;
|
---|
20 | };
|
---|
21 |
|
---|
22 | // XMLシリアライズ用
|
---|
23 | private:
|
---|
24 | friend class boost::serialization::access;
|
---|
25 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
26 | {
|
---|
27 | ar & BOOST_SERIALIZATION_NVP( basicType );
|
---|
28 | if( HasMember() )
|
---|
29 | {
|
---|
30 | ar & boost::serialization::make_nvp("pClass", const_cast<CClass *&>(pClass));
|
---|
31 | }
|
---|
32 | else
|
---|
33 | {
|
---|
34 | ar & BOOST_SERIALIZATION_NVP( index );
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public:
|
---|
39 | static int GetBasicSize( int basicType );
|
---|
40 |
|
---|
41 | Type():
|
---|
42 | basicType( DEF_NON ),
|
---|
43 | index( -1 ){}
|
---|
44 | Type( int basicType ):
|
---|
45 | basicType( basicType ),
|
---|
46 | index( -1 ){}
|
---|
47 |
|
---|
48 | Type( int basicType, LONG_PTR index ):
|
---|
49 | basicType( basicType ),
|
---|
50 | index( index ){}
|
---|
51 |
|
---|
52 | Type( int basicType, const CClass &objClass ):
|
---|
53 | basicType( basicType ),
|
---|
54 | index( (LONG_PTR)&objClass ){}
|
---|
55 |
|
---|
56 | Type( const Type &type ):
|
---|
57 | basicType( type.basicType ),
|
---|
58 | index( type.index ){}
|
---|
59 |
|
---|
60 | __inline int GetBasicType() const
|
---|
61 | {
|
---|
62 | return basicType;
|
---|
63 | }
|
---|
64 | LONG_PTR GetIndex() const
|
---|
65 | {
|
---|
66 | return index;
|
---|
67 | }
|
---|
68 | const CClass &GetClass() const
|
---|
69 | {
|
---|
70 | return *pClass;
|
---|
71 | }
|
---|
72 |
|
---|
73 | void SetBasicType( int basicType ){
|
---|
74 | this->basicType = basicType;
|
---|
75 | }
|
---|
76 | void SetIndex( LONG_PTR index ){
|
---|
77 | this->index = index;
|
---|
78 | }
|
---|
79 | void SetClassPtr( const CClass *pClass )
|
---|
80 | {
|
---|
81 | this->pClass = pClass;
|
---|
82 | }
|
---|
83 | void SetNull(){
|
---|
84 | SetBasicType( DEF_NON );
|
---|
85 | SetIndex( -1 );
|
---|
86 | }
|
---|
87 | void SetType( int basicType, LONG_PTR index ){
|
---|
88 | SetBasicType( basicType );
|
---|
89 | SetIndex( index );
|
---|
90 | }
|
---|
91 | void SetType( int basicType, const CClass *pClass ){
|
---|
92 | SetBasicType( basicType );
|
---|
93 | this->pClass = pClass;
|
---|
94 | }
|
---|
95 |
|
---|
96 | int PtrLevel() const
|
---|
97 | {
|
---|
98 | return PTR_LEVEL( basicType );
|
---|
99 | }
|
---|
100 | void PtrLevelUp(){
|
---|
101 | PTR_LEVEL_UP( basicType );
|
---|
102 | }
|
---|
103 | void PtrLevelDown(){
|
---|
104 | PTR_LEVEL_DOWN( basicType );
|
---|
105 | }
|
---|
106 |
|
---|
107 | bool Equals( const Type &type ) const;
|
---|
108 |
|
---|
109 | int GetBasicSize() const;
|
---|
110 | int GetSize() const;
|
---|
111 |
|
---|
112 | bool IsNull() const;
|
---|
113 |
|
---|
114 | bool IsByte() const;
|
---|
115 | bool IsSByte() const;
|
---|
116 | bool IsWord() const;
|
---|
117 | bool IsInteger() const;
|
---|
118 | bool IsDWord() const;
|
---|
119 | bool IsLong() const;
|
---|
120 | bool IsQWord() const;
|
---|
121 | bool IsInt64() const;
|
---|
122 | bool IsSingle() const;
|
---|
123 | bool IsDouble() const;
|
---|
124 | bool IsBoolean() const;
|
---|
125 |
|
---|
126 | static bool IsPointer( int basicType );
|
---|
127 | bool IsPointer() const;
|
---|
128 | bool IsSigned() const;
|
---|
129 | bool IsNaturalWhole() const;
|
---|
130 | bool IsWhole() const;
|
---|
131 | bool IsReal() const;
|
---|
132 | bool Is64() const;
|
---|
133 | bool IsProcPtr() const;
|
---|
134 | bool IsStruct() const;
|
---|
135 | bool IsStructPtr() const;
|
---|
136 | bool IsObject() const;
|
---|
137 | bool IsObjectPtr() const;
|
---|
138 | bool IsObjectClass() const;
|
---|
139 | bool IsStringClass() const;
|
---|
140 | bool IsVoidPtr() const;
|
---|
141 | bool IsAny() const;
|
---|
142 |
|
---|
143 | // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
|
---|
144 | bool HasMember() const;
|
---|
145 |
|
---|
146 | void operator= ( const Type &type ){
|
---|
147 | basicType = type.basicType;
|
---|
148 | index = type.index;
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 | private:
|
---|
153 | static const int basicTypeList[];
|
---|
154 | static const std::string basicTypeNameList[];
|
---|
155 | public:
|
---|
156 | static bool StringToBasicType( const std::string &typeName, int &basicType );
|
---|
157 | static const char *Type::BasicTypeToCharPtr( const Type &type );
|
---|
158 | static int GetBasicTypeFromSimpleName( const char *variable );
|
---|
159 | };
|
---|
160 |
|
---|
161 | class BlittableType
|
---|
162 | {
|
---|
163 | Type basicType;
|
---|
164 | CClass *pClass;
|
---|
165 | public:
|
---|
166 | BlittableType( const Type &basicType, CClass *pClass )
|
---|
167 | : basicType( basicType )
|
---|
168 | , pClass( pClass )
|
---|
169 | {
|
---|
170 | }
|
---|
171 | BlittableType(){}
|
---|
172 | const Type &GetBasicType() const
|
---|
173 | {
|
---|
174 | return basicType;
|
---|
175 | }
|
---|
176 | const CClass *GetClassPtr() const
|
---|
177 | {
|
---|
178 | return pClass;
|
---|
179 | }
|
---|
180 | const std::string GetCreateStaticMethodFullName() const;
|
---|
181 | };
|
---|
182 | class BlittableTypes : public std::vector<BlittableType>
|
---|
183 | {
|
---|
184 | public:
|
---|
185 | bool IsExist( Type type ) const
|
---|
186 | {
|
---|
187 | const BlittableTypes &blittableTypes = *this;
|
---|
188 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
189 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
190 | return true;
|
---|
191 | }
|
---|
192 | }
|
---|
193 | return false;
|
---|
194 | }
|
---|
195 | const BlittableType &Find( const Type &type ) const
|
---|
196 | {
|
---|
197 | const BlittableTypes &blittableTypes = *this;
|
---|
198 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
199 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
200 | return blittableType;
|
---|
201 | }
|
---|
202 | }
|
---|
203 | throw "Blittable型ではない";
|
---|
204 | }
|
---|
205 | const CClass *GetClassPtr( const Type &type ) const
|
---|
206 | {
|
---|
207 | const BlittableTypes &blittableTypes = *this;
|
---|
208 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
209 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
210 | return blittableType.GetClassPtr();
|
---|
211 | }
|
---|
212 | }
|
---|
213 | return NULL;
|
---|
214 | }
|
---|
215 | const CClass &GetClass( const Type &type ) const
|
---|
216 | {
|
---|
217 | return *GetClassPtr( type );
|
---|
218 | }
|
---|
219 | };
|
---|