public static bool StreamProtoEnum <TDoc, TCursor>(this IO.TagElementStream <TDoc, TCursor, string> s , string xmlName, ref int dbid , Collections.IProtoEnum protoEnum , bool isOptional = true, IO.TagElementNodeType xmlSource = XML.XmlUtil.kSourceElement , int isOptionalDefaultValue = TypeExtensions.kNone) where TDoc : class where TCursor : class { Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName)); Contract.Requires(protoEnum != null); string id_name = null; bool was_streamed = true; bool to_lower = false; if (s.IsReading) { if (isOptional) { was_streamed = s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true); } else { s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true); } if (was_streamed) { dbid = protoEnum.TryGetMemberId(id_name); Contract.Assert(dbid.IsNotNone(), id_name); } //else // dbid = isOptionalDefaultValue; } else if (s.IsWriting) { if (isOptional && isOptionalDefaultValue.IsNotNone() && isOptionalDefaultValue == dbid) { was_streamed = false; return(was_streamed); } id_name = protoEnum.TryGetMemberName(dbid); if (id_name.IsNullOrEmpty()) { Contract.Assert(!id_name.IsNullOrEmpty(), dbid.ToString()); } if (isOptional) { s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true); } else { s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true); } } return(was_streamed); }
public static bool StreamBVector <TDoc, TCursor>(this IO.TagElementStream <TDoc, TCursor, string> s , string xmlName, ref BVector vector , bool isOptional = true, IO.TagElementNodeType xmlSource = XML.XmlUtil.kSourceElement) where TDoc : class where TCursor : class { Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName)); string string_value = null; bool was_streamed = true; const bool to_lower = false; if (s.IsReading) { if (isOptional) { was_streamed = s.StreamStringOpt(xmlName, ref string_value, to_lower, xmlSource); } else { s.StreamString(xmlName, ref string_value, to_lower, xmlSource); } if (was_streamed) { var parse_result = PhxUtil.ParseBVectorString(string_value); if (!parse_result.HasValue) { s.ThrowReadException(new System.IO.InvalidDataException(string.Format( "Failed to parse value (hint: {0}) as vector: {1}", xmlSource.RequiresName() ? xmlName : "ElementText", string_value))); } vector = parse_result.Value; } } else if (s.IsWriting) { if (isOptional && PhxPredicates.IsZero(vector)) { was_streamed = false; return(was_streamed); } string_value = vector.ToBVectorString(); if (isOptional) { s.StreamStringOpt(xmlName, ref string_value, to_lower, xmlSource); } else { s.StreamString(xmlName, ref string_value, to_lower, xmlSource); } } return(was_streamed); }
public static bool StreamIntegerColor <TDoc, TCursor>(this IO.TagElementStream <TDoc, TCursor, string> s , string xmlName, ref System.Drawing.Color color , byte defaultAlpha = 0xFF , bool isOptional = true, IO.TagElementNodeType xmlSource = XML.XmlUtil.kSourceElement) where TDoc : class where TCursor : class { Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName)); string string_value = null; bool was_streamed = true; const bool to_lower = false; if (s.IsReading) { if (isOptional) { was_streamed = s.StreamStringOpt(xmlName, ref string_value, to_lower, xmlSource); } else { s.StreamString(xmlName, ref string_value, to_lower, xmlSource); } if (was_streamed) { if (!PhxUtil.TokenizeIntegerColor(string_value, defaultAlpha, ref color)) { s.ThrowReadException(new System.IO.InvalidDataException(string.Format( "Failed to parse value (hint: {0}) as color: {1}", xmlSource.RequiresName() ? xmlName : "ElementText", string_value))); } } } else if (s.IsWriting) { if (isOptional && PhxPredicates.IsZero(color)) { was_streamed = false; return(was_streamed); } string_value = color.ToIntegerColorString(defaultAlpha); if (isOptional) { s.StreamStringOpt(xmlName, ref string_value, to_lower, xmlSource); } else { s.StreamString(xmlName, ref string_value, to_lower, xmlSource); } } return(was_streamed); }
internal bool StreamID <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, string xmlName, ref int dbid, TacticDataObjectKind kind, bool isOptional = true, IO.TagElementNodeType xmlSource = XML.XmlUtil.kSourceElement) where TDoc : class where TCursor : class { Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName)); Contract.Requires(kind != TacticDataObjectKind.None); string id_name = null; bool was_streamed = true; bool to_lower = false; if (s.IsReading) { if (isOptional) { was_streamed = s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true); } else { s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true); } if (was_streamed) { IProtoDataObjectDatabaseProvider provider = this; dbid = provider.GetId((int)kind, id_name); Contract.Assert(dbid.IsNotNone()); } else { dbid = TypeExtensions.kNone; } } else if (s.IsWriting && dbid.IsNotNone()) { IProtoDataObjectDatabaseProvider provider = this; id_name = provider.GetName((int)kind, dbid); Contract.Assert(!string.IsNullOrEmpty(id_name)); if (isOptional) { s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true); } else { s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true); } } return(was_streamed); }
public void StreamIcon <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, XML.BXmlSerializerInterface xs) where TDoc : class where TCursor : class { // #NOTE engine parses this as "IconType", but its parser ignores case s.StreamAttributeEnum("iconType", ref Icon_Type); // #NOTE engine parses this as "IconType", but its parser ignores case s.StreamString("iconName", ref Icon_Name, false); }
public bool StreamDBID <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, string xmlName, ref int dbid, Phx.DatabaseObjectKind kind, bool isOptional = true, IO.TagElementNodeType xmlSource = XmlUtil.kSourceElement) where TDoc : class where TCursor : class { Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName)); string id_name = null; bool was_streamed = true; bool to_lower = ToLowerName(kind); if (s.IsReading) { if (isOptional) { was_streamed = s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true); } else { s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true); } if (was_streamed) { dbid = Database.GetId(kind, id_name); Contract.Assert(dbid.IsNotNone()); if (PhxUtil.IsUndefinedReferenceHandle(dbid)) { TraceUndefinedHandle(s, id_name, xmlName, dbid, kind.ToString()); } } else { dbid = TypeExtensions.kNone; } } else if (s.IsWriting) { if (dbid.IsNone()) { was_streamed = false; return(was_streamed); } id_name = Database.GetName(kind, dbid); Contract.Assert(!string.IsNullOrEmpty(id_name)); if (isOptional) { s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true); } else { s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true); } } return(was_streamed); }