public CppStructureMember(StructureMember member, CppType type)
     : base(member)
 {
     _type = type;
 }
Esempio n. 2
0
        public override object CreateStructureMemberImplementationHelper(StructureMember member)
        {
            if (member.FieldTypeReference is IntrinsicTypeReference)
            {
                IntrinsicTypeReference reference = member.FieldTypeReference as IntrinsicTypeReference;

                return new CppStructureMember(member, _intrinsics[new Pair<IntrinsicType, FieldModifier>(reference.Type, member.Modifier)]);
            }
            else
            {
                DeclarationTypeReference reference = member.FieldTypeReference as DeclarationTypeReference;

                bool isInProtocolNamespace =
                    reference.Declaration.QualifiedName.ContainingName.Equals(member.Parent.Parent.Name);

                CppType type;

                string referenceClassName = IdentifierToClassName(reference.Declaration.Identifier);

                if (reference.Declaration is Enumeration)
                {
                    string typeName = string.Format("{0}::Enumeration", referenceClassName);

                    if (member.Modifier == FieldModifier.Optional) typeName = string.Format("CNullable<{0}>", typeName);

                    if (isInProtocolNamespace)
                    {
                        type = new CppType(typeName, typeName);
                    }
                    else
                    {
                        type = new CppType(typeName, typeName);
                    }
                }
                else if (reference.Declaration.Implementation is CppStructure)
                {
                    CppStructure structure = (CppStructure)reference.Declaration.Implementation;

                    if (!structure.IsSurrogate)
                    {
                        type = new CppType(
                            string.Format("boost::shared_ptr<{0}>", referenceClassName),
                            string.Format("const boost::shared_ptr<{0}>", referenceClassName),
                            null, referenceClassName, structure);
                    }
                    else
                    {
                        type = new CppType(
                            member.Modifier == FieldModifier.Required ? structure.SurrogateValueType : structure.SurrogateNullableValueType,
                            member.Modifier == FieldModifier.Required ? structure.SurrogateReferenceType : structure.SurrogateNullableReferenceType,
                            null, referenceClassName, structure);
                    }
                }
                else
                {
                    throw new InvalidOperationException();
                }

                return new CppStructureMember(member, type);
            }
        }