[206] | 1 | #pragma once
|
---|
| 2 |
|
---|
| 3 | #include <string>
|
---|
| 4 | #include <vector>
|
---|
| 5 |
|
---|
| 6 | #include <boost/foreach.hpp>
|
---|
| 7 |
|
---|
| 8 | #include <jenga/include/common/Exception.h>
|
---|
[215] | 9 | #include <BoostSerializationSupport.h>
|
---|
[206] | 10 | #include <jenga/include/smoothie/BasicFixed.h>
|
---|
| 11 |
|
---|
| 12 | #include <option.h>
|
---|
| 13 | #include <Program.h>
|
---|
| 14 |
|
---|
| 15 | #include <windows.h>
|
---|
| 16 |
|
---|
| 17 | class CClass;
|
---|
| 18 |
|
---|
[290] | 19 | class GenericType;
|
---|
| 20 | typedef std::vector<GenericType> GenericTypes;
|
---|
| 21 |
|
---|
[206] | 22 | class Type{
|
---|
| 23 | int basicType;
|
---|
| 24 | union{
|
---|
| 25 | LONG_PTR index;
|
---|
| 26 | const CClass *pClass;
|
---|
| 27 | };
|
---|
[290] | 28 | GenericTypes actualGenericTypes;
|
---|
[206] | 29 |
|
---|
| 30 | // XMLシリアライズ用
|
---|
| 31 | private:
|
---|
| 32 | friend class boost::serialization::access;
|
---|
| 33 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 34 | {
|
---|
| 35 | trace_for_serialize( "serializing - Type" );
|
---|
| 36 |
|
---|
| 37 | ar & BOOST_SERIALIZATION_NVP( basicType );
|
---|
| 38 | if( HasMember() )
|
---|
| 39 | {
|
---|
| 40 | ar & boost::serialization::make_nvp("pClass", const_cast<CClass *&>(pClass));
|
---|
[293] | 41 | ar & BOOST_SERIALIZATION_NVP( actualGenericTypes );
|
---|
[206] | 42 | }
|
---|
| 43 | else
|
---|
| 44 | {
|
---|
| 45 | ar & BOOST_SERIALIZATION_NVP( index );
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public:
|
---|
| 50 | static int GetBasicSize( int basicType );
|
---|
| 51 |
|
---|
| 52 | Type():
|
---|
| 53 | basicType( DEF_NON ),
|
---|
| 54 | index( -1 ){}
|
---|
| 55 | Type( int basicType ):
|
---|
| 56 | basicType( basicType ),
|
---|
| 57 | index( -1 ){}
|
---|
| 58 |
|
---|
[290] | 59 | Type( int basicType, LONG_PTR index )
|
---|
| 60 | : basicType( basicType )
|
---|
| 61 | , index( index )
|
---|
| 62 | {
|
---|
| 63 | }
|
---|
[206] | 64 |
|
---|
| 65 | Type( int basicType, const CClass &objClass ):
|
---|
| 66 | basicType( basicType ),
|
---|
| 67 | index( (LONG_PTR)&objClass ){}
|
---|
| 68 |
|
---|
[290] | 69 | Type( const Type &type )
|
---|
| 70 | : basicType( type.basicType )
|
---|
| 71 | , index( type.index )
|
---|
| 72 | , actualGenericTypes( type.actualGenericTypes )
|
---|
| 73 | {
|
---|
| 74 | }
|
---|
[206] | 75 |
|
---|
[290] | 76 | ~Type();
|
---|
| 77 |
|
---|
| 78 | void operator= ( const Type &type )
|
---|
| 79 | {
|
---|
| 80 | basicType = type.basicType;
|
---|
| 81 | index = type.index;
|
---|
| 82 | actualGenericTypes = type.actualGenericTypes;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[206] | 85 | __inline int GetBasicType() const
|
---|
| 86 | {
|
---|
| 87 | return basicType;
|
---|
| 88 | }
|
---|
| 89 | LONG_PTR GetIndex() const
|
---|
| 90 | {
|
---|
| 91 | return index;
|
---|
| 92 | }
|
---|
[290] | 93 | const CClass &GetClass() const;
|
---|
[206] | 94 |
|
---|
| 95 | void SetBasicType( int basicType ){
|
---|
| 96 | this->basicType = basicType;
|
---|
| 97 | }
|
---|
| 98 | void SetIndex( LONG_PTR index ){
|
---|
| 99 | this->index = index;
|
---|
| 100 | }
|
---|
| 101 | void SetClassPtr( const CClass *pClass )
|
---|
| 102 | {
|
---|
[290] | 103 | int naturalBasicType = NATURAL_TYPE( basicType );
|
---|
| 104 | if( !HasMember() )
|
---|
| 105 | {
|
---|
| 106 | Jenga::Throw( "クラスまたは構造体でない型に対してSetClassPtrを呼び出した" );
|
---|
| 107 | }
|
---|
[206] | 108 | this->pClass = pClass;
|
---|
| 109 | }
|
---|
| 110 | void SetNull(){
|
---|
| 111 | SetBasicType( DEF_NON );
|
---|
| 112 | SetIndex( -1 );
|
---|
| 113 | }
|
---|
| 114 | void SetType( int basicType, LONG_PTR index ){
|
---|
| 115 | SetBasicType( basicType );
|
---|
| 116 | SetIndex( index );
|
---|
| 117 | }
|
---|
| 118 | void SetType( int basicType, const CClass *pClass ){
|
---|
| 119 | SetBasicType( basicType );
|
---|
| 120 | this->pClass = pClass;
|
---|
| 121 | }
|
---|
[290] | 122 | void SetActualGenericTypes( const GenericTypes &genericTypes )
|
---|
| 123 | {
|
---|
| 124 | this->actualGenericTypes = genericTypes;
|
---|
| 125 | }
|
---|
[206] | 126 |
|
---|
| 127 | int PtrLevel() const
|
---|
| 128 | {
|
---|
| 129 | return PTR_LEVEL( basicType );
|
---|
| 130 | }
|
---|
| 131 | void PtrLevelUp(){
|
---|
| 132 | PTR_LEVEL_UP( basicType );
|
---|
| 133 | }
|
---|
| 134 | void PtrLevelDown(){
|
---|
| 135 | PTR_LEVEL_DOWN( basicType );
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | bool Equals( const Type &type ) const;
|
---|
| 139 |
|
---|
| 140 | int GetBasicSize() const;
|
---|
| 141 | int GetSize() const;
|
---|
| 142 |
|
---|
| 143 | bool IsNull() const;
|
---|
| 144 |
|
---|
| 145 | bool IsByte() const;
|
---|
| 146 | bool IsSByte() const;
|
---|
| 147 | bool IsWord() const;
|
---|
| 148 | bool IsInteger() const;
|
---|
| 149 | bool IsDWord() const;
|
---|
| 150 | bool IsLong() const;
|
---|
| 151 | bool IsQWord() const;
|
---|
| 152 | bool IsInt64() const;
|
---|
| 153 | bool IsSingle() const;
|
---|
| 154 | bool IsDouble() const;
|
---|
| 155 | bool IsBoolean() const;
|
---|
| 156 |
|
---|
| 157 | static bool IsPointer( int basicType );
|
---|
| 158 | bool IsPointer() const;
|
---|
| 159 | bool IsSigned() const;
|
---|
| 160 | bool IsNaturalWhole() const;
|
---|
| 161 | bool IsWhole() const;
|
---|
| 162 | bool IsReal() const;
|
---|
| 163 | bool Is64() const;
|
---|
| 164 | bool IsProcPtr() const;
|
---|
| 165 | bool IsStruct() const;
|
---|
| 166 | bool IsStructPtr() const;
|
---|
| 167 | bool IsObject() const;
|
---|
| 168 | bool IsObjectPtr() const;
|
---|
[290] | 169 | bool IsTypeParameter() const;
|
---|
[206] | 170 | bool IsObjectClass() const;
|
---|
| 171 | bool IsStringClass() const;
|
---|
| 172 | bool IsVoidPtr() const;
|
---|
| 173 | bool IsAny() const;
|
---|
| 174 |
|
---|
| 175 | // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
|
---|
| 176 | bool HasMember() const;
|
---|
| 177 |
|
---|
[290] | 178 | // 未完成
|
---|
| 179 | const Type &GetDummyActualGenericType() const;
|
---|
| 180 | bool HasActualGenericType() const;
|
---|
[206] | 181 |
|
---|
| 182 |
|
---|
| 183 | private:
|
---|
| 184 | static const int basicTypeList[];
|
---|
| 185 | static const std::string basicTypeNameList[];
|
---|
| 186 | public:
|
---|
| 187 | static bool StringToBasicType( const std::string &typeName, int &basicType );
|
---|
| 188 | static const char *Type::BasicTypeToCharPtr( const Type &type );
|
---|
| 189 | static int GetBasicTypeFromSimpleName( const char *variable );
|
---|
| 190 | };
|
---|
| 191 |
|
---|
[290] | 192 | class GenericType
|
---|
| 193 | {
|
---|
| 194 | std::string name;
|
---|
| 195 | Type type;
|
---|
[293] | 196 |
|
---|
| 197 | // XMLシリアライズ用
|
---|
| 198 | private:
|
---|
| 199 | friend class boost::serialization::access;
|
---|
| 200 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 201 | {
|
---|
| 202 | trace_for_serialize( "serializing - GenericType" );
|
---|
| 203 |
|
---|
| 204 | ar & BOOST_SERIALIZATION_NVP( name );
|
---|
| 205 | ar & BOOST_SERIALIZATION_NVP( type );
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[290] | 208 | public:
|
---|
| 209 | GenericType( const std::string &name, const Type &type )
|
---|
| 210 | : name( name )
|
---|
| 211 | , type( type )
|
---|
| 212 | {
|
---|
| 213 | }
|
---|
| 214 | GenericType()
|
---|
| 215 | {
|
---|
| 216 | }
|
---|
| 217 | ~GenericType()
|
---|
| 218 | {
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | const std::string &GetName() const
|
---|
| 222 | {
|
---|
| 223 | return name;
|
---|
| 224 | }
|
---|
| 225 | const Type &GetType() const
|
---|
| 226 | {
|
---|
| 227 | return type;
|
---|
| 228 | }
|
---|
| 229 | };
|
---|
| 230 |
|
---|
[206] | 231 | class BlittableType
|
---|
| 232 | {
|
---|
| 233 | Type basicType;
|
---|
| 234 | CClass *pClass;
|
---|
| 235 |
|
---|
| 236 | // XMLシリアライズ用
|
---|
| 237 | private:
|
---|
| 238 | friend class boost::serialization::access;
|
---|
| 239 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 240 | {
|
---|
| 241 | trace_for_serialize( "serializing - BlittableType" );
|
---|
| 242 |
|
---|
| 243 | ar & BOOST_SERIALIZATION_NVP( basicType );
|
---|
| 244 | ar & BOOST_SERIALIZATION_NVP( pClass );
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | public:
|
---|
[271] | 248 | bool isTargetObjectModule;
|
---|
[206] | 249 | BlittableType( const Type &basicType, CClass *pClass )
|
---|
| 250 | : basicType( basicType )
|
---|
| 251 | , pClass( pClass )
|
---|
[271] | 252 | , isTargetObjectModule( true )
|
---|
[206] | 253 | {
|
---|
| 254 | }
|
---|
| 255 | BlittableType()
|
---|
[271] | 256 | : isTargetObjectModule( true )
|
---|
[206] | 257 | {
|
---|
| 258 | }
|
---|
| 259 | const Type &GetBasicType() const
|
---|
| 260 | {
|
---|
| 261 | return basicType;
|
---|
| 262 | }
|
---|
| 263 | const CClass *GetClassPtr() const
|
---|
| 264 | {
|
---|
| 265 | return pClass;
|
---|
| 266 | }
|
---|
| 267 | const std::string GetCreateStaticMethodFullName() const;
|
---|
| 268 | };
|
---|
| 269 | class BlittableTypes : public std::vector<BlittableType>
|
---|
| 270 | {
|
---|
| 271 | // XMLシリアライズ用
|
---|
| 272 | private:
|
---|
| 273 | friend class boost::serialization::access;
|
---|
| 274 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 275 | {
|
---|
| 276 | trace_for_serialize( "serializing - BlittableTypes" );
|
---|
| 277 |
|
---|
| 278 | ar & boost::serialization::make_nvp("vector_BlittableType",
|
---|
| 279 | boost::serialization::base_object<std::vector<BlittableType>>(*this));
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | public:
|
---|
| 283 | bool IsExist( Type type ) const
|
---|
| 284 | {
|
---|
| 285 | const BlittableTypes &blittableTypes = *this;
|
---|
| 286 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
| 287 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
| 288 | return true;
|
---|
| 289 | }
|
---|
| 290 | }
|
---|
| 291 | return false;
|
---|
| 292 | }
|
---|
| 293 | const BlittableType &Find( const Type &type ) const
|
---|
| 294 | {
|
---|
| 295 | const BlittableTypes &blittableTypes = *this;
|
---|
| 296 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
| 297 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
| 298 | return blittableType;
|
---|
| 299 | }
|
---|
| 300 | }
|
---|
| 301 | Jenga::Throw( "Blittable型ではない" );
|
---|
| 302 |
|
---|
| 303 | static BlittableType dummy;
|
---|
| 304 | return dummy;
|
---|
| 305 | }
|
---|
| 306 | const CClass *GetClassPtr( const Type &type ) const
|
---|
| 307 | {
|
---|
| 308 | const BlittableTypes &blittableTypes = *this;
|
---|
| 309 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
| 310 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
| 311 | return blittableType.GetClassPtr();
|
---|
| 312 | }
|
---|
| 313 | }
|
---|
| 314 | return NULL;
|
---|
| 315 | }
|
---|
| 316 | const CClass &GetClass( const Type &type ) const
|
---|
| 317 | {
|
---|
| 318 | return *GetClassPtr( type );
|
---|
| 319 | }
|
---|
| 320 | };
|
---|