Go to the documentation of this file.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 namespace XMLStorage
00040 {
00041
00042
00043
00044
00045 public class XMLBool
00046 {
00047 public XMLBool(bool value)
00048 {
00049 _value = value;
00050 }
00051
00052 public XMLBool(string value)
00053 {
00054 init(value, false);
00055 }
00056
00057 public XMLBool(string value, bool def)
00058 {
00059 init(value, def);
00060 }
00061
00062 private void init(string value, bool def)
00063 {
00064 if (string.IsNullOrEmpty(value) || !bool.TryParse(value, out _value))
00065 _value = def;
00066 }
00067
00068
00069 public XMLBool(AbstractXMLNode node, string attrName)
00070 {
00071 init(node, attrName, false);
00072 }
00073
00074 public XMLBool(XMLPos pos, string attrName)
00075 {
00076 init(pos.cur(), attrName, false);
00077 }
00078
00079 public XMLBool(XMLPos pos, string attrName, bool def)
00080 {
00081 init(pos.cur(), attrName, def);
00082 }
00083
00084 public XMLBool(XMLStreamReader reader, string attrName)
00085 {
00086 init(reader.getNode(), attrName, false);
00087 }
00088
00089 public XMLBool(XMLStreamReader reader, string attrName, bool def)
00090 {
00091 init(reader.getNode(), attrName, def);
00092 }
00093
00094 public XMLBool(AbstractXMLNode node, string attrName, bool def)
00095 {
00096 init(node, attrName, def);
00097 }
00098
00099 private void init(AbstractXMLNode node, string attrName, bool def)
00100 {
00101 string value = node.get(attrName);
00102
00103 if (value.Length==0 || !bool.TryParse(value, out _value))
00104 _value = def;
00105 }
00106
00107
00108 public bool boolValue()
00109 {
00110 return _value;
00111 }
00112
00113 public override string ToString()
00114 {
00115 return _value.ToString();
00116 }
00117
00118 protected bool _value;
00119 }
00120
00121
00122
00123
00124
00125 public class XMLBoolRef
00126 {
00127 public XMLBoolRef(XMLNode node, string attrName)
00128 {
00129 init(node, attrName, false);
00130 }
00131
00132 public XMLBoolRef(XMLNode node, string attrName, bool def)
00133 {
00134 init(node, attrName, def);
00135 }
00136
00137 private void init(XMLNode node, string attrName, bool def)
00138 {
00139 _node = node;
00140 _attrName = attrName;
00141
00142 if (node != null)
00143 if (node.get(attrName).Length == 0)
00144 assign(def);
00145 }
00146
00147
00148
00149
00150 public bool boolValue()
00151 {
00152 bool value;
00153
00154 if (_node != null && bool.TryParse(_node.get(_attrName), out value))
00155 return value;
00156 else
00157 return false;
00158 }
00159
00160
00161
00162
00163
00164 public void assign(bool 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 }