Exemplo n.º 1
0
        /// <summary>
        /// Returns the domain ID for the given attribute type.
        /// </summary>
        /// <param name="kind">The attribute kind</param>
        /// <param name="enumAttrType">For enums, enumAttrType must be valid. Otherwise it may be null.</param>
        /// <returns></returns>
        protected String GetDomainID(AttributeKind kind, EnumAttributeType enumAttrType)
        {
            switch (kind)
            {
            case AttributeKind.BooleanAttr: return("DM_bool");

            case AttributeKind.DoubleAttr: return("DM_double");

            case AttributeKind.FloatAttr: return("DM_float");

            case AttributeKind.ByteAttr: return("DM_byte");

            case AttributeKind.ShortAttr: return("DM_short");

            case AttributeKind.IntegerAttr: return("DM_int");

            case AttributeKind.LongAttr: return("DM_long");

            case AttributeKind.StringAttr: return("DM_string");

            case AttributeKind.EnumAttr: return("DM_enum_" + enumAttrType.Name);

            default:
                throw new Exception("Unsupported attribute value type: \"" + kind + "\"");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes an AttributeType instance.
 /// </summary>
 /// <param name="name">The name for the attribute.</param>
 /// <param name="ownerType">The owner model type.</param>
 /// <param name="kind">The kind of the attribute.</param>
 /// <param name="enumType">The enum type description, if Kind == AttributeKind.EnumAttr, otherwise null.</param>
 /// <param name="valueType">The attribute type of the value of the set, if Kind == AttributeKind.SetAttr; the attribute type of the value of the map, if Kind == AttributeKind.MapAttr; the attribute type of the value of the array, if Kind == AttributeKind.ArrayAttr; the attribute type of the value of the deque, if Kind == AttributeKind.DequeAttr; otherwise null. </param>
 /// <param name="keyType">The attribute type of the key of the map, if Kind == AttributeKind.MapAttr; otherwise null.</param>
 /// <param name="typeName">The name of the attribute type, if Kind == AttributeKind.NodeAttr || Kind == AttributeKind.EdgeAttr; otherwise null.</param>
 /// <param name="package">The package name if this is a node or edge type that is contained in a package, otherwise null.</param>
 /// <param name="packagePrefixedTypeName">The name of the attribute type with the package as prefix if it is contained in a package, if Kind == AttributeKind.NodeAttr || Kind == AttributeKind.EdgeAttr.</param>
 /// <param name="type">The type of the attribute type.</param>
 public AttributeType(String name, InheritanceType ownerType, AttributeKind kind,
                      EnumAttributeType enumType, AttributeType valueType, AttributeType keyType,
                      String typeName, String package, String packagePrefixedTypeName, Type type)
 {
     Name      = name;
     OwnerType = ownerType;
     Kind      = kind;
     EnumType  = enumType;
     ValueType = valueType;
     KeyType   = keyType;
     TypeName  = typeName;
     Package   = package;
     PackagePrefixedTypeName = packagePrefixedTypeName;
     Type = type;
 }
Exemplo n.º 3
0
        protected void WriteEnumType(EnumAttributeType enumType)
        {
            String enumid = GetDomainID(enumType);

            WriteGXLNode(enumid, "Enum");

            foreach (EnumMember member in enumType.Members)
            {
                String memberid = "EV_";
                if ((int)member.Value < 0)
                {
                    memberid += "_" + (-member.Value);
                }
                else
                {
                    memberid += member.Value.ToString();
                }
                memberid += "_" + member.Name;
                WriteGXLNode(memberid, "EnumVal", new Attr("value", "string", member.Name));
                WriteGXLEdge(enumid, memberid, "containsValue");
            }
        }
Exemplo n.º 4
0
 protected String GetDomainID(EnumAttributeType enumAttrType)
 {
     return(GetDomainID(AttributeKind.EnumAttr, enumAttrType));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns a string representation of the given scalar value
        /// </summary>
        /// <param name="value">The scalar of which to get the string representation</param>
        /// <param name="attrType">The attribute type</param>
        /// <param name="graph">The graph with the model and the element names</param>
        /// <returns>String representation of the scalar.</returns>
        private static string ToString(object value, AttributeType attrType, IGraph graph)
        {
            // enums are bitches, sometimes ToString gives the symbolic name, sometimes only the integer value
            // we always want the symbolic name, enforce this here
            if (attrType != null && attrType.Kind == AttributeKind.EnumAttr)
            {
                Debug.Assert(attrType.Kind != AttributeKind.SetAttr && attrType.Kind != AttributeKind.MapAttr);
                EnumAttributeType enumAttrType = attrType.EnumType;
                EnumMember        member       = enumAttrType[(int)value];
                if (member != null)
                {
                    return(member.Name);
                }
            }
            if (graph != null && value is Enum)
            {
                Debug.Assert(value.GetType().Name != "Dictionary`2" && value.GetType().Name != "List`1" && value.GetType().Name != "Deque`1");
                foreach (EnumAttributeType enumAttrType in graph.Model.EnumAttributeTypes)
                {
                    if (value.GetType() == enumAttrType.EnumType)
                    {
                        EnumMember member = enumAttrType[(int)value];
                        if (member != null)
                        {
                            return(member.Name);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            // for set/map entries of node/edge type return the persistent name
            if (attrType != null && (attrType.Kind == AttributeKind.NodeAttr || attrType.Kind == AttributeKind.EdgeAttr))
            {
                if (graph != null && value != null)
                {
                    return(((INamedGraph)graph).GetElementName((IGraphElement)value));
                }
            }
            if (value is IGraphElement)
            {
                if (graph != null)
                {
                    return(((INamedGraph)graph).GetElementName((IGraphElement)value));
                }
            }

            // we return "" for null as null is a valid string denoting the empty string in GrGen (dubious performance optimization)
            if (value == null)
            {
                return("");
            }
            else
            {
                if (value is double)
                {
                    return(((double)value).ToString(System.Globalization.CultureInfo.InvariantCulture));
                }
                else if (value is float)
                {
                    return(((float)value).ToString(System.Globalization.CultureInfo.InvariantCulture) + "f");
                }
                else
                {
                    return(value.ToString());
                }
            }
        }