//============================================================================ /// <summary> /// Adds a scalar to an array or record. /// </summary> /// <param name="sName">Name of the scalar.</param> /// <param name="aType">The basic type for this scalar.</param> /// <returns>A ref to the newly created scalar.</returns> //============================================================================ public override TTypedValue addScalar(String sName, TBaseType aType) { TInitValue newScalar; TTypedValue result = null; if (FIsArray || FIsRecord) { newScalar = new TInitValue(sName, aType); if (isArray()) { // Arrays pass their default value and valid range down to their elements if (newScalar.getDefault() != null) { newScalar.getDefault().copyFrom(FDefault); } if (newScalar.getMin() != null) { newScalar.getMin().copyFrom(FMin); } if (newScalar.getMax() != null) { newScalar.getMax().copyFrom(FMax); } } addMember(newScalar); result = newScalar; } return(result); }
//============================================================================ /// <summary> /// Formats the xml text for the 'field' or 'element' description of the typed /// value stored as a TPropertyInfo or TDriverInfo. /// </summary> /// <param name="attrInfo">The TypedValue attribute.</param> /// <param name="indent">Indentation in chars.</param> /// <param name="tab">Number of spaces in each tab</param> /// <returns>XML text for the field</returns> //============================================================================ protected override String writeFieldInfo(TTypedValue attrInfo, int indent, int tab) { uint i; uint iFirst; 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"; } nextIndent = indent; String sIndent = new String(' ', startIndent + oneIndent); StringBuilder xml = new StringBuilder(""); 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 a scalar or array of scalars then write the defval|minval|maxval elements if (attrInfo.isScalar() || (attrInfo.isArray() && attrInfo.baseType() == TTypedValue.TBaseType.ITYPE_DEF)) { TInitValue initInfo = new TInitValue(attrInfo); if (initInfo != null) { if (initInfo.getDefault() != null) { xml.Append(sIndent + "<defval>" + initInfo.getDefault().asEscapedString() + "</defval>" + CR); } if (initInfo.getMin() != null) { xml.Append(sIndent + "<minval>" + initInfo.getMin().asEscapedString() + "</minval>" + CR); } if (initInfo.getMax() != null) { xml.Append(sIndent + "<maxval>" + initInfo.getMax().asEscapedString() + "</maxval>" + CR); } } } //now nest into the fields/elements sIndent = new String(' ', startIndent); if (!attrInfo.isScalar()) { // Special handling for non-scalar arrays of length 0, to ensure type definition is output iFirst = (uint)((attrInfo.isArray() && attrInfo.count() == 0) ? 0 : 1); for (i = iFirst; i <= attrInfo.count(); i++) { //for each child field if (attrInfo.isArray() && attrInfo.baseType() == TTypedValue.TBaseType.ITYPE_DEF) { xml.Append(sIndent + "<element"); xml.Append(writeFieldInfo(attrInfo.item(i), nextIndent, oneIndent)); xml.Append(sIndent + "</element>" + CR); } else if (attrInfo.isRecord()) { xml.Append(sIndent + "<field name=\"" + attrInfo.item(i).Name + "\""); xml.Append(writeFieldInfo(attrInfo.item(i), nextIndent, oneIndent)); xml.Append(sIndent + "</field>" + CR); } } } return(xml.ToString()); }