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

Last change on this file since 170 was 170, checked in by dai_9181, 17 years ago

ベースを作成中...

File size: 4.1 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 bool IsPointer() const;
106 bool IsSigned() const;
107 bool IsNaturalWhole() const;
108 bool IsWhole() const;
109 bool IsReal() const;
110 bool Is64() const;
111 bool IsProcPtr() const;
112 bool IsStruct() const;
113 bool IsStructPtr() const;
114 bool IsObject() const;
115 bool IsObjectPtr() const;
116 bool IsObjectClass() const;
117 bool IsStringClass() const;
118 bool IsVoidPtr() const;
119 bool IsAny() const;
120
121 // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
122 bool HasMember() const;
123
124 const std::string ToString() const;
125
126 void operator= ( const Type &type ){
127 basicType = type.basicType;
128 index = type.index;
129 }
130
131 static Type String();
132
133
134private:
135 static const int basicTypeList[];
136 static const std::string basicTypeNameList[];
137public:
138 static bool StringToBasicType( const std::string &typeName, int &basicType );
139 static bool StringToType( const std::string &typeName, Type &type );
140};
141
142class BlittableType
143{
144 Type basicType;
145 CClass *pClass;
146public:
147 BlittableType( const Type &basicType, CClass *pClass )
148 : basicType( basicType )
149 , pClass( pClass )
150 {
151 }
152 BlittableType(){}
153 const Type &GetBasicType() const
154 {
155 return basicType;
156 }
157 const CClass *GetClassPtr() const
158 {
159 return pClass;
160 }
161 const std::string GetCreateStaticMethodFullName() const;
162};
163class BlittableTypes : public std::vector<BlittableType>
164{
165public:
166 bool IsExist( Type type ) const
167 {
168 const BlittableTypes &blittableTypes = *this;
169 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
170 if( blittableType.GetBasicType().Equals( type ) ){
171 return true;
172 }
173 }
174 return false;
175 }
176 const BlittableType &Find( const Type &type ) const
177 {
178 const BlittableTypes &blittableTypes = *this;
179 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
180 if( blittableType.GetBasicType().Equals( type ) ){
181 return blittableType;
182 }
183 }
184 throw "Blittable型ではない";
185 }
186 const CClass *GetClassPtr( const Type &type ) const
187 {
188 const BlittableTypes &blittableTypes = *this;
189 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
190 if( blittableType.GetBasicType().Equals( type ) ){
191 return blittableType.GetClassPtr();
192 }
193 }
194 return NULL;
195 }
196 const CClass &GetClass( const Type &type ) const
197 {
198 return *GetClassPtr( type );
199 }
200};
Note: See TracBrowser for help on using the repository browser.