public static void AddMethodHandlersClass(DefClass type, IndentStringBuilder sb)
        {
            if (!type.HasWrapType(WrapTypes.NativeDirector))
                throw new Exception("Unexpected");

            if (type.IsNested)
                sb.AppendIndent("public: ");
            else
                sb.AppendIndent("public ");

            sb.Append("ref class " + type.Name + " abstract sealed\n");
            sb.AppendLine("{");
            sb.AppendLine("public:");
            sb.IncreaseIndent();

            foreach (DefFunction f in type.PublicMethods)
            {
                if (f.IsDeclarableFunction && f.IsVirtual)
                {
                    sb.AppendIndent("delegate static " + f.CLRTypeName + " " + f.CLRName + "Handler(");
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        DefParam param = f.Parameters[i];
                        sb.Append(" " + param.Type.GetCLRParamTypeName(param) + " " + param.Name);
                        if (i < f.Parameters.Count - 1) sb.Append(",");
                    }
                    sb.Append(" );\n");
                }
            }

            sb.DecreaseIndent();
            sb.AppendLine("};");
            sb.AppendLine();
        }
Exemplo n.º 2
0
 public CppClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
     //if (AllowSubclassing)
     //{
     //    _wrapper.PreClassProducers.Add(new CppNativeProtectedTypesProxy(_wrapper, _t, _sb));
     //}
 }
Exemplo n.º 3
0
        public IncClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
            : base(wrapper, t, sb)
        {
            AddPreDeclarations();

            if (_t.BaseClass != null)
                AddTypeDependancy(_t.BaseClass);

            if (AllowSubclassing)
            {
                _wrapper.PreClassProducers.Add(new NativeProtectedTypesProxy(_wrapper, _t, _sb));
                _wrapper.PostClassProducers.Add(new NativeProtectedStaticsProxy(_wrapper, _t, _sb));
                //_wrapper.PreClassProducers.Add(new IncNativeProtectedTypesProxy(_wrapper, _t, _sb));
            }
        }
Exemplo n.º 4
0
        public ClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
        {
            this._wrapper = wrapper;
            this._t = t;
            this._sb = sb;

            foreach (DefClass iface in _t.GetInterfaces())
            {
                AddTypeDependancy(iface);
                _interfaces.Add(iface);
            }

            if (_t.IsInterface)
            {
                // Declaring an overridable class for interface
                _interfaces.Add(_t);
            }
        }
 public IncInterfaceClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
 }
 public IncNativePtrValueClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
 }
 public IncCLRHandleClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
 }
Exemplo n.º 8
0
 public void IncAddValueTypeTypeDef(DefTypeDef t, IndentStringBuilder sb)
 {
     sb.AppendIndent("");
     if (t.IsNested)
         sb.Append(Producer.GetProtectionString(t.ProtectionType) + ": ");
     sb.Append("typedef " + t.BaseType.FullCLRName + " " + t.CLRName + ";\n\n");
 }
Exemplo n.º 9
0
        public void IncAddSTLContainer(DefTypeDef t, IndentStringBuilder sb)
        {
            if (t is DefStdPair)
            {
                //sb.AppendIndent("");
                //if (t.IsNested)
                //    sb.Append(Producer.GetProtectionString(t.ProtectionType) + ": ");
                //sb.Append("typedef " + t.FullSTLContainerTypeName + " " + t.CLRName + ";\n\n");
                return;
            }

            if (!t.IsNested)
            {
                this.AddPreDeclaration("ref class " + t.CLRName + ";");
                this.AddPreDeclaration("ref class Const_" + t.CLRName + ";");
            }

            if (t is DefTemplateOneType)
            {
                if (t.HasAttribute<STLListNoRemoveAndUniqueAttribute>())
                {
                    sb.AppendLine("#undef INC_STLLIST_DEFINE_REMOVE_AND_UNIQUE");
                    sb.AppendLine("#define INC_STLLIST_DEFINE_REMOVE_AND_UNIQUE(M)");
                    sb.AppendLine();
                }

                sb.AppendLine("#define STLDECL_MANAGEDTYPE " + t.TypeMembers[0].CLRTypeName);
                sb.AppendLine("#define STLDECL_NATIVETYPE " + t.TypeMembers[0].NativeTypeName);
                CheckTypeForDependancy(t.TypeMembers[0].Type);
            }
            else if (t is DefTemplateTwoTypes)
            {
                sb.AppendLine("#define STLDECL_MANAGEDKEY " + t.TypeMembers[0].CLRTypeName);
                sb.AppendLine("#define STLDECL_MANAGEDVALUE " + t.TypeMembers[1].CLRTypeName);
                sb.AppendLine("#define STLDECL_NATIVEKEY " + t.TypeMembers[0].NativeTypeName);
                sb.AppendLine("#define STLDECL_NATIVEVALUE " + t.TypeMembers[1].NativeTypeName);
                CheckTypeForDependancy(t.TypeMembers[0].Type);
                CheckTypeForDependancy(t.TypeMembers[1].Type);
            }

            sb.AppendIndent("");
            string publicprot, privateprot;
            if (!t.IsNested)
            {
                publicprot = "public";
                privateprot = "private";
            }
            else
            {
                publicprot = Producer.GetProtectionString(t.ProtectionType) + ": ";
                privateprot = "private:";
                sb.Append(publicprot);
            }

            sb.Append("INC_DECLARE_STL" + t.STLContainer.ToUpper());

            if (t.IsReadOnly)
                sb.Append("_READONLY");

            sb.Append("( " + t.CLRName);

            if (t is DefTemplateOneType)
                sb.Append(", STLDECL_MANAGEDTYPE, STLDECL_NATIVETYPE, " + publicprot + ", " + privateprot + " )\n");
            else if (t is DefTemplateTwoTypes)
                sb.Append(", STLDECL_MANAGEDKEY, STLDECL_MANAGEDVALUE, STLDECL_NATIVEKEY, STLDECL_NATIVEVALUE, " + publicprot + ", " + privateprot + " )\n");
            else
                throw new Exception("Unexpected");

            if (t is DefTemplateOneType)
            {
                sb.AppendLine("#undef STLDECL_MANAGEDTYPE");
                sb.AppendLine("#undef STLDECL_NATIVETYPE");

                if (t.HasAttribute<STLListNoRemoveAndUniqueAttribute>())
                {
                    sb.AppendLine();
                    sb.AppendLine("#undef INC_STLLIST_DEFINE_REMOVE_AND_UNIQUE");
                    sb.AppendLine("#define INC_STLLIST_DEFINE_REMOVE_AND_UNIQUE(M)    INC_STLLIST_REMOVE_AND_UNIQUE_DEFINITIONS(M)");
                }
            }
            else if (t is DefTemplateTwoTypes)
            {
                sb.AppendLine("#undef STLDECL_MANAGEDKEY");
                sb.AppendLine("#undef STLDECL_MANAGEDVALUE");
                sb.AppendLine("#undef STLDECL_NATIVEKEY");
                sb.AppendLine("#undef STLDECL_NATIVEVALUE");
            }

            sb.AppendLine();
        }
Exemplo n.º 10
0
        //, bool inProtectedTypesProxy)
        //public void IncAddEnum(DefEnum enm, IndentStringBuilder sb)
        //{
        //    IncAddEnum(enm, sb, false);
        //}
        public void IncAddEnum(DefEnum enm, IndentStringBuilder sb)
        {
            if (enm.Name[0] == '@')
                return;

            if (enm.HasAttribute<FlagsEnumAttribute>())
            {
                sb.AppendLine("[Flags]");
            }

            sb.AppendIndent("");
            if (!enm.IsNested)
                sb.Append("public ");
            else
                sb.Append(Producer.GetProtectionString(enm.ProtectionType) + ": ");

            //if (inProtectedTypesProxy)
                //sb.Append("enum " + enm.Name + "\n");
            //else
                sb.Append("enum class " + enm.CLRName + "\n");

            sb.AppendLine("{");
            sb.IncreaseIndent();
            for (int i=0; i < enm.CLREnumValues.Length; i++)
            {
                string value = enm.NativeEnumValues[i];
                sb.AppendIndent("");
                //if (inProtectedTypesProxy)
                //{
                //    value = enm.ParentFullNativeName + "::" + enm.CLREnumValues[i];
                //    sb.Append("PUBLIC_");
                //}

                sb.Append(enm.CLREnumValues[i] + " = " + value);
                if (i < enm.CLREnumValues.Length - 1)
                    sb.Append(",");
                sb.Append("\n");
            }
            sb.DecreaseIndent();
            sb.AppendLine("};\n");
        }
        public static void AddNativeProxyMethodBody(DefFunction f, string managedTarget, IndentStringBuilder sb)
        {
            string managedCall;
            string fullPostConv = null;

            if (f.IsGetProperty)
            {
                sb.AppendLine(f.CLRTypeName + " mp_return = " + managedTarget + "->" + f.CLRName + ";");
                managedCall = "mp_return";
            }
            else if (f.IsSetProperty)
            {
                DefParam param = f.Parameters[0];
                managedCall = managedTarget + "->" + f.CLRName + " = " + param.Type.GetNativeCallConversion(param.Name, param);
            }
            else
            {
                string pre, post, conv;

                foreach (DefParam param in f.Parameters)
                {
                    param.Type.GetNativeParamConversion(param, out pre, out conv, out post);
                    if (!String.IsNullOrEmpty(pre))
                        sb.AppendLine(pre);

                    if (!String.IsNullOrEmpty(post))
                        fullPostConv += post + "\n";
                }

                bool explicitCast = f.HasAttribute<ExplicitCastingForParamsAttribute>();

                if (!f.IsVoid)
                {
                    sb.AppendIndent(f.CLRTypeName + " mp_return = " + managedTarget + "->" + f.CLRName + "(");
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        DefParam param = f.Parameters[i];
                        param.Type.GetNativeParamConversion(param, out pre, out conv, out post);
                        sb.Append(" ");
                        if (explicitCast) sb.Append("(" + param.CLRTypeName + ")");
                        sb.Append(conv);
                        if (i < f.Parameters.Count - 1) sb.Append(",");
                    }
                    sb.Append(" );\n");
                    managedCall = "mp_return";

                    if (!String.IsNullOrEmpty(fullPostConv))
                        sb.AppendLine(fullPostConv);
                }
                else
                {
                    managedCall = managedTarget + "->" + f.CLRName + "(";
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        DefParam param = f.Parameters[i];
                        param.Type.GetNativeParamConversion(param, out pre, out conv, out post);
                        managedCall += " ";
                        if (explicitCast) managedCall += "(" + param.CLRTypeName + ")";
                        managedCall += conv;
                        if (i < f.Parameters.Count - 1) managedCall += ",";
                    }
                    managedCall += " )";
                }
            }

            if (!f.IsVoid)
            {
                if (f.Type is IDefString)
                {
                    sb.AppendLine("SET_NATIVE_STRING( Mogre::Implementation::cachedReturnString, " + managedCall + " )");
                    sb.AppendLine("return Mogre::Implementation::cachedReturnString;");
                }
                else
                {
                    string returnExpr;
                    string newname, expr, postcall;
                    DefParam param = new DefParam(f, managedCall);
                    expr = f.Type.GetPreCallParamConversion(param, out newname);
                    postcall = f.Type.GetPostCallParamConversionCleanup(param);
                    if (!String.IsNullOrEmpty(expr))
                    {
                        sb.AppendLine(expr);
                        if (String.IsNullOrEmpty(postcall))
                            returnExpr = newname;
                        else
                        {
                            throw new Exception("Unexpected");
                        }
                    }
                    else
                    {
                        returnExpr = newname;
                    }

                    if (IsCachedFunction(f))
                    {
                        sb.AppendLine("STATIC_ASSERT( sizeof(" + f.Type.FullNativeName + ") <= CACHED_RETURN_SIZE )");
                        sb.AppendLine("memcpy( Mogre::Implementation::cachedReturn, &" + returnExpr + ", sizeof(" + f.Type.FullNativeName + ") );");
                        sb.AppendLine("return *reinterpret_cast<" + f.Type.FullNativeName + "*>(Mogre::Implementation::cachedReturn);");
                    }
                    else
                    {
                        sb.AppendLine("return " + returnExpr + ";");
                    }
                }
            }
            else
            {
                sb.AppendLine(managedCall + ";");

                if (!String.IsNullOrEmpty(fullPostConv))
                    sb.AppendLine(fullPostConv);
            }
        }
        public override void Add()
        {
            if (_t.IsInterface)
            {
                IndentStringBuilder tempsb = _sb;
                _sb = new IndentStringBuilder();
                base.Add();
                string fname = _t.FullCLRName.Replace(_t.CLRName, _t.Name);
                string res = _sb.ToString().Replace(_t.FullCLRName + "::", fname + "::");
                fname = GetClassName().Replace(_t.CLRName, _t.Name);
                res = res.Replace(GetClassName() + "::", fname + "::");

                _sb = tempsb;
                _sb.AppendLine(res);
            }
            else
                base.Add();
        }
 public CppOverridableClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
     _wrapper.PostClassProducers.Add(new CppNativeProxyClassProducer(_wrapper, _t, _sb));
 }
 public NativeProtectedTypesProxy(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
 }
Exemplo n.º 15
0
        public virtual void AddFirst()
        {
            IndentStringBuilder orig = _sb;
            _sb = new IndentStringBuilder();

            Add();

            orig.sb.Insert(0, _sb.ToString());
            _sb = orig;
        }
Exemplo n.º 16
0
        public string CreateIncludeCodeForIncludeFile(string include)
        {
            UsedTypes.Clear();

            PreClassProducers.Clear();
            PostClassProducers.Clear();

            IndentStringBuilder sbTypes = new IndentStringBuilder();
            foreach (DefType t in IncludeFiles[include])
            {
                IncAddType(t, sbTypes);
            }

            foreach (ClassProducer producer in PostClassProducers)
            {
                producer.Add();
            }

            foreach (ClassProducer producer in PreClassProducers)
            {
                producer.AddFirst();
            }

            IndentStringBuilder sb = new IndentStringBuilder();
            sb.AppendLine("#pragma once\n");

            IncAddIncludeFiles(include, UsedTypes, sb);

            sb.AppendFormat("namespace {0}\n{{\n", ManagedNamespace);

            sb.IncreaseIndent();
            sb.AppendLine(sbTypes.ToString());
            sb.DecreaseIndent();

            sb.AppendLine("}");

            return sb.ToString().Replace("\r","");
        }
Exemplo n.º 17
0
        public string CreateIncludeCodeForOverridable(DefClass type)
        {
            UsedTypes.Clear();

            PreClassProducers.Clear();
            PostClassProducers.Clear();

            IndentStringBuilder sbTypes = new IndentStringBuilder();

            new IncSubclassingClassProducer(this, type, sbTypes, null).Add();
            if (type.HasAttribute<InterfacesForOverridableAttribute>())
            {
                List<DefClass[]> interfaces = type.GetAttribute<InterfacesForOverridableAttribute>().Interfaces;
                foreach (DefClass[] ifaces in interfaces)
                {
                    new IncSubclassingClassProducer(this, type, sbTypes, ifaces).Add();
                }
            }

            foreach (ClassProducer producer in PostClassProducers)
            {
                if (!(producer is NativeProtectedTypesProxy)
                    && !(producer is NativeProtectedStaticsProxy))
                    producer.Add();
            }

            foreach (ClassProducer producer in PreClassProducers)
            {
                if (!(producer is NativeProtectedTypesProxy)
                    && !(producer is NativeProtectedStaticsProxy))
                    producer.AddFirst();
            }

            IndentStringBuilder sb = new IndentStringBuilder();
            sb.AppendLine("#pragma once\n");

            sb.AppendFormat("namespace {0}\n{{\n", ManagedNamespace);

            sb.IncreaseIndent();
            sb.AppendLine(sbTypes.ToString());
            sb.DecreaseIndent();

            sb.AppendLine("}");

            return sb.ToString().Replace("\r", "");
        }
 public CppSubclassingClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb, DefClass[] additionalInterfaces)
     : base(wrapper, t, sb)
 {
     this._additionalInterfaces = additionalInterfaces;
 }
Exemplo n.º 19
0
        public void IncAddIterator(DefIterator t, IndentStringBuilder sb)
        {
            if (!t.IsNested)
            {
                this.AddPreDeclaration("ref class " + t.CLRName + ";");
            }

            CheckTypeForDependancy(t.IterationElementTypeMember.Type);

            if (t.IsMapIterator)
                CheckTypeForDependancy(t.IterationKeyTypeMember.Type);

            sb.AppendIndent(Producer.GetProtectionString(t.ProtectionType));
            if (t.IsNested) sb.Append(":");

            if (t.IsMapIterator)
                sb.Append(" INC_DECLARE_MAP_ITERATOR");
            else
                sb.Append(" INC_DECLARE_ITERATOR");

            if (t.TypeMembers[0].Type.ProtectionType == ProtectionType.Protected
                && !t.TypeMembers[0].Type.ParentClass.AllowVirtuals)
            {
                // the container type will not be declared,
                // declare an iterator without a constructor that takes a container class
                sb.Append("_NOCONSTRUCTOR");
            }

            if (t.IsMapIterator)
                sb.Append("( " + t.CLRName + ", " + t.FullNativeName + ", " + t.TypeMembers[0].Type.FullCLRName + ", " + t.IterationElementTypeMember.CLRTypeName + ", " + t.IterationElementTypeMember.NativeTypeName + ", " + t.IterationKeyTypeMember.CLRTypeName + ", " + t.IterationKeyTypeMember.NativeTypeName + " )\n");
            else
                sb.Append("( " + t.CLRName + ", " + t.FullNativeName + ", " + t.TypeMembers[0].Type.FullCLRName + ", " + t.IterationElementTypeMember.CLRTypeName + ", " + t.IterationElementTypeMember.NativeTypeName + " )\n");

            sb.AppendLine();
        }
Exemplo n.º 20
0
        private void IncAddIncludeFiles(string include, List<DefType> usedTypes, IndentStringBuilder sb)
        {
            sb.AppendFormat("#include \"{0}\"\n", include);
            List<string> added = new List<string>();

            foreach (DefType type in usedTypes)
            {
                if (String.IsNullOrEmpty(type.IncludeFile) || type.IncludeFile == include)
                    continue;

                if (added.Contains(type.IncludeFile))
                    continue;

                sb.AppendLine("#include \"" + GetManagedIncludeFileName(type.IncludeFile) + "\"");
                added.Add(type.IncludeFile);
            }

            sb.AppendLine();
        }
Exemplo n.º 21
0
        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);
                }
            }
        }
Exemplo n.º 22
0
        private void IncAddSharedPtrType(DefType type, IndentStringBuilder sb)
        {
            if (!type.Name.EndsWith("Ptr"))
                throw new Exception("SharedPtr class that doesn't have a name ending to 'Ptr'");

            string basename = null;
            if (type is DefClass)
                basename = (type as DefClass).Inherits[0];
            else
                basename = (type as DefTypeDef).BaseTypeName;

            int s = basename.IndexOf("<");
            int e = basename.LastIndexOf(">");
            string baseClass = basename.Substring(s + 1, e - s - 1).Trim();
            //string nativeClass = _nativePrefix + "::" + baseClass;
            string nativeClass = type.FindType<DefType>(baseClass).FullNativeName;

            string className = type.FullCLRName;
            if (className.Contains("::"))
                className = className.Substring(className.IndexOf("::") + 2);

            if (!type.IsNested)
            {
                PreDeclarations.Add("ref class " + type.Name + ";");
                sb.AppendIndent("public ");
            }
            else
            {
                sb.AppendIndent(Producer.GetProtectionString(type.ProtectionType) + ": ");
            }

            sb.Append("ref class " + type.Name + " : public " + baseClass + "\n");
            sb.AppendLine("{");
            sb.AppendLine("internal:");
            sb.IncreaseIndent();
            sb.AppendLine("\t" + type.FullNativeName + "* _sharedPtr;");
            sb.AppendLine();
            sb.AppendLine(type.Name + "(" + type.FullNativeName + "& sharedPtr) : " + baseClass + "( sharedPtr.getPointer() )");
            sb.AppendLine("{");
            sb.AppendLine("\t_sharedPtr = new " + type.FullNativeName + "(sharedPtr);");
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("!" + type.Name + "()");
            sb.AppendLine("{");
            sb.IncreaseIndent();
            sb.AppendLine("if (_sharedPtr != 0)");
            sb.AppendLine("{");
            sb.AppendLine("\tdelete _sharedPtr;");
            sb.AppendLine("\t_sharedPtr = 0;");
            sb.AppendLine("}");
            sb.DecreaseIndent();
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("~" + type.Name + "()");
            sb.AppendLine("{");
            sb.AppendLine("\tthis->!" + type.Name + "();");
            sb.AppendLine("}");
            sb.AppendLine();
            sb.DecreaseIndent();
            sb.AppendLine("public:");
            sb.IncreaseIndent();

            sb.AppendLine("DEFINE_MANAGED_NATIVE_CONVERSIONS_FOR_SHAREDPTR( " + className + " )");
            sb.AppendLine();

            if (type is DefClass)
            {
                DefClass realType = type.FindType<DefClass>(baseClass, false);
                if (realType != null && realType.BaseClass != null && realType.BaseClass.Name == "Resource")
                {
                    // For Resource subclasses (Material etc.) allow implicit conversion of ResourcePtr (i.e ResourcePtr -> MaterialPtr)

                    AddTypeDependancy(realType.BaseClass);

                    sb.AppendLine("static " + type.Name + "^ FromResourcePtr( ResourcePtr^ ptr )");
                    sb.AppendLine("{");
                    sb.AppendLine("\treturn (" + type.Name + "^) ptr;");
                    sb.AppendLine("}");
                    sb.AppendLine();

                    sb.AppendLine("static operator " + type.Name + "^ ( ResourcePtr^ ptr )");
                    sb.AppendLine("{");
                    sb.IncreaseIndent();
                    sb.AppendLine("void* castptr = dynamic_cast<" + nativeClass + "*>(ptr->_native);");
                    sb.AppendLine("if (castptr == 0) throw gcnew InvalidCastException(\"The underlying type of the ResourcePtr object is not of type " + baseClass + ".\");");
                    sb.AppendLine("return gcnew " + type.Name + "( (" + type.FullNativeName + ") *(ptr->_sharedPtr) );");
                    sb.DecreaseIndent();
                    sb.AppendLine("}");
                    sb.AppendLine();
                }
            }

            //sb.AppendLine(type.Name + "() : " + baseClass + "( (" + nativeClass + "*) 0 )");
            //sb.AppendLine("{");
            //sb.AppendLine("\t_sharedPtr = new " + type.FullNativeName + "();");
            //sb.AppendLine("}");
            //sb.AppendLine();
            sb.AppendLine(type.Name + "(" + baseClass + "^ obj) : " + baseClass + "( obj->_native )");
            sb.AppendLine("{");
            sb.AppendLine("\t_sharedPtr = new " + type.FullNativeName + "( static_cast<" + nativeClass + "*>(obj->_native) );");
            sb.AppendLine("}");
            sb.AppendLine();
            //sb.AppendLine("void Bind(" + baseClass + "^ obj)");
            //sb.AppendLine("{");
            //sb.AppendLine("\t(*_sharedPtr).bind( static_cast<" + nativeClass + "*>(obj->_native) );");
            //sb.AppendLine("}");
            //sb.AppendLine();

            sb.AppendLine("virtual bool Equals(Object^ obj) override");
            sb.AppendLine("{");
            sb.IncreaseIndent();
            sb.AppendLine(type.Name + "^ clr = dynamic_cast<" + type.Name + "^>(obj);");
            sb.AppendLine("if (clr == CLR_NULL)");
            sb.AppendLine("{");
            sb.AppendLine("\treturn false;");
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("return (_native == clr->_native);");
            sb.DecreaseIndent();
            sb.AppendLine("}");
            sb.AppendLine("bool Equals(" + type.Name + "^ obj)");
            sb.AppendLine("{");
            sb.IncreaseIndent();
            sb.AppendLine("if (obj == CLR_NULL)");
            sb.AppendLine("{");
            sb.AppendLine("\treturn false;");
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("return (_native == obj->_native);");
            sb.DecreaseIndent();
            sb.AppendLine("}");
            sb.AppendLine();

            sb.AppendLine("static bool operator == (" + type.Name + "^ val1, " + type.Name + "^ val2)");
            sb.AppendLine("{");
            sb.IncreaseIndent();
            sb.AppendLine("if ((Object^)val1 == (Object^)val2) return true;");
            sb.AppendLine("if ((Object^)val1 == nullptr || (Object^)val2 == nullptr) return false;");
            sb.AppendLine("return (val1->_native == val2->_native);");
            sb.DecreaseIndent();
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("static bool operator != (" + type.Name + "^ val1, " + type.Name + "^ val2)");
            sb.AppendLine("{");
            sb.AppendLine("\treturn !(val1 == val2);");
            sb.AppendLine("}");
            sb.AppendLine();

            sb.AppendLine("virtual int GetHashCode() override");
            sb.AppendLine("{");
            sb.AppendLine("\treturn reinterpret_cast<int>( _native );");
            sb.AppendLine("}");
            sb.AppendLine();

            sb.AppendLine("property IntPtr NativePtr");
            sb.AppendLine("{");
            sb.AppendLine("\tIntPtr get() { return (IntPtr)_sharedPtr; }");
            sb.AppendLine("}");
            sb.AppendLine();

            sb.AppendLine("property bool Unique");
            sb.AppendLine("{");
            sb.IncreaseIndent();
            sb.AppendLine("bool get()");
            sb.AppendLine("{");
            sb.AppendLine("\treturn (*_sharedPtr).unique();");
            sb.AppendLine("}");
            sb.DecreaseIndent();
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("property int UseCount");
            sb.AppendLine("{");
            sb.IncreaseIndent();
            sb.AppendLine("int get()");
            sb.AppendLine("{");
            sb.AppendLine("\treturn (*_sharedPtr).useCount();");
            sb.AppendLine("}");
            sb.DecreaseIndent();
            sb.AppendLine("}");
            sb.AppendLine();
            //sb.AppendLine("void SetNull()");
            //sb.AppendLine("{");
            //sb.AppendLine("\t(*_sharedPtr).setNull();");
            //sb.AppendLine("\t_native = 0;");
            //sb.AppendLine("}");
            //sb.AppendLine();
            sb.AppendLine("property bool IsNull");
            sb.AppendLine("{");
            sb.IncreaseIndent();
            sb.AppendLine("bool get()");
            sb.AppendLine("{");
            sb.AppendLine("\treturn (*_sharedPtr).isNull();");
            sb.AppendLine("}");
            sb.DecreaseIndent();
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("property " + baseClass + "^ Target");
            sb.AppendLine("{");
            sb.IncreaseIndent();
            sb.AppendLine(baseClass + "^ get()");
            sb.AppendLine("{");
            sb.AppendLine("\treturn static_cast<" + nativeClass + "*>(_native);");
            sb.AppendLine("}");
            sb.DecreaseIndent();
            sb.AppendLine("}");
            sb.DecreaseIndent();
            sb.AppendLine("};\n\n");
        }
Exemplo n.º 23
0
 //protected List<DefFunction> _protectedFunctions = new List<DefFunction>();
 public NativeProxyClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
     //SearchProtectedFunctions(_t);
 }
Exemplo n.º 24
0
        public void CppAddIterator(DefIterator t, IndentStringBuilder sb)
        {
            string prefix;
            if (!t.IsNested)
            {
                prefix = t.FullNativeName;
                prefix = prefix.Substring(0, prefix.LastIndexOf("::"));
            }
            else
            {
                prefix = t.ParentClass.FullNativeName;
            }

            if (prefix.Contains("::"))
                prefix = prefix.Substring(prefix.IndexOf("::") + 2) + "::";
            else
                prefix = "";

            if (t.IsMapIterator)
                sb.Append("CPP_DECLARE_MAP_ITERATOR");
            else
                sb.Append("CPP_DECLARE_ITERATOR");

            bool noConstructor = t.TypeMembers[0].Type.ProtectionType == ProtectionType.Protected
                && !t.TypeMembers[0].Type.ParentClass.AllowVirtuals;

            if (noConstructor)
            {
                // the container type will not be declared,
                // declare an iterator without a constructor that takes a container class
                sb.Append("_NOCONSTRUCTOR");
            }

            if (t.IsMapIterator)
                sb.Append("( " + prefix + ", " + t.CLRName + ", " + t.FullNativeName + ", " + t.TypeMembers[0].Type.FullCLRName + ", " + t.IterationElementTypeMember.CLRTypeName + ", " + t.IterationElementTypeMember.NativeTypeName + ", " + t.IterationKeyTypeMember.CLRTypeName + ", " + t.IterationKeyTypeMember.NativeTypeName);
            else
                sb.Append("( " + prefix + ", " + t.CLRName + ", " + t.FullNativeName + ", " + t.TypeMembers[0].Type.FullCLRName + ", " + t.IterationElementTypeMember.CLRTypeName + ", " + t.IterationElementTypeMember.NativeTypeName);

            if (!noConstructor)
            {
                if (t.IsConstIterator)
                    sb.Append(", const");
                else
                    sb.Append(", ");
            }

            sb.Append(" )\n");

            AddTypeDependancy(t.TypeMembers[0].Type);

            sb.AppendLine();
        }
 public IncSingletonClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
 }
Exemplo n.º 26
0
        public void CppAddSTLContainer(DefTypeDef t, IndentStringBuilder sb)
        {
            if (t is DefStdPair)
            {
                return;
            }

            if (t is DefTemplateOneType)
            {
                if (t.HasAttribute<STLListNoRemoveAndUniqueAttribute>())
                {
                    sb.AppendLine("#undef CPP_STLLIST_DEFINE_REMOVE_AND_UNIQUE");
                    sb.AppendLine("#define CPP_STLLIST_DEFINE_REMOVE_AND_UNIQUE(PREFIX,CLASS_NAME,M,N)");
                    sb.AppendLine();
                }

                sb.AppendLine("#define STLDECL_MANAGEDTYPE " + t.TypeMembers[0].CLRTypeName);
                sb.AppendLine("#define STLDECL_NATIVETYPE " + t.TypeMembers[0].NativeTypeName);
                CppCheckTypeForDependancy(t.TypeMembers[0].Type);
            }
            else if (t is DefTemplateTwoTypes)
            {
                sb.AppendLine("#define STLDECL_MANAGEDKEY " + t.TypeMembers[0].CLRTypeName);
                sb.AppendLine("#define STLDECL_MANAGEDVALUE " + t.TypeMembers[1].CLRTypeName);
                sb.AppendLine("#define STLDECL_NATIVEKEY " + t.TypeMembers[0].NativeTypeName);
                sb.AppendLine("#define STLDECL_NATIVEVALUE " + t.TypeMembers[1].NativeTypeName);
                CppCheckTypeForDependancy(t.TypeMembers[0].Type);
                CppCheckTypeForDependancy(t.TypeMembers[1].Type);
            }

            sb.AppendIndent("CPP_DECLARE_STL" + t.STLContainer.ToUpper());

            if (t.IsReadOnly)
                sb.Append("_READONLY");

            string prefix;
            if (!t.IsNested)
            {
                prefix = t.FullNativeName;
                prefix = prefix.Substring(0, prefix.LastIndexOf("::"));
            }
            else
            {
                prefix = t.ParentClass.FullNativeName;
            }

            if (prefix.Contains("::"))
                prefix = prefix.Substring(prefix.IndexOf("::") + 2) + "::";
            else
                prefix = "";

            sb.Append("( " + prefix + ", " + t.CLRName);

            if (t is DefTemplateOneType)
                sb.Append(", STLDECL_MANAGEDTYPE, STLDECL_NATIVETYPE )\n");
            else if (t is DefTemplateTwoTypes)
                sb.Append(", STLDECL_MANAGEDKEY, STLDECL_MANAGEDVALUE, STLDECL_NATIVEKEY, STLDECL_NATIVEVALUE )\n");
            else
                throw new Exception("Unexpected");

            if (t is DefTemplateOneType)
            {
                sb.AppendLine("#undef STLDECL_MANAGEDTYPE");
                sb.AppendLine("#undef STLDECL_NATIVETYPE");

                if (t.HasAttribute<STLListNoRemoveAndUniqueAttribute>())
                {
                    sb.AppendLine();
                    sb.AppendLine("#undef CPP_STLLIST_DEFINE_REMOVE_AND_UNIQUE");
                    sb.AppendLine("#define CPP_STLLIST_DEFINE_REMOVE_AND_UNIQUE(PREFIX,CLASS_NAME,M,N)    CPP_STLLIST_REMOVE_AND_UNIQUE_DEFINITIONS(PREFIX,CLASS_NAME,M,N)");
                }
            }
            else if (t is DefTemplateTwoTypes)
            {
                sb.AppendLine("#undef STLDECL_MANAGEDKEY");
                sb.AppendLine("#undef STLDECL_MANAGEDVALUE");
                sb.AppendLine("#undef STLDECL_NATIVEKEY");
                sb.AppendLine("#undef STLDECL_NATIVEVALUE");
            }

            sb.AppendLine();
        }
 public IncNonOverridableClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
 }
Exemplo n.º 28
0
        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 CppNativeDirectorClassProducer(Wrapper wrapper, DefClass t, IndentStringBuilder sb)
     : base(wrapper, t, sb)
 {
 }
Exemplo n.º 30
0
        public string CreateCppCodeForIncludeFile(string include, out bool hasContent)
        {
            UsedTypes.Clear();

            PreClassProducers.Clear();
            PostClassProducers.Clear();

            IndentStringBuilder contentsb = new IndentStringBuilder();
            foreach (DefType t in IncludeFiles[include])
            {
                CppAddType(t, contentsb);
            }

            foreach (ClassProducer producer in PostClassProducers)
            {
                producer.Add();
            }

            foreach (ClassProducer producer in PreClassProducers)
            {
                producer.AddFirst();
            }

            IndentStringBuilder sb = new IndentStringBuilder();
            hasContent = false;

            CppAddIncludeFiles(include, UsedTypes, sb);

            sb.AppendFormat("namespace {0}\n{{\n", ManagedNamespace);

            sb.IncreaseIndent();

            string txt = contentsb.ToString();
            if (txt != "")
            {
                hasContent = true;
                sb.AppendLine(txt);
            }

            sb.DecreaseIndent();

            sb.AppendLine("}");

            return sb.ToString().Replace("\r", "");
        }