Beispiel #1
0
        public NativeSchemaInfo(XmlSchemaTypeLoader typeLoader)
        {
            m_nativeClasses = new List <NativeClassInfo>();

            // parse schema & add our Annotations
            foreach (DomNodeType domType in typeLoader.GetNodeTypes())
            {
                IEnumerable <XmlNode> annotations = domType.GetTagLocal <IEnumerable <XmlNode> >();
                if (annotations == null)
                {
                    continue;
                }

                NativeClassInfo classInfo = null;
                foreach (XmlNode annot in annotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == SchemaStrings.LegeNativeType)
                    {
                        classInfo = new NativeClassInfo(elm, domType.IsAbstract);
                        m_nativeClasses.Add(classInfo);
                        break;
                    }
                }

                if (classInfo == null)
                {
                    continue;
                }

                foreach (XmlNode annot in annotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == SchemaStrings.LeGeNativeProperty)
                    {
                        NativePropertyInfo info = new NativePropertyInfo(elm);
                        classInfo.Properties.Add(info);
                    }
                    else if (elm.LocalName == SchemaStrings.LeGeNativeElement)
                    {
                        NativeListInfo info = new NativeListInfo(elm);
                        classInfo.Lists.Add(info);
                    }
                }
            }
        }
Beispiel #2
0
 private static void GeneratePropertyRegistration(StringBuilder sb, NativeClassInfo classInfo, NativePropertyInfo info)
 {
     string setFunc = info.Setable ? String.Format("&{0}_{1}_Set", classInfo.NativeName, info.NativeName) : "NULL";
     string getFunc = info.Getable ? String.Format("&{0}_{1}_Get", classInfo.NativeName, info.NativeName) : "NULL";
     WriteLine(sb, "  bridge.RegisterProperty( \"{0}\", \"{1}\", {3}, {4} );", classInfo.NativeName, info.NativeName, info.NativeType, setFunc, getFunc);
 }
Beispiel #3
0
        private static void GeneratePropertyDefinition(StringBuilder sb, NativeClassInfo classInfo, NativePropertyInfo info)
        {
            WriteLine(sb, "");
            if (info.Setable)
            {
                WriteLine(sb, "//-----------------------------------------------------------------------------");
                WriteLine(sb, "void {0}_{1}_Set({2} instanceId, void* data, int size)", classInfo.NativeName, info.NativeName, ConstStrings.ObjectID);
                WriteLine(sb, "{{");
                WriteLine(sb, "    assert((data && size > 0) || (!data && size == 0));");
                WriteLine(sb, "    {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
                switch (info.NativeType)
                {                    
                    case "Matrix":
                    case "AABB":
                    case "float2":                          
                    case "float3":                        
                    case "float4":                    
                    case "bool":                        
                    case "float":
                    case "int":
                    case "int8_t":
                    case "uint8_t":
                    case "int16_t":
                    case "uint16_t":
                    case "int32_t":
                    case "uint32_t":
                    case "int64_t":
                    case "uint64_t":
                        WriteLine(sb, "    {0} localData = *reinterpret_cast<{0}*>(data);", info.NativeType);
                        WriteLine(sb, "    instance->Set{0}(localData);", info.NativeName);
                        break;
                    case "wchar_t*":
                    case "char*":
                        WriteLine(sb, "    {0} localData = reinterpret_cast<{0}>(data);", info.NativeType);
                        WriteLine(sb, "    instance->Set{0}(localData);", info.NativeName);
                        break;
                    default:
                        WriteLine(sb, "    {0} localData = reinterpret_cast<{0}>(data);", info.NativeType);
                        WriteLine(sb, "    instance->Set{0}(localData, size);", info.NativeName);
                        break;

                }
                WriteLine(sb, "}}");
            }
            if (info.Getable)
            {
                WriteLine(sb, "//-----------------------------------------------------------------------------");
                WriteLine(sb, "void {0}_{1}_Get({2} instanceId, void** data, int* size)", classInfo.NativeName, info.NativeName, ConstStrings.ObjectID);
                WriteLine(sb, "{{");
                WriteLine(sb, "    {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
                WriteLine(sb, "    static {0} localData;", info.NativeType);
                WriteLine(sb, "    localData = instance->Get{0}();", info.NativeName);
                WriteLine(sb, "    *data = (void*)&localData;");
                WriteLine(sb, "    *size = sizeof(localData);");
                WriteLine(sb, "}}");
            }
        }
Beispiel #4
0
        private static void GeneratePropertyDefinition(StringBuilder sb, NativeClassInfo classInfo, NativePropertyInfo info)
        {
            WriteLine(sb, "");
            if (info.Setable)
            {
                WriteLine(sb, "//-----------------------------------------------------------------------------");
                WriteLine(sb, "void {0}_{1}_Set({2} instanceId, void* data, int size)", classInfo.NativeName, info.NativeName, ConstStrings.ObjectID);
                WriteLine(sb, "{{");
                WriteLine(sb, "    assert((data && size > 0) || (!data && size == 0));");
                WriteLine(sb, "    {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
                switch (info.NativeType)
                {
                case "Matrix":
                case "AABB":
                case "float2":
                case "float3":
                case "float4":
                case "bool":
                case "float":
                case "int":
                case "int8_t":
                case "uint8_t":
                case "int16_t":
                case "uint16_t":
                case "int32_t":
                case "uint32_t":
                case "int64_t":
                case "uint64_t":
                    WriteLine(sb, "    {0} localData = *reinterpret_cast<{0}*>(data);", info.NativeType);
                    WriteLine(sb, "    instance->Set{0}(localData);", info.NativeName);
                    break;

                case "wchar_t*":
                case "char*":
                    WriteLine(sb, "    {0} localData = reinterpret_cast<{0}>(data);", info.NativeType);
                    WriteLine(sb, "    instance->Set{0}(localData);", info.NativeName);
                    break;

                default:
                    WriteLine(sb, "    {0} localData = reinterpret_cast<{0}>(data);", info.NativeType);
                    WriteLine(sb, "    instance->Set{0}(localData, size);", info.NativeName);
                    break;
                }
                WriteLine(sb, "}}");
            }
            if (info.Getable)
            {
                WriteLine(sb, "//-----------------------------------------------------------------------------");
                WriteLine(sb, "void {0}_{1}_Get({2} instanceId, void** data, int* size)", classInfo.NativeName, info.NativeName, ConstStrings.ObjectID);
                WriteLine(sb, "{{");
                WriteLine(sb, "    {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
                WriteLine(sb, "    static {0} localData;", info.NativeType);
                WriteLine(sb, "    localData = instance->Get{0}();", info.NativeName);

                // need special handling for strings and wide strings here,
                // or you'll end up trying to marshal the memory address
                // instead of the contents into a managed string downstream
                switch (info.NativeType)
                {
                case "wchar_t*":
                    WriteLine(sb, "    *data = (void*)localData;");
                    WriteLine(sb, "    *size = wcslen(localData);");
                    break;

                case "char*":
                    WriteLine(sb, "    *data = (void*)localData;");
                    WriteLine(sb, "    *size = strlen(localData);");
                    break;

                default:
                    WriteLine(sb, "    *data = (void*)&localData;");
                    WriteLine(sb, "    *size = sizeof(localData);");
                    break;
                }
                WriteLine(sb, "}}");
            }
        }
Beispiel #5
0
        private static void GeneratePropertyRegistration(StringBuilder sb, NativeClassInfo classInfo, NativePropertyInfo info)
        {
            string setFunc = info.Setable ? String.Format("&{0}_{1}_Set", classInfo.NativeName, info.NativeName) : "NULL";
            string getFunc = info.Getable ? String.Format("&{0}_{1}_Get", classInfo.NativeName, info.NativeName) : "NULL";

            WriteLine(sb, "  bridge.RegisterProperty( \"{0}\", \"{1}\", {3}, {4} );", classInfo.NativeName, info.NativeName, info.NativeType, setFunc, getFunc);
        }
Beispiel #6
0
        public NativeSchemaInfo(XmlSchemaTypeLoader typeLoader)
        {
            m_nativeClasses = new List<NativeClassInfo>();

            // parse schema & add our Annotations
            foreach (DomNodeType domType in typeLoader.GetNodeTypes())
            {
                IEnumerable<XmlNode> annotations = domType.GetTagLocal<IEnumerable<XmlNode>>();
                if (annotations == null)
                    continue;
                                
                NativeClassInfo classInfo = null;
                foreach (XmlNode annot in annotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == SchemaStrings.LegeNativeType)
                    {
                        classInfo = new NativeClassInfo(elm, domType.IsAbstract);
                        m_nativeClasses.Add(classInfo);
                        break;
                    }
                }

                if (classInfo == null) continue;

                foreach (XmlNode annot in annotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == SchemaStrings.LeGeNativeProperty)
                    {
                        NativePropertyInfo info = new NativePropertyInfo(elm);
                        classInfo.Properties.Add(info);
                    }
                    else if (elm.LocalName == SchemaStrings.LeGeNativeElement)
                    {
                        NativeListInfo info = new NativeListInfo(elm);
                        classInfo.Lists.Add(info);
                    }
                }
            }
        }
Beispiel #7
0
        private static void GeneratePropertyDefinition(StringBuilder sb, NativeClassInfo classInfo, NativePropertyInfo info)
        {
            WriteLine(sb, "");
            if (info.Setable)
            {
                WriteLine(sb, "//-----------------------------------------------------------------------------");
                WriteLine(sb, "void {0}_{1}_Set({2} instanceId, void* data, int size)", classInfo.NativeName, info.NativeName, ConstStrings.ObjectID);
                WriteLine(sb, "{{");
                WriteLine(sb, "    assert((data && size > 0) || (!data && size == 0));");
                WriteLine(sb, "    {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
                switch (info.NativeType)
                {                    
                    case "Matrix":
                    case "AABB":
                    case "float2":                          
                    case "float3":                        
                    case "float4":                    
                    case "bool":                        
                    case "float":
                    case "int":
                    case "int8_t":
                    case "uint8_t":
                    case "int16_t":
                    case "uint16_t":
                    case "int32_t":
                    case "uint32_t":
                    case "int64_t":
                    case "uint64_t":
                        WriteLine(sb, "    {0} localData = *reinterpret_cast<{0}*>(data);", info.NativeType);
                        WriteLine(sb, "    instance->Set{0}(localData);", info.NativeName);
                        break;
                    case "wchar_t*":
                    case "char*":
                        WriteLine(sb, "    {0} localData = reinterpret_cast<{0}>(data);", info.NativeType);
                        WriteLine(sb, "    instance->Set{0}(localData);", info.NativeName);
                        break;
                    default:
                        WriteLine(sb, "    {0} localData = reinterpret_cast<{0}>(data);", info.NativeType);
                        WriteLine(sb, "    instance->Set{0}(localData, size);", info.NativeName);
                        break;

                }
                WriteLine(sb, "}}");
            }
            if (info.Getable)
            {
                WriteLine(sb, "//-----------------------------------------------------------------------------");
                WriteLine(sb, "void {0}_{1}_Get({2} instanceId, void** data, int* size)", classInfo.NativeName, info.NativeName, ConstStrings.ObjectID);
                WriteLine(sb, "{{");
                WriteLine(sb, "    {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
                WriteLine(sb, "    static {0} localData;", info.NativeType);
                WriteLine(sb, "    localData = instance->Get{0}();", info.NativeName);

                // need special handling for strings and wide strings here,
                // or you'll end up trying to marshal the memory address
                // instead of the contents into a managed string downstream
                switch(info.NativeType)
                {
                    case "wchar_t*":
                        WriteLine(sb, "    *data = (void*)localData;");
                        WriteLine(sb, "    *size = wcslen(localData);");
                        break;
                    case "char*":
                        WriteLine(sb, "    *data = (void*)localData;");
                        WriteLine(sb, "    *size = strlen(localData);");
                        break;

                    default:
                        WriteLine(sb, "    *data = (void*)&localData;");
                        WriteLine(sb, "    *size = sizeof(localData);");
                        break;
                }
                WriteLine(sb, "}}");
            }
        }
Beispiel #8
0
        private static void GeneratePropertyDefinition(StringBuilder sb, NativeClassInfo classInfo, NativePropertyInfo info)
        {
            WriteLine(sb, "");
            if (info.Setable)
            {
                WriteLine(sb, "//-----------------------------------------------------------------------------");
                WriteLine(sb, "void {0}_{1}_Set({2} instanceId, void* data, int size)", classInfo.NativeName, info.NativeName, ConstStrings.ObjectID);
                WriteLine(sb, "{{");
                WriteLine(sb, "    assert((data && size > 0) || (!data && size == 0));");
                WriteLine(sb, "    {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
                switch (info.NativeType)
                {
                case "Matrix":
                case "AABB":
                case "float2":
                case "float3":
                case "float4":
                case "bool":
                case "float":
                case "int":
                case "int8_t":
                case "uint8_t":
                case "int16_t":
                case "uint16_t":
                case "int32_t":
                case "uint32_t":
                case "int64_t":
                case "uint64_t":
                    WriteLine(sb, "    {0} localData = *reinterpret_cast<{0}*>(data);", info.NativeType);
                    WriteLine(sb, "    instance->Set{0}(localData);", info.NativeName);
                    break;

                case "wchar_t*":
                case "char*":
                    WriteLine(sb, "    {0} localData = reinterpret_cast<{0}>(data);", info.NativeType);
                    WriteLine(sb, "    instance->Set{0}(localData);", info.NativeName);
                    break;

                default:
                    WriteLine(sb, "    {0} localData = reinterpret_cast<{0}>(data);", info.NativeType);
                    WriteLine(sb, "    instance->Set{0}(localData, size);", info.NativeName);
                    break;
                }
                WriteLine(sb, "}}");
            }
            if (info.Getable)
            {
                WriteLine(sb, "//-----------------------------------------------------------------------------");
                WriteLine(sb, "void {0}_{1}_Get({2} instanceId, void** data, int* size)", classInfo.NativeName, info.NativeName, ConstStrings.ObjectID);
                WriteLine(sb, "{{");
                WriteLine(sb, "    {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
                WriteLine(sb, "    static {0} localData;", info.NativeType);
                WriteLine(sb, "    localData = instance->Get{0}();", info.NativeName);
                WriteLine(sb, "    *data = (void*)&localData;");
                WriteLine(sb, "    *size = sizeof(localData);");
                WriteLine(sb, "}}");
            }
        }