aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
authorJonathan Freedman2010-12-05 11:49:15 -0800
committerJonathan Freedman2010-12-05 11:49:15 -0800
commit45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a (patch)
tree0351fb2c756a46d522fe41798c3969e020a3258d /OpenSim/Framework/Util.cs
parentMerge branch 'master-core' into mantis5110 (diff)
parentMerge branch 'master' of /var/git/opensim/ (diff)
downloadopensim-SC_OLD-45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a.zip
opensim-SC_OLD-45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a.tar.gz
opensim-SC_OLD-45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a.tar.bz2
opensim-SC_OLD-45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a.tar.xz
Merge branch 'master-core' into mantis5110
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs81
1 files changed, 81 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index e8f8e01..8d1671a 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1558,5 +1558,86 @@ namespace OpenSim.Framework
1558 return string.Empty; 1558 return string.Empty;
1559 } 1559 }
1560 1560
1561 #region Xml Serialization Utilities
1562 public static bool ReadBoolean(XmlTextReader reader)
1563 {
1564 reader.ReadStartElement();
1565 bool result = Boolean.Parse(reader.ReadContentAsString().ToLower());
1566 reader.ReadEndElement();
1567
1568 return result;
1569 }
1570
1571 public static UUID ReadUUID(XmlTextReader reader, string name)
1572 {
1573 UUID id;
1574 string idStr;
1575
1576 reader.ReadStartElement(name);
1577
1578 if (reader.Name == "Guid")
1579 idStr = reader.ReadElementString("Guid");
1580 else if (reader.Name == "UUID")
1581 idStr = reader.ReadElementString("UUID");
1582 else // no leading tag
1583 idStr = reader.ReadContentAsString();
1584 UUID.TryParse(idStr, out id);
1585 reader.ReadEndElement();
1586
1587 return id;
1588 }
1589
1590 public static Vector3 ReadVector(XmlTextReader reader, string name)
1591 {
1592 Vector3 vec;
1593
1594 reader.ReadStartElement(name);
1595 vec.X = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // X or x
1596 vec.Y = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // Y or y
1597 vec.Z = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // Z or z
1598 reader.ReadEndElement();
1599
1600 return vec;
1601 }
1602
1603 public static Quaternion ReadQuaternion(XmlTextReader reader, string name)
1604 {
1605 Quaternion quat = new Quaternion();
1606
1607 reader.ReadStartElement(name);
1608 while (reader.NodeType != XmlNodeType.EndElement)
1609 {
1610 switch (reader.Name.ToLower())
1611 {
1612 case "x":
1613 quat.X = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1614 break;
1615 case "y":
1616 quat.Y = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1617 break;
1618 case "z":
1619 quat.Z = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1620 break;
1621 case "w":
1622 quat.W = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1623 break;
1624 }
1625 }
1626
1627 reader.ReadEndElement();
1628
1629 return quat;
1630 }
1631
1632 public static T ReadEnum<T>(XmlTextReader reader, string name)
1633 {
1634 string value = reader.ReadElementContentAsString(name, String.Empty);
1635 // !!!!! to deal with flags without commas
1636 if (value.Contains(" ") && !value.Contains(","))
1637 value = value.Replace(" ", ", ");
1638
1639 return (T)Enum.Parse(typeof(T), value); ;
1640 }
1641 #endregion
1561 } 1642 }
1562} 1643}