00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 using System;
00040
00041 namespace XMLStorage {
00042
00043
00044
00045
00046 public class XMLInt
00047 {
00048 public XMLInt(int value)
00049 {
00050 _value = value;
00051 }
00052
00053 public XMLInt(string value)
00054 {
00055 init(value, 0);
00056 }
00057
00058 public XMLInt(string value, int def)
00059 {
00060 init(value, def);
00061 }
00062
00063 public XMLInt(AbstractXMLNode node, string attrName)
00064 {
00065 init(node, attrName, 0);
00066 }
00067
00068 public XMLInt(XMLPos pos, string attrName)
00069 {
00070 init(pos.cur(), attrName, 0);
00071 }
00072
00073 public XMLInt(XMLPos pos, string attrName, int def)
00074 {
00075 init(pos.cur(), attrName, def);
00076 }
00077
00078 public XMLInt(XMLStreamReader reader, string attrName)
00079 {
00080 init(reader.getNode(), attrName, 0);
00081 }
00082
00083 public XMLInt(XMLStreamReader reader, string attrName, int def)
00084 {
00085 init(reader.getNode(), attrName, def);
00086 }
00087
00088 public XMLInt(AbstractXMLNode node, string attrName, int def)
00089 {
00090 init(node, attrName, def);
00091 }
00092
00093
00094 private void init(AbstractXMLNode node, string attrName, int def)
00095 {
00096 init(node.get(attrName), def);
00097 }
00098
00099 private void init(string value, int def)
00100 {
00101 if (string.IsNullOrEmpty(value) || !Int32.TryParse(value, out _value))
00102 _value = def;
00103 }
00104
00105
00106 public int intValue()
00107 {
00108 return _value;
00109 }
00110
00111 public override string ToString()
00112 {
00113 return _value.ToString();
00114 }
00115
00116 protected int _value;
00117 }
00118
00119
00120
00121
00122 public class XMLIntRef
00123 {
00124 public XMLIntRef(XMLNode node, string attrName)
00125 {
00126 init(node, attrName, 0);
00127 }
00128
00129 public XMLIntRef(XMLPos pos, string attrName)
00130 {
00131 init(pos.cur(), attrName, 0);
00132 }
00133
00134 public XMLIntRef(XMLNode node, string attrName, int def)
00135 {
00136 init(node, attrName, def);
00137 }
00138
00139 public XMLIntRef(XMLPos pos, string attrName, int def)
00140 {
00141 init(pos.cur(), attrName, def);
00142 }
00143
00144 private void init(XMLNode node, string attrName, int def)
00145 {
00146 _node = node;
00147 _attrName = attrName;
00148
00149 if (node != null)
00150 if (node.get(attrName).Length == 0)
00151 assign(def);
00152 }
00153
00154 public int intValue()
00155 {
00156 int value;
00157
00158 if (_node!=null && Int32.TryParse(_node.get(_attrName), out value))
00159 return value;
00160 else
00161 return 0;
00162 }
00163
00164 public void assign(int value)
00165 {
00166 if (_node != null)
00167 _node.put(_attrName, value.ToString());
00168 }
00169
00170 protected XMLNode _node;
00171 protected string _attrName;
00172 }
00173
00174 }