Пример #1
0
        //============================================================================
        /// <summary>
        /// The new member to add to this structure.
        /// </summary>
        /// <param name="typedValue">Typed value to copy.</param>
        // N.Herrmann Apr 2002
        //============================================================================
        protected void initTypeCopy(TTypedValue typedValue)
        {
            uint i;

            Name = typedValue.Name;
            FBaseType = typedValue.baseType();
            FIsScalar = typedValue.isScalar();
            FIsArray = typedValue.isArray();
            FIsRecord = typedValue.isRecord();
            setUnits(typedValue.units());

            if (FIsScalar)
            {
                createScalar();
                switch (FBaseType)
                {                                           //For scalars, copy the value data.
                    case TBaseType.ITYPE_INT1:                                            //Data pertaining to arrays and records
                    case TBaseType.ITYPE_INT2:                                            //   is ultimately stored in their
                    case TBaseType.ITYPE_INT4:                                            //   constituent scalars
                    case TBaseType.ITYPE_INT8: setValue(typedValue.asInt()); break;
                    case TBaseType.ITYPE_SINGLE: setValue(typedValue.asSingle()); break;
                    case TBaseType.ITYPE_DOUBLE: setValue(typedValue.asDouble()); break;
                    case TBaseType.ITYPE_BOOL: setValue(typedValue.asBool()); break;
                    case TBaseType.ITYPE_CHAR:
                    case TBaseType.ITYPE_WCHAR: setValue(typedValue.asChar()); break;
                    case TBaseType.ITYPE_STR:
                    case TBaseType.ITYPE_WSTR: setValue(typedValue.asStr()); break;
                }
            }
            else if (FIsArray || FIsRecord)
            {
                uint iCount = typedValue.count();
                if (FIsArray && (iCount == 0))
                {
                    if (typedValue.item(0) != null)
                        newMember(typedValue.item(0));
                    setElementCount(0);
                }
                else
                    for (i = 1; i <= iCount; i++)
                        newMember(typedValue.item(i)); //clones and adds this typed value
            }
        }
Пример #2
0
      //============================================================================
      /// <summary>
      /// Writes the SDML value as XML.
      /// </summary>
      /// <param name="attrInfo">The typed value to use.</param>
      /// <param name="indent">Indent spaces to use. -1 = no indent.</param>
      /// <param name="tab">Number of spaces in each tab</param>
      /// <returns>The XML for the SDML value.</returns>
      //============================================================================
       protected override String writeFieldInfo(TTypedValue attrInfo, int indent, int tab)
       {
           uint i;
           int oneIndent;
           int nextIndent;
           int startIndent;
           String CR = "";

           //determine how much to indent this description
           oneIndent = 0;
           startIndent = 0;
           if (indent > -1)
           {
               oneIndent = tab;
               startIndent = indent;
               CR = "\r\n";
           }
           String sIndent = new String(' ', startIndent);   //begin at this level
           nextIndent = indent + oneIndent;

           StringBuilder xml = new StringBuilder("");
           if (attrInfo.baseType() != TTypedValue.TBaseType.ITYPE_DEF)
               xml.Append(" kind=\"" + attrInfo.typeName() + "\"");
           if (attrInfo.isArray())
               xml.Append(" array=\"T\"");
           if ((attrInfo.units().Length > 0) && (attrInfo.units()[0] != '-'))
               xml.Append(" unit=\"" + attrInfo.units() + "\"");

           xml.Append(">" + CR);

           if (attrInfo.isScalar()) // Scalars - use a <val> element
           {
               xml.Append(sIndent + "<val>" + scalarString(attrInfo) + "</val>" + CR);
           }
           else
           {
               //now nest into the fields/elements
               for (i = 1; i <= attrInfo.count(); i++)
               {
                   if (attrInfo.isArray() && (attrInfo.baseType() != TTypedValue.TBaseType.ITYPE_DEF))
                   {
                       xml.Append(new String(' ', oneIndent) + "<val>" + scalarString(attrInfo.item(i)) + "</val>" + CR); // Scalar array, indented format
                   }
                   else if (attrInfo.isArray())                                          // All other arrays
                       xml.Append(sIndent + "<element"
                                   + writeFieldInfo(attrInfo.item(i), nextIndent, oneIndent)
                                   + sIndent + "</element>" + CR);
                   else if (attrInfo.isRecord())                                         // Records
                       xml.Append(sIndent + "<field name=\"" + attrInfo.item(i).Name + "\""
                                   + writeFieldInfo(attrInfo.item(i), nextIndent, oneIndent)
                                   + sIndent + "</field>" + CR);
               }
           }

           return xml.ToString();
       }
Пример #3
0
        //============================================================================
        /// <summary>
        /// Tests for identity of two TTypedValue objects.
        /// </summary>
        /// <param name="otherValue">Typed value to test against this one.</param>
        /// <returns>True if it matches in type, size, and structure.</returns>
        // N.Herrmann Apr 2002
        //============================================================================
        public Boolean equals(TTypedValue otherValue)
        {
            uint i;
            Boolean bEqual = false;

            if ((otherValue != null) &&
               (FBaseType == otherValue.baseType()) &&
               (FIsArray == otherValue.isArray()) &&
               (FIsRecord == otherValue.isRecord()) &&
               (count() == otherValue.count()) &&
               (FDataSize == otherValue.sizeBytes()))
                bEqual = true;

            if (bEqual)
            {
                if (FIsScalar)
                    bEqual = bEqual && (asStr() == otherValue.asStr());    //str comparison of the scalar (needs refinement)
            }
            else
            {
                for (i = 1; i <= count(); i++)
                    bEqual = bEqual && item(i).equals(otherValue.item(i));
            }
            return bEqual;
        }