source: dev/trunk/jenga/include/smoothie/Type.h@ 192

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