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

Last change on this file since 197 was 197, 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 void operator= ( const Type &type ){
130 basicType = type.basicType;
131 index = type.index;
132 }
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 const char *Type::BasicTypeToCharPtr( const Type &type );
141 static int GetBasicTypeFromSimpleName( const char *variable );
142};
143
144class BlittableType
145{
146 Type basicType;
147 CClass *pClass;
148public:
149 BlittableType( const Type &basicType, CClass *pClass )
150 : basicType( basicType )
151 , pClass( pClass )
152 {
153 }
154 BlittableType(){}
155 const Type &GetBasicType() const
156 {
157 return basicType;
158 }
159 const CClass *GetClassPtr() const
160 {
161 return pClass;
162 }
163 const std::string GetCreateStaticMethodFullName() const;
164};
165class BlittableTypes : public std::vector<BlittableType>
166{
167public:
168 bool IsExist( Type type ) const
169 {
170 const BlittableTypes &blittableTypes = *this;
171 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
172 if( blittableType.GetBasicType().Equals( type ) ){
173 return true;
174 }
175 }
176 return false;
177 }
178 const BlittableType &Find( const Type &type ) const
179 {
180 const BlittableTypes &blittableTypes = *this;
181 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
182 if( blittableType.GetBasicType().Equals( type ) ){
183 return blittableType;
184 }
185 }
186 throw "Blittable型ではない";
187 }
188 const CClass *GetClassPtr( const Type &type ) const
189 {
190 const BlittableTypes &blittableTypes = *this;
191 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
192 if( blittableType.GetBasicType().Equals( type ) ){
193 return blittableType.GetClassPtr();
194 }
195 }
196 return NULL;
197 }
198 const CClass &GetClass( const Type &type ) const
199 {
200 return *GetClassPtr( type );
201 }
202};
Note: See TracBrowser for help on using the repository browser.