Beispiel #1
0
        public static bool TryParse(string s, ElementParserDelegate elementParser, out DicomArray <T> result)
        {
            Platform.CheckForNullReference(elementParser, "elementParser");

            if (s != null)
            {
                if (s.Length == 0)
                {
                    result = new DicomArray <T>();
                    return(true);
                }

                int countParserAttempts = 0;
                int countParserFailures = 0;

                List <T?> list = new List <T?>();
                foreach (string elementString in s.Split(new char[] { '\\' }, StringSplitOptions.None))
                {
                    if (string.IsNullOrEmpty(elementString))
                    {
                        list.Add(null);
                    }
                    else
                    {
                        countParserAttempts++;

                        T element;
                        if (elementParser(elementString, out element))
                        {
                            list.Add(element);
                        }
                        else
                        {
                            list.Add(null);
                            countParserFailures++;
                        }
                    }
                }

                // the overall parse succeeds if every non-empty element parsed succeeded (or if everything was empty and nothing was parsed)
                if (countParserAttempts == 0 || countParserAttempts != countParserFailures)
                {
                    result = new DicomArray <T>(list);
                    return(true);
                }
            }
            result = null;
            return(false);
        }
Beispiel #2
0
        public static int Compare(DicomArray <T> x, DicomArray <T> y, Comparison <T?> comparer)
        {
            if (comparer == null)
            {
                return(0);
            }
            if (x == null && y == null)
            {
                return(0);
            }
            if (x == null)
            {
                return(-1);
            }
            if (y == null)
            {
                return(1);
            }

            IEnumerator <T?> xnumerator = x._values.GetEnumerator();
            IEnumerator <T?> ynumerator = y._values.GetEnumerator();

            int result = 0;

            do
            {
                bool xHasMore = xnumerator.MoveNext();
                bool yHasMore = ynumerator.MoveNext();

                if (xHasMore ^ yHasMore)
                {
                    result = xHasMore ? 1 : -1;
                }
                else if (xHasMore)                 // note that yHasMore == xHasMore
                {
                    result = comparer(xnumerator.Current, ynumerator.Current);
                }
                else
                {
                    result = 0;
                    break;
                }
            } while (result == 0);

            return(result);
        }
        public override bool Parse(string input, out DicomArray <DateTime> output)
        {
            if (DicomArray <DateTime> .TryParse(input, DateTimeTryParseExact, out output))
            {
                return(true);
            }

            if (DicomArray <DateTime> .TryParse(input, DateTime.TryParse, out output))
            {
                return(true);
            }

            switch (base.VR)
            {
            case "DA":
                if (DicomArray <DateTime> .TryParse(input, DateParser.Parse, out output))
                {
                    return(true);
                }
                break;

            case "TM":
                if (DicomArray <DateTime> .TryParse(input, TimeParser.Parse, out output))
                {
                    return(true);
                }
                break;

            case "DT":
            default:
                if (DicomArray <DateTime> .TryParse(input, DateTimeParser.Parse, out output))
                {
                    return(true);
                }
                break;
            }
            return(false);
        }
Beispiel #4
0
 public override bool Parse(string input, out DicomArray <uint> output)
 {
     return(DicomArray <uint> .TryParse(input, TagTryParse, out output));
 }
 public int CompareNumerically(IStudyItem x, IStudyItem y)
 {
     return(DicomArray <int> .Compare(this.GetTypedValue(x), this.GetTypedValue(y)));
 }
 public override bool Parse(string input, out DicomArray <DicomAge> output)
 {
     return(DicomArray <DicomAge> .TryParse(input, DicomAge.TryParse, out output));
 }
 public int CompareTemporally(IStudyItem x, IStudyItem y)
 {
     return(DicomArray <DateTime> .Compare(this.GetTypedValue(x), this.GetTypedValue(y)));
 }
Beispiel #8
0
 public bool Equals(DicomArray <T> other)
 {
     return(this.CompareTo(other) == 0);
 }
Beispiel #9
0
 public int CompareTo(DicomArray <T> other)
 {
     return(Compare(this, other, CompareElement));
 }
Beispiel #10
0
 public static int Compare(DicomArray <T> x, DicomArray <T> y)
 {
     return(Compare(x, y, CompareElement));
 }