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

Last change on this file since 172 was 172, checked in by dai_9181, 17 years ago
File size: 4.2 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 SetNull(){
63 SetBasicType( DEF_NON );
64 SetIndex( -1 );
65 }
66 void SetType( int basicType, LONG_PTR index ){
67 SetBasicType( basicType );
68 SetIndex( index );
69 }
70 void SetType( int basicType, const CClass *pClass ){
71 SetBasicType( basicType );
72 this->pClass = pClass;
73 }
74
75 int PtrLevel() const
76 {
77 return PTR_LEVEL( basicType );
78 }
79 void PtrLevelUp(){
80 PTR_LEVEL_UP( basicType );
81 }
82 void PtrLevelDown(){
83 PTR_LEVEL_DOWN( basicType );
84 }
85
86 bool Equals( const Type &type ) const;
87
88 int GetBasicSize() const;
89 int GetSize() const;
90
91 bool IsNull() const;
92
93 bool IsByte() const;
94 bool IsSByte() const;
95 bool IsWord() const;
96 bool IsInteger() const;
97 bool IsDWord() const;
98 bool IsLong() const;
99 bool IsQWord() const;
100 bool IsInt64() const;
101 bool IsSingle() const;
102 bool IsDouble() const;
103 bool IsBoolean() const;
104
105 static bool IsPointer( int basicType );
106 bool IsPointer() const;
107 bool IsSigned() const;
108 bool IsNaturalWhole() const;
109 bool IsWhole() const;
110 bool IsReal() const;
111 bool Is64() const;
112 bool IsProcPtr() const;
113 bool IsStruct() const;
114 bool IsStructPtr() const;
115 bool IsObject() const;
116 bool IsObjectPtr() const;
117 bool IsObjectClass() const;
118 bool IsStringClass() const;
119 bool IsVoidPtr() const;
120 bool IsAny() const;
121
122 // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
123 bool HasMember() const;
124
125 const std::string ToString() const;
126
127 void operator= ( const Type &type ){
128 basicType = type.basicType;
129 index = type.index;
130 }
131
132 static Type String();
133
134
135private:
136 static const int basicTypeList[];
137 static const std::string basicTypeNameList[];
138public:
139 static bool StringToBasicType( const std::string &typeName, int &basicType );
140 static bool StringToType( const std::string &typeName, Type &type );
141};
142
143class BlittableType
144{
145 Type basicType;
146 CClass *pClass;
147public:
148 BlittableType( const Type &basicType, CClass *pClass )
149 : basicType( basicType )
150 , pClass( pClass )
151 {
152 }
153 BlittableType(){}
154 const Type &GetBasicType() const
155 {
156 return basicType;
157 }
158 const CClass *GetClassPtr() const
159 {
160 return pClass;
161 }
162 const std::string GetCreateStaticMethodFullName() const;
163};
164class BlittableTypes : public std::vector<BlittableType>
165{
166public:
167 bool IsExist( Type type ) const
168 {
169 const BlittableTypes &blittableTypes = *this;
170 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
171 if( blittableType.GetBasicType().Equals( type ) ){
172 return true;
173 }
174 }
175 return false;
176 }
177 const BlittableType &Find( const Type &type ) const
178 {
179 const BlittableTypes &blittableTypes = *this;
180 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
181 if( blittableType.GetBasicType().Equals( type ) ){
182 return blittableType;
183 }
184 }
185 throw "Blittable型ではない";
186 }
187 const CClass *GetClassPtr( const Type &type ) const
188 {
189 const BlittableTypes &blittableTypes = *this;
190 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
191 if( blittableType.GetBasicType().Equals( type ) ){
192 return blittableType.GetClassPtr();
193 }
194 }
195 return NULL;
196 }
197 const CClass &GetClass( const Type &type ) const
198 {
199 return *GetClassPtr( type );
200 }
201};
Note: See TracBrowser for help on using the repository browser.