- Timestamp:
- 04/23/09 14:22:29 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleArray2XmlFormatters.cs
r1612 r1625 2 2 using HeuristicLab.Persistence.Core; 3 3 using System.Globalization; 4 using HeuristicLab.Persistence.Default.Decomposers.Storable; 4 5 5 6 namespace HeuristicLab.Persistence.Default.Xml.Compact { -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/IntArray2XmlFormatters.cs
r1612 r1625 1 1 using System; 2 2 using HeuristicLab.Persistence.Core; 3 using HeuristicLab.Persistence.Default.Decomposers.Storable; 3 4 4 5 namespace HeuristicLab.Persistence.Default.Xml.Compact { -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberArray2XmlFormatterBase.cs
r1612 r1625 3 3 using HeuristicLab.Persistence.Interfaces; 4 4 using System; 5 using HeuristicLab.Persistence.Core; 5 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Compact { … … 46 47 47 48 public override T Parse(XmlString x) { 48 IEnumerator values = 49 x.Data.Split(new[] { Separator }, 50 StringSplitOptions.RemoveEmptyEntries).GetEnumerator(); 51 values.MoveNext(); 52 int rank = int.Parse((string)values.Current); 53 int[] lengths = new int[rank]; 54 for (int i = 0; i < rank; i++) { 49 try { 50 IEnumerator values = 51 x.Data.Split(new[] { Separator }, 52 StringSplitOptions.RemoveEmptyEntries).GetEnumerator(); 55 53 values.MoveNext(); 56 lengths[i] = int.Parse((string)values.Current); 57 } 58 int[] lowerBounds = new int[rank]; 59 for (int i = 0; i < rank; i++) { 60 values.MoveNext(); 61 lowerBounds[i] = int.Parse((string)values.Current); 62 } 63 Array a = Array.CreateInstance(this.SourceType.GetElementType(), lengths, lowerBounds); 64 int[] positions = new int[rank]; 65 while (values.MoveNext()) { 66 a.SetValue(ParseValue((string)values.Current), positions); 67 positions[0] += 1; 68 for (int i = 0; i < rank - 1; i++) { 69 if (positions[i] >= lengths[i]) { 70 positions[i] = 0; 71 positions[i + 1] += 1; 72 } else { 73 break; 54 int rank = int.Parse((string)values.Current); 55 int[] lengths = new int[rank]; 56 for (int i = 0; i < rank; i++) { 57 values.MoveNext(); 58 lengths[i] = int.Parse((string)values.Current); 59 } 60 int[] lowerBounds = new int[rank]; 61 for (int i = 0; i < rank; i++) { 62 values.MoveNext(); 63 lowerBounds[i] = int.Parse((string)values.Current); 64 } 65 Array a = Array.CreateInstance(this.SourceType.GetElementType(), lengths, lowerBounds); 66 int[] positions = (int[])lowerBounds.Clone(); 67 while (values.MoveNext()) { 68 a.SetValue(ParseValue((string)values.Current), positions); 69 positions[0] += 1; 70 for (int i = 0; i < rank - 1; i++) { 71 if (positions[i] >= lengths[i]) { 72 positions[i] = 0; 73 positions[i + 1] += 1; 74 } else { 75 break; 76 } 74 77 } 75 78 } 76 } 77 return (T)(object)a; 79 if (positions[rank - 1] != lowerBounds[rank - 1] + lengths[rank - 1]) 80 throw new PersistenceException("Insufficient number of elements while trying to fill number array."); 81 return (T)(object)a; 82 } catch (InvalidOperationException e) { 83 throw new PersistenceException("Insufficient information to rebuild number array.", e); 84 } catch (InvalidCastException e) { 85 throw new PersistenceException("Invalid element data or meta data to reconstruct number array.", e); 86 } catch (OverflowException e) { 87 throw new PersistenceException("Overflow during element parsing while trying to reconstruct number array.", e); 88 } 78 89 } 79 90 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberEnumeration2XmlFormatterBase.cs
r1566 r1625 3 3 using HeuristicLab.Persistence.Interfaces; 4 4 using System; 5 using HeuristicLab.Persistence.Core; 5 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Compact { … … 24 25 25 26 public override T Parse(XmlString x) { 26 IEnumerable enumeration = Instantiate(); 27 string[] values = x.Data.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries); 28 foreach (var value in values) { 29 Add(enumeration, ParseValue(value)); 30 } 31 return (T)enumeration; 27 try { 28 IEnumerable enumeration = Instantiate(); 29 string[] values = x.Data.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries); 30 foreach (var value in values) { 31 Add(enumeration, ParseValue(value)); 32 } 33 return (T)enumeration; 34 } catch (InvalidCastException e) { 35 throw new PersistenceException("Invalid element data during reconstruction of number enumerable.", e); 36 } catch (OverflowException e) { 37 throw new PersistenceException("Overflow during element parsing while trying to reconstruct number enumerable.", e); 38 } 32 39 } 33 40 }
Note: See TracChangeset
for help on using the changeset viewer.