/// <summary>toString() outputs the path (from segmentID onward) in the ZYX[a]-b[c]-d-e /// style (TODO: give it a name), suitable for a key in a map of /// message datum paths to values. /// </summary> /// <summary>Integer values are converted to strings directly (1 => "1") so when you /// constructed this you should have started counting from 1 for everything but /// the "repeat" fields, if you truly want the ZYX[a]-b[c]-d-e style. /// If toString() is called when this has a size in [1, 6) (=> missing numeric /// elments), then we act as though the elements in [size(), 6) are 0 or 1 as /// appropriate for each element. We don't provide a default for the element 0 /// (the String element): will throw an IndexOutOfBoundsException if (size() == /// 1). /// eg. a (new DatumPath()).add(new String("ZYX")).add(2).add(6).toString() /// would yield "ZYX[2]-6[0]-1-1" /// </summary> public override System.String ToString() { System.Text.StringBuilder strbuf = new System.Text.StringBuilder(15); if (m_path.Count >= 1) { NuGenDatumPath extendedCopy = (NuGenDatumPath)this.Clone(); extendedCopy.setSize(s_maxSize); for (int i = 0; i < extendedCopy.size(); ++i) { if (i == 0) { strbuf.Append("" + ((System.String)extendedCopy.get_Renamed(0))); } else if ((i == 1) || (i == 3)) { strbuf.Append("[" + ((System.Int32)extendedCopy.get_Renamed(i)) + "]"); } else if ((i == 2) || (i == 4) || (i == 5)) { strbuf.Append("-" + (((System.Int32)extendedCopy.get_Renamed(i)))); } } } else { throw new System.IndexOutOfRangeException(); } return("" + strbuf); }
/* Compare the numeric parts of "this" and "other". string-style, start from * the left: if this[1] < other[1], then return true, if this[1] > other[1] then * return false, else repeat with [2] ... if we compare all elements, then return * false (they're the same.) * * What are actually compared are copies of this and other that have been grown * to s_maxSize (default values in effect), so they'll have the same size. * * This is just a little thing that gets used in the class XML. Look there for * a justification of it's existence. * * ex. [1, 1, 1, 1] < [1, 1, 1, 2] * [1, 2, 1, 1] < [1, 2, 1, 2] * [1, 1, 5, 5] < [1, 2] * [1, 1] < [1, 1, 5, 5] */ public virtual bool numbersLessThan(NuGenDatumPath other) { NuGenDatumPath extendedCopyThis = new NuGenDatumPath(this); extendedCopyThis.setSize(s_maxSize); NuGenDatumPath extendedCopyOther = new NuGenDatumPath(other); extendedCopyOther.setSize(s_maxSize); bool lessThan = false; for (int i = 1; !lessThan && (i < s_maxSize); ++i) { int this_i = ((System.Int32)extendedCopyThis.get_Renamed(i)); int other_i = ((System.Int32)extendedCopyOther.get_Renamed(i)); lessThan |= (this_i < other_i); } return(lessThan); }
/* Compare the numeric parts of "this" and "other". string-style, start from the left: if this[1] < other[1], then return true, if this[1] > other[1] then return false, else repeat with [2] ... if we compare all elements, then return false (they're the same.) What are actually compared are copies of this and other that have been grown to s_maxSize (default values in effect), so they'll have the same size. This is just a little thing that gets used in the class XML. Look there for a justification of it's existence. ex. [1, 1, 1, 1] < [1, 1, 1, 2] [1, 2, 1, 1] < [1, 2, 1, 2] [1, 1, 5, 5] < [1, 2] [1, 1] < [1, 1, 5, 5] */ public virtual bool numbersLessThan(NuGenDatumPath other) { NuGenDatumPath extendedCopyThis = new NuGenDatumPath(this); extendedCopyThis.setSize(s_maxSize); NuGenDatumPath extendedCopyOther = new NuGenDatumPath(other); extendedCopyOther.setSize(s_maxSize); bool lessThan = false; for (int i = 1; !lessThan && (i < s_maxSize); ++i) { int this_i = ((System.Int32) extendedCopyThis.get_Renamed(i)); int other_i = ((System.Int32) extendedCopyOther.get_Renamed(i)); lessThan |= (this_i < other_i); } return lessThan; }
public override void startElement(System.String uri, System.String localName, System.String qName, SaxAttributesSupport attributes) { //System.err.println("startelem: " + qName + " curpathsize; " + //m_curPath.size()); bool ok = false; if (m_startedDocument) { // A single unit of text data will be within a single element, // -- none of it will be in sub-elements and there will be no // sub-elements fragmenting the data text. // Right now we're entering a new element: this means that anything // in m_chars will be whitespace (likely), or text left over from, // say, the last field, or text that was somewhere it shouldn't have been. // (ex. "<ZYX.9> shouldn't be here <PT.1> P </PT.1> </ZYX.9>" m_chars.Remove(0, m_chars.Length - 0); if (m_depthWithinUselessElement >= 0) { ++m_depthWithinUselessElement; } else { int oldCurPathSize = m_curPath.size(); if (tryToGrowDocLocationFromElementName(m_msgID, m_curPath, m_segmentId2nextRepIdx, m_lastDumpedPath, qName)) { if (m_curPath.size() > oldCurPathSize) { // assert (m_depthWithinUselessElement == -1) // m_curPath // should not have grown if we're within a useless element. if (m_depthWithinUsefulElement == -1) { // this new element could match one of the DatumPaths in // m_msgMask -- if that's the case, we've just entered a // useful element. // TODO: functional stylee (a la C++'s std::accumulate) ? bool curPathStartsWithAMaskElem = false; for (System.Collections.IEnumerator maskIt = m_msgMask.GetEnumerator(); !curPathStartsWithAMaskElem && maskIt.MoveNext();) { curPathStartsWithAMaskElem = m_curPath.startsWith((NuGenDatumPath)maskIt.Current); } if (curPathStartsWithAMaskElem) { m_depthWithinUsefulElement = 0; } else { // so this element we're entering is not specified by m_msgMask // to be useful -- but might it contains elements that // are? bool aMaskElemStartsWithCurPath = false; for (System.Collections.IEnumerator maskIt = m_msgMask.GetEnumerator(); !aMaskElemStartsWithCurPath && maskIt.MoveNext();) { aMaskElemStartsWithCurPath = ((NuGenDatumPath)maskIt.Current).startsWith(m_curPath); } if (!aMaskElemStartsWithCurPath) { // ... nope! useless. m_depthWithinUselessElement = 0; m_curPath.setSize(oldCurPathSize); } // else => ok, carry on, m_depthWithinUse{less,ful}Element // still both -1. } } // else => already within a useful element, don't need to compare // against m_msgMask. } } else { m_depthWithinUselessElement = 0; } } ok = true; } if (!ok) { clear(); throw new StopParsingException(); } }