예제 #1
0
        /// <summary> 
        /// Generates all Simple data types.
        /// </summary>
        private void GenerateSimpleDataType(System.IO.StreamWriter stream, HLASimpleData simpleData)
        {
            int indentLevel = 0;
            string indentStr = GenerateIndentString(indentLevel);

            try
            {
                System.IO.StreamWriter sw;
                String typeName = simpleData.Name;
                if (stream == null)
                {
                    String qualifiedTypeName = packagePrefix + typeName;
                    String path = qualifiedTypeName.Replace('.', Path.DirectorySeparatorChar) + ".cs";
                    System.IO.FileInfo sourceFile = new System.IO.FileInfo(targetDirectory.FullName + Path.DirectorySeparatorChar + path);
                    System.IO.Directory.CreateDirectory(new System.IO.FileInfo(sourceFile.DirectoryName).FullName);

                    System.IO.FileStream fos = new System.IO.FileStream(sourceFile.FullName, System.IO.FileMode.Create);
                    sw = new System.IO.StreamWriter(fos);
                    System.String packageName = GetPackageName(qualifiedTypeName);

                    if (packageName != null)
                    {
                        sw.WriteLine(indentStr + "namespace " + packageName);
                    }
                    else
                    {
                        sw.WriteLine(indentStr + "namespace Sxta.Rti1516.Proxies");
                    }

                    sw.WriteLine(indentStr + "{");
                    indentLevel++;
                    indentStr = GenerateIndentString(indentLevel);

                    sw.WriteLine(indentStr + "using System;");
                    sw.WriteLine(indentStr + "using System.IO;");
                    sw.WriteLine();
                    sw.WriteLine(indentStr + "using HlaEncodingReader = Sxta.Rti1516.Serializers.XrtiEncoding.HlaEncodingReader;");
                    sw.WriteLine(indentStr + "using HlaEncodingWriter = Sxta.Rti1516.Serializers.XrtiEncoding.HlaEncodingWriter;");
                    sw.WriteLine(indentStr + "using Sxta.Rti1516.Reflection;");
                }
                else
                {
                    sw = stream;
                }
                sw.WriteLine();
                if (!string.IsNullOrEmpty(simpleData.Semantics))
                {
                    PrintClassComment(sw, simpleData.Semantics, indentLevel);
                }
                else
                {
                    PrintClassComment(sw, "Autogenerated simple data type.", indentLevel);
                }
                GenerateHLASimpleDataAttribute(indentLevel, sw, simpleData);
                sw.WriteLine(indentStr + "public struct " + typeName);

                sw.WriteLine(indentStr + "{");
                indentLevel++;
                indentStr = GenerateIndentString(indentLevel);

                String representation = simpleData.Representation;
                if (string.IsNullOrEmpty(representation))
                {
                    throw new RTIexception("SimpleData :" + simpleData.Name + "doesn't have a representation");
                }
                String nativeType = NativeTypeForBasicRepresentation(representation);
                string indentStr1 = GenerateIndentString(indentLevel + 1);
                sw.WriteLine(indentStr + "public " + nativeType + " data;");
                sw.WriteLine();
                sw.WriteLine(indentStr + "public static implicit operator " + nativeType + "(" + simpleData.Name + " val)");
                sw.WriteLine(indentStr + "{");
                sw.WriteLine(indentStr1 + "return val.data;");
                sw.WriteLine(indentStr + "}");
                sw.WriteLine();
                sw.WriteLine(indentStr + "public static implicit operator " + simpleData.Name + "(" + nativeType + " val)");
                sw.WriteLine(indentStr + "{");
                sw.WriteLine(indentStr1 + simpleData.Name + " tmp = new " + simpleData.Name + "();");
                sw.WriteLine(indentStr1 + "tmp.data = val;");
                sw.WriteLine(indentStr1 + "return tmp;");
                sw.WriteLine(indentStr + "}");

                sw.WriteLine();
                indentLevel--;
                indentStr = GenerateIndentString(indentLevel);
                sw.WriteLine(indentStr + "}");
                sw.WriteLine();

                sw.WriteLine(indentStr + "[Serializable]");
                sw.WriteLine(indentStr + "public sealed class " + typeName + "XrtiSerializer");
                sw.WriteLine(indentStr + "{");
                indentLevel++;
                indentStr = GenerateIndentString(indentLevel);

                sw.WriteLine(indentStr + "///<summary> Reads and returns a " + typeName + " from the specified stream.</summary>");
                sw.WriteLine(indentStr + "///<param name=\"reader\"> the input stream to read from</param>");
                sw.WriteLine(indentStr + "///<returns>return the decoded value</returns>");
                sw.WriteLine(indentStr + "///<exception cref=\"IOException\"> if an error occurs</exception>");
                sw.WriteLine(indentStr + "public static " + typeName + " Deserialize(HlaEncodingReader reader)");
                sw.WriteLine(indentStr + "{");
                sw.WriteLine(GenerateIndentString(indentLevel + 1) + "return (" + typeName + ")reader.Read" + representation + "();");
                sw.WriteLine(indentStr + "}");
                sw.WriteLine();

                sw.WriteLine(indentStr + "///<summary>Writes this " + typeName + " to the specified stream.</summary>");
                sw.WriteLine(indentStr + "///<param name=\"writer\"> the stream to write to</param>");
                sw.WriteLine(indentStr + "///<exception cref=\"IOException\"> if an error occurs</exception>");
                sw.WriteLine(indentStr + "public static void Serialize(HlaEncodingWriter writer, " + typeName + " val)");
                sw.WriteLine(indentStr + "{");
                sw.WriteLine(GenerateIndentString(indentLevel + 1) + "writer.Write" + representation + "((" + nativeType + ")val);");
                sw.WriteLine(indentStr + "}");
                sw.WriteLine();

                indentLevel--;
                indentStr = GenerateIndentString(indentLevel);
                sw.WriteLine(indentStr + "}");
                if (stream == null)
                {
                    indentLevel--;
                    indentStr = GenerateIndentString(indentLevel);
                    sw.WriteLine(indentStr + "}");

                    sw.Flush();
                    sw.Close();
                }
            }
            catch (System.IO.IOException ioe)
            {
                System.Console.Error.WriteLine("Error generating simple data type: " + ioe);
            }
        }
예제 #2
0
 /// <summary> 
 /// Generates a <code>GenerateHLASimpleDataAttribute</code>.
 /// </summary>
 private void GenerateHLASimpleDataAttribute(int localIndentLevel, System.IO.StreamWriter ps, HLASimpleData simpleData)
 {
     string indentStr = GenerateIndentString(localIndentLevel);
     string newLine = "," + Environment.NewLine + indentStr + "                ";
     ps.Write(indentStr + "[HLASimpleData(Name = \"" + simpleData.Name + "\"");
     if (!String.IsNullOrEmpty(simpleData.NameNotes))
     {
         ps.Write(newLine);
         ps.Write("NameNotes = \"" + simpleData.NameNotes + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.Representation))
     {
         ps.Write(newLine);
         ps.Write("Representation = \"" + simpleData.Representation + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.RepresentationNotes))
     {
         ps.Write(newLine);
         ps.Write("RepresentationNotes = \"" + simpleData.RepresentationNotes + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.Semantics))
     {
         ps.Write(newLine);
         ps.Write("Semantics = \"" + simpleData.Semantics + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.SemanticsNotes))
     {
         ps.Write(newLine);
         ps.Write("SemanticsNotes = \"" + simpleData.SemanticsNotes + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.Accuracy))
     {
         ps.Write(newLine);
         ps.Write("Accuracy = \"" + simpleData.Accuracy + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.AccuracyNotes))
     {
         ps.Write(newLine);
         ps.Write("AccuracyNotes = \"" + simpleData.AccuracyNotes + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.Resolution))
     {
         ps.Write(newLine);
         ps.Write("Resolution = \"" + simpleData.Resolution + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.ResolutionNotes))
     {
         ps.Write(newLine);
         ps.Write("ResolutionNotes = \"" + simpleData.ResolutionNotes + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.Units))
     {
         ps.Write(newLine);
         ps.Write("Units = \"" + simpleData.Units + "\"");
     }
     if (!String.IsNullOrEmpty(simpleData.UnitsNotes))
     {
         ps.Write(newLine);
         ps.Write("UnitsNotes = \"" + simpleData.UnitsNotes + "\"");
     }
     ps.WriteLine(")]");
 }
예제 #3
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public HLASimpleDataAttribute()
 {
     baseInfo = new HLASimpleData();
 }
예제 #4
0
        /// <summary> 
        /// Adds a set of descriptors corresponding to the features contained
        /// in the specified federation description document.  Handle
        /// values will be assigned in the order that the described features are
        /// encountered in the document, starting at <code>1</code>.
        /// </summary>
        /// <param name="fdd">the parsed federation description document to interpret
        /// </param>
        public virtual void AddDescriptors(System.Xml.XmlDocument fdd)
        {
            System.Xml.XmlElement documentElement = (System.Xml.XmlElement)fdd.DocumentElement;

            objectModel = new HLAObjectModel(documentElement);

            names.Add(objectModel.Name);

            System.String version = objectModel.Version;
            if (!string.IsNullOrEmpty(version))
            {
                SupportClass.Tokenizer st = new SupportClass.Tokenizer(version, " .");
                majorVersion = System.Int32.Parse(st.NextToken());
                minorVersion = System.Int32.Parse(st.NextToken());
            }

            // First pass creates descriptors, assigns handles

            System.Xml.XmlNodeList nl = documentElement.GetElementsByTagName("basicData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement basicDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLABasicData basicData = new HLABasicData(basicDataElement);
                basicDataMap[basicData.Name] = basicData;
            }

            nl = documentElement.GetElementsByTagName("simpleData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement simpleDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLASimpleData simpleData = new HLASimpleData(simpleDataElement);
                simpleDataMap[simpleData.Name] = simpleData;
            }
            nl = documentElement.GetElementsByTagName("enumeratedData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement enumeratedDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLAEnumeratedData enumeratedData = new HLAEnumeratedData(enumeratedDataElement);
                enumeratedDataMap[enumeratedData.Name] = enumeratedData;
            }
            nl = documentElement.GetElementsByTagName("fixedRecordData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement fixedRecordDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLAFixedRecordData fixedRecordData = new HLAFixedRecordData(fixedRecordDataElement);
                fixedRecordDataMap[fixedRecordData.Name] = fixedRecordData;
            }
            nl = documentElement.GetElementsByTagName("arrayData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement arrayDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLAarrayDataType arrayData = new HLAarrayDataType(arrayDataElement);
                arrayDataMap[arrayData.Name] = arrayData;
            }

            nl = documentElement.GetElementsByTagName(OBJECT_CLASS);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement objectClassElement = (System.Xml.XmlElement)nl.Item(i);

                ObjectClassDescriptor ocd = new ObjectClassDescriptor(objectClassElement, new XRTIObjectClassHandle(handleCounter++), new List<ObjectClassDescriptor>());
                System.Xml.XmlNodeList nl2 = objectClassElement.ChildNodes;
                for (int j = 0; j < nl2.Count; j++)
                {
                    if (nl2.Item(j) is System.Xml.XmlElement && nl2.Item(j).Name.Equals(ATTRIBUTE))
                    {
                        System.Xml.XmlElement attributeElement = (System.Xml.XmlElement)nl2.Item(j);

                        AttributeDescriptor ad = new AttributeDescriptor(attributeElement, new XRTIAttributeHandle(handleCounter++), new XRTIDimensionHandleSet(), "HLAreliable".Equals(attributeElement.GetAttribute(TRANSPORTATION)) ? TransportationType.HLA_RELIABLE : TransportationType.HLA_BEST_EFFORT, "Receive".Equals(attributeElement.GetAttribute(ORDER)) ? Hla.Rti1516.OrderType.RECEIVE : OrderType.TIMESTAMP);
                        ocd.AddAttributeDescriptor(ad);

                        // PATCH ANGEL
                        AddAttributeDescriptor(ad);
                    }
                }

                AddObjectClassDescriptor(ocd);
            }

            nl = documentElement.GetElementsByTagName(INTERACTION_CLASS);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement interactionClassElement = (System.Xml.XmlElement)nl.Item(i);

                InteractionClassDescriptor icd = new InteractionClassDescriptor(interactionClassElement, new XRTIInteractionClassHandle(handleCounter++), new List<InteractionClassDescriptor>(), new XRTIDimensionHandleSet(), "HLAreliable".Equals(interactionClassElement.GetAttribute(TRANSPORTATION)) ? TransportationType.HLA_RELIABLE : TransportationType.HLA_BEST_EFFORT, "Receive".Equals(interactionClassElement.GetAttribute(ORDER)) ? Sxta.Rti1516.Reflection.HLAorderType.Receive : Sxta.Rti1516.Reflection.HLAorderType.TimeStamp);

                System.Xml.XmlNodeList nl2 = interactionClassElement.ChildNodes;

                for (int j = 0; j < nl2.Count; j++)
                {
                    if (nl2.Item(j) is System.Xml.XmlElement && nl2.Item(j).Name.Equals(PARAMETER))
                    {
                        System.Xml.XmlElement parameterElement = (System.Xml.XmlElement)nl2.Item(j);

                        icd.AddParameterDescriptor(new ParameterDescriptor(parameterElement, new XRTIParameterHandle(handleCounter++)));
                    }
                }

                AddInteractionClassDescriptor(icd);
            }

            nl = documentElement.GetElementsByTagName(DIMENSION);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement dimensionElement = (System.Xml.XmlElement)nl.Item(i);

                long upperBound = System.Int64.MaxValue;

                if (dimensionElement.HasAttribute(UPPER_BOUND))
                {
                    try
                    {
                        upperBound = System.Int64.Parse(dimensionElement.GetAttribute(UPPER_BOUND));
                    }
                    catch (System.FormatException)
                    {
                    }
                }
                AddDimensionDescriptor(new DimensionDescriptor(dimensionElement.GetAttribute(NAME), new XRTIDimensionHandle(handleCounter++), upperBound));
            }

            // Second pass resolves parents, dimensions

            nl = documentElement.GetElementsByTagName(OBJECT_CLASS);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement objectClassElement = (System.Xml.XmlElement)nl.Item(i);

                ObjectClassDescriptor ocd = GetObjectClassDescriptor(objectClassElement.GetAttribute(NAME));

                if (objectClassElement.ParentNode.Name.Equals(OBJECT_CLASS))
                {
                    ocd.AddParentDescriptor(GetObjectClassDescriptor(((System.Xml.XmlElement)objectClassElement.ParentNode).GetAttribute(NAME)));
                }

                if (objectClassElement.HasAttribute(PARENTS))
                {
                    SupportClass.Tokenizer st = new SupportClass.Tokenizer(objectClassElement.GetAttribute(PARENTS));

                    // PATCH ANGEL while (st.HasMoreTokens())
                    //{
                    ocd.ParentDescriptors.Add(GetObjectClassDescriptor(st.NextToken()));
                    //}
                }

                System.Xml.XmlNodeList nl2 = objectClassElement.ChildNodes;
                for (int j = 0; j < nl2.Count; j++)
                {
                    if (nl2.Item(j) is System.Xml.XmlElement && nl2.Item(j).Name.Equals(ATTRIBUTE))
                    {
                        System.Xml.XmlElement attributeElement = (System.Xml.XmlElement)nl2.Item(j);

                        if (attributeElement.HasAttribute(DIMENSIONS))
                        {
                            AttributeDescriptor ad = ocd.GetAttributeDescriptor(attributeElement.GetAttribute(NAME));

                            SupportClass.Tokenizer st = new SupportClass.Tokenizer(attributeElement.GetAttribute(DIMENSIONS));

                            // PATCH ANGEL while (st.HasMoreTokens())
                            //{
                            System.String dimension = st.NextToken();

                            if (!dimension.Equals("NA"))
                            {
                                ad.Dimensions.Add(GetDimensionDescriptor(dimension).Handle);
                            }
                            //}
                        }
                    }
                }
            }

            nl = documentElement.GetElementsByTagName(INTERACTION_CLASS);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement interactionClassElement = (System.Xml.XmlElement)nl.Item(i);

                InteractionClassDescriptor icd = GetInteractionClassDescriptor(interactionClassElement.GetAttribute(NAME));

                if (interactionClassElement.HasAttribute(DIMENSIONS))
                {
                    SupportClass.Tokenizer st = new SupportClass.Tokenizer(interactionClassElement.GetAttribute(DIMENSIONS));

                    // PATCH ANGEL while (st.HasMoreTokens())
                    //{
                    System.String dimension = st.NextToken();

                    if (!dimension.Equals("NA"))
                    {
                        icd.Dimensions.Add(GetDimensionDescriptor(dimension).Handle);
                    }
                    //}
                }

                if (interactionClassElement.ParentNode.Name.Equals(INTERACTION_CLASS))
                {
                    icd.AddParentDescriptor(GetInteractionClassDescriptor(((System.Xml.XmlElement)interactionClassElement.ParentNode).GetAttribute(NAME)));
                }

                if (interactionClassElement.HasAttribute(PARENTS))
                {
                    SupportClass.Tokenizer st = new SupportClass.Tokenizer(interactionClassElement.GetAttribute(PARENTS));

                    // PATCH ANGEL while (st.HasMoreTokens())
                    //{
                    icd.AddParentDescriptor(GetInteractionClassDescriptor(st.NextToken()));
                    //}
                }
            }

            //PATCH ANGEL CheckAopFdd();
        }
예제 #5
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public HLASimpleDataAttribute()
 {
     baseInfo = new HLASimpleData();
 }