public void CppAddType(DefType t, IndentStringBuilder sb) { if (t.HasAttribute<CustomCppClassDefinitionAttribute>()) { string txt = t.GetAttribute<CustomCppClassDefinitionAttribute>().Text; sb.AppendLine(txt); return; } if (t is DefClass) { if (!t.HasAttribute<WrapTypeAttribute>()) { //Ignore } else { switch (t.GetAttribute<WrapTypeAttribute>().WrapType) { case WrapTypes.NonOverridable: new CppNonOverridableClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.Overridable: new CppOverridableClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.Interface: new CppOverridableClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.NativeDirector: new CppNativeDirectorClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.NativePtrValueType: new CppNativePtrValueClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.Singleton: new CppSingletonClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.CLRHandle: new CppCLRHandleClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.PlainWrapper: new CppPlainWrapperClassProducer(this, t as DefClass, sb).Add(); break; } } } else if (t is DefTypeDef) { DefTypeDef explicitType; if (t.IsUnnamedSTLContainer) explicitType = t as DefTypeDef; else explicitType = (t.IsNested) ? t.ParentClass.FindType<DefTypeDef>(t.Name) : t.NameSpace.FindType<DefTypeDef>(t.Name); if (explicitType.IsSTLContainer) { CppAddSTLContainer(explicitType, sb); } else if (explicitType is DefIterator) { CppAddIterator(explicitType as DefIterator, sb); } } }
public void IncAddType(DefType t, IndentStringBuilder sb) { if (t.HasAttribute<CustomIncClassDefinitionAttribute>()) { string txt = t.GetAttribute<CustomIncClassDefinitionAttribute>().Text; sb.AppendLine(txt); return; } if (t is DefClass) { if (!t.HasAttribute<WrapTypeAttribute>()) { //Ignore } else { switch (t.GetAttribute<WrapTypeAttribute>().WrapType) { case WrapTypes.NonOverridable: new IncNonOverridableClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.Overridable: new IncOverridableClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.NativeDirector: new IncNativeDirectorClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.Interface: new IncInterfaceClassProducer(this, t as DefClass, sb).Add(); new IncOverridableClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.Singleton: new IncSingletonClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.ReadOnlyStruct: new IncReadOnlyStructClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.ValueType: new IncValueClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.NativePtrValueType: new IncNativePtrValueClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.CLRHandle: new IncCLRHandleClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.PlainWrapper: new IncPlainWrapperClassProducer(this, t as DefClass, sb).Add(); break; case WrapTypes.SharedPtr: IncAddSharedPtrType(t, sb); break; } } } else if (t is DefEnum) { IncAddEnum(t as DefEnum, sb); } else if (t is DefTypeDef) { DefTypeDef explicitType; if (t.IsUnnamedSTLContainer) explicitType = t as DefTypeDef; else explicitType = (t.IsNested) ? t.ParentClass.FindType<DefTypeDef>(t.Name) : t.NameSpace.FindType<DefTypeDef>(t.Name); if (t.HasWrapType(WrapTypes.SharedPtr)) { IncAddSharedPtrType(t, sb); } else if (explicitType.IsSTLContainer) { IncAddSTLContainer(explicitType, sb); } else if (explicitType is DefIterator) { IncAddIterator(explicitType as DefIterator, sb); } else if (explicitType.BaseType is DefInternal) { IncAddInternalTypeDef(explicitType, sb); } else if (explicitType.BaseType.HasAttribute<ValueTypeAttribute>()) { IncAddValueTypeTypeDef(explicitType, sb); } } }
public bool TypeIsWrappable(DefType type) { if (type.Name.StartsWith("DLL_")) { //It's DLL function pointers of OgrePlatformManager.h return false; } // Get explicit type or a new type if type has ReplaceBy attribute type = (type.IsNested) ? type.ParentClass.FindType<DefType>(type.Name) : type.NameSpace.FindType<DefType>(type.Name); if (type.HasAttribute<CustomIncClassDefinitionAttribute>()) return true; if (type.IsIgnored) return false; if (type.HasAttribute<WrapTypeAttribute>()) return true; if (type.IsSharedPtr) { type.Attributes.Add(new WrapTypeAttribute(WrapTypes.SharedPtr)); return true; } else if (type is DefClass) { DefClass cls = type as DefClass; if (cls.HasAttribute<CLRObjectAttribute>(true)) { if (cls.HasAttribute<OverridableAttribute>(true)) cls.Attributes.Add(new WrapTypeAttribute(WrapTypes.Overridable)); else cls.Attributes.Add(new WrapTypeAttribute(WrapTypes.NonOverridable)); return true; } if (cls.IsSingleton) { cls.Attributes.Add(new WrapTypeAttribute(WrapTypes.Singleton)); return true; } return false; } else if (type is DefTypeDef) { if (type.IsSTLContainer) { foreach (ITypeMember m in (type as DefTypeDef).TypeMembers) { DefType mt = m.Type; if (!mt.IsValueType && !mt.IsPureManagedClass && !TypeIsWrappable(mt)) return false; } return true; } else if (type is DefIterator) { if (TypeIsWrappable((type as DefIterator).TypeMembers[0].Type)) { if ((type as DefIterator).IsConstIterator) { try { DefType notconst = type.FindType<DefType>(type.Name.Substring("Const".Length), true); return false; } catch { return true; } } else return true; } else return false; } else if ((type as DefTypeDef).BaseType is DefInternal || (type as DefTypeDef).BaseType.HasAttribute<ValueTypeAttribute>()) return true; else return false; } else return false; }