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 int TryGetId(this Collections.IProtoEnum dbi, string name) { if (dbi == null) { return(TypeExtensions.kNone); } return(dbi.TryGetMemberId(name)); }
protected BDatabaseBase(Engine.PhxEngine engine, Collections.IProtoEnum gameObjectTypes) { Engine = engine; ObjectDatabase = new ProtoDataObjectDatabase(this, typeof(DatabaseObjectKind)); ObjectTypes = new Collections.BTypeNamesWithCode(gameObjectTypes); InitializeDatabaseInterfaces(); }
void ReadNodes <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var xs = s.GetSerializerInterface(); Collections.IProtoEnum penum = Bits.InitializeFromEnum(xs.Database); if (Params.ElementItselfMeansTrue) { var getDefault = Bits.Params.kGetMemberDefaultValue; foreach (var e in s.Elements) { var element_name = s.GetElementName(e); int id = penum.TryGetMemberId(element_name); if (id.IsNone()) { continue; } bool flag = true; s.StreamElementOpt(element_name, ref flag); if (getDefault != null && flag != getDefault(id)) { // do nothing, allow the Set call below } else if (!flag) { continue; } Bits.Set(id, flag); } } else { foreach (var n in s.ElementsByName(Params.ElementName)) { using (s.EnterCursorBookmark(n)) { string name = null; Params.StreamDataName(s, ref name); int id = penum.GetMemberId(name); Bits.Set(id); } } } Bits.OptimizeStorage(); }
protected BDatabaseBase(PhxEngine engine, Collections.IProtoEnum game_object_types) { Engine = engine; StringTable = new Dictionary <int, string>(); GameData = new BGameData(); DamageTypes = new Collections.BListAutoId <BDamageType>(); WeaponTypes = new Collections.BListAutoId <BWeaponType>(); UserClasses = new Collections.BListAutoId <BUserClass>(); ObjectTypes = new Collections.BTypeNamesWithCode(game_object_types); Abilities = new Collections.BListAutoId <BAbility>(); Objects = new Collections.BListAutoId <BProtoObject>(); Squads = new Collections.BListAutoId <BProtoSquad>(); Powers = new Collections.BListAutoId <BProtoPower>(); Techs = new Collections.BListAutoId <BProtoTech>(); Civs = new Collections.BListAutoId <BCiv>(); Leaders = new Collections.BListAutoId <BLeader>(); InitializeDatabaseInterfaces(); }
void WriteXmlNodes(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs) { if (Bits.EnabledCount == 0) { return; } Collections.IProtoEnum penum = GetProtoEnum(xs.Database); for (int x = 0; x < Bits.Count; x++) { if (Bits[x]) { using (s.EnterCursorBookmark(Params.ElementName)) { string name = penum.GetMemberName(x); Params.StreamDataName(s, FA.Write, ref name); } } } }
void WriteNodes <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { if (Bits.EnabledCount == 0) { return; } var xs = s.GetSerializerInterface(); Collections.IProtoEnum penum = GetProtoEnum(xs.Database); if (Bits.Params.kGetMemberDefaultValue != null) { Contract.Assert(Params.ElementItselfMeansTrue); WriteNodesNotEqualToDefaultValues(s, penum); return; } foreach (var bitIndex in Bits.RawBits.SetBitIndices) { string name = penum.GetMemberName(bitIndex); if (Params.ElementItselfMeansTrue) { using (s.EnterCursorBookmark(name)) { // do nothing } } else { using (s.EnterCursorBookmark(Params.ElementName)) { Params.StreamDataName(s, ref name); } } } }
void ReadXmlNodes(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs) { Collections.IProtoEnum penum = Bits.InitializeFromEnum(xs.Database); foreach (XmlNode n in s.Cursor.ChildNodes) { if (n.Name != Params.ElementName) { continue; } using (s.EnterCursorBookmark(n as XmlElement)) { string name = null; Params.StreamDataName(s, FA.Read, ref name); int id = penum.GetMemberId(name); Bits[id] = true; } } Bits.OptimizeStorage(); }
void WriteNodesNotEqualToDefaultValues <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, Collections.IProtoEnum penum) where TDoc : class where TCursor : class { var getDefault = Bits.Params.kGetMemberDefaultValue; for (int x = 0; x < penum.MemberCount; x++) { bool bitDefault = getDefault(x); if (bitDefault == Bits[x]) { continue; } string name = penum.GetMemberName(x); using (s.EnterCursorBookmark(name)) { bool writtenValue = !bitDefault; s.WriteCursor(writtenValue); } } }