protected virtual AbstractTypeDefinition CreateSTLCollectionType(TypedefDefinition typedef)
        {
            string baseTypeName = Mogre17.GetBaseType(typedef);

            switch (baseTypeName)
            {
            case "std::vector":
                return(new DefStdVector(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            case "std::set":
                return(new DefStdSet(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            case "std::deque":
                return(new DefStdDeque(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            case "std::list":
                return(new DefStdList(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            case "HashedVector":
                return(new DefHashedVector(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            case "std::map":
                return(new DefStdMap(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            default:
                throw new Exception("Unexpected");
            }
        }
        public virtual AbstractTypeDefinition FindStandardType(TypedefDefinition typedef)
        {
            AbstractTypeDefinition expl = null;

            if (typedef.BaseTypeName.Contains("<") || typedef.BaseTypeName.Contains("std::") || Mogre17.IsCollection(typedef.BaseTypeName))
            {
                if (typedef.BaseTypeName == "std::vector" || typedef.BaseTypeName == "std::list")
                {
                    expl = CreateTemplateOneTypeParamType(typedef);
                }
                else
                {
                    switch (typedef.TypeParamNames.Length)
                    {
                    case 1:
                        expl = CreateTemplateOneTypeParamType(typedef);
                        break;

                    case 2:
                        expl = CreateTemplateTwoTypeParamsType(typedef);
                        break;

                    default:
                        throw new Exception("Unexpected");
                    }
                }
            }

            if (expl == null)
            {
                throw new ArgumentException("Unsupported or unknown standard type: " + typedef.BaseTypeName);
            }

            return(expl);
        }
        /// <summary>
        /// Creates a type definition for a collection type (e.g. a list or a map).
        /// </summary>
        public static AbstractTypeDefinition CreateExplicitCollectionType(ClassDefinition surroundingClass, string container, string key, string val)
        {
            string      stdcont = "std::" + container;
            XmlDocument doc     = new XmlDocument();

            XmlElement elem = doc.CreateElement("typedef");

            elem.SetAttribute("basetype", stdcont);
            elem.SetAttribute("name", stdcont);

            XmlElement te = doc.CreateElement("type");

            te.InnerText = val;
            elem.AppendChild(te);

            if (key != "")
            {
                te           = doc.CreateElement("type");
                te.InnerText = key;
                elem.InsertAfter(te, null);
            }

            TypedefDefinition newTypedef = surroundingClass.Namespace.MetaDef.Factory.CreateTypedef(surroundingClass.Namespace, surroundingClass, elem);

            return(newTypedef.ResolveType());
        }
Exemple #4
0
        public static bool IsIteratorWrapper(TypedefDefinition type)
        {
            string[] iters = new string[] { "MapIterator", "ConstMapIterator",
                                            "VectorIterator", "ConstVectorIterator" };

            foreach (string it in iters)
            {
                if (type.BaseTypeName.StartsWith(it))
                {
                    return(true);
                }
            }

            return(false);
        }
        protected virtual AbstractTypeDefinition CreateTemplateOneTypeParamType(TypedefDefinition typedef)
        {
            if (typedef.IsSharedPtr)
            {
                return(new DefSharedPtr(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));
            }

            if (AbstractCodeProducer.IsIteratorWrapper(typedef))
            {
                return(new DefIterator(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));
            }

            if (typedef.BaseTypeName.StartsWith("TRect"))
            {
                return(new DefTRect(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));
            }

            return(CreateSTLCollectionType(typedef));
        }
        protected virtual AbstractTypeDefinition CreateTemplateTwoTypeParamsType(TypedefDefinition typedef)
        {
            string baseTypeName = Mogre17.GetBaseType(typedef);

            switch (baseTypeName)
            {
            case "::std::hash_map":
                return(new DefStdHashMap(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            case "std::map":
                return(new DefStdMap(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            case "std::multimap":
                return(new DefStdMultiMap(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            case "std::pair":
                return(new DefStdPair(typedef.Namespace, typedef.SurroundingClass, typedef.DefiningXmlElement));

            default:
                throw new Exception("Unexpected");
            }
        }
Exemple #7
0
        public static string GetBaseType(TypedefDefinition typedef)
        {
            string baseTypeName = typedef.BaseTypeName;

            if (string.IsNullOrEmpty(baseTypeName))
            {
                return(baseTypeName);
            }

            int    charPos     = baseTypeName.IndexOf("<");
            string ogreTypeDef = charPos == -1 ? baseTypeName : baseTypeName.Substring(0, charPos);

            if (IsStdCollection(ogreTypeDef))
            {
                return("std::" + ogreTypeDef);
            }

            if (ogreTypeDef.Equals("HashedVector", StringComparison.Ordinal))
            {
                return(ogreTypeDef);
            }

            return(baseTypeName);
        }