public static bool StreamStringOpt(KSoft.IO.XmlElementStream s, FA mode, string name, ref string value, bool toLower, XmlNodeType type = kSourceAttr, bool intern = false) { Contract.Requires(KSoft.IO.XmlElementStream.StreamSourceIsValid(type)); Contract.Requires(KSoft.IO.XmlElementStream.StreamSourceRequiresName(type) == (name != null)); bool result = true; if (type == XmlNodeType.Element) { result = s.StreamElementOpt(mode, name, ref value, PhxLib.Util.kNotNullOrEmpty); } else if (type == XmlNodeType.Attribute) { result = s.StreamAttributeOpt(mode, name, ref value, PhxLib.Util.kNotNullOrEmpty); } else if (type == XmlNodeType.Text) { s.StreamCursor(mode, ref value); } if (mode == FA.Read && result) { if (toLower) { value = value.ToLowerInvariant(); } if (intern) { value = string.Intern(value); } } return(result); }
public virtual int CompareTo(BTriggerSystem ts, TriggerScriptDbObjectWithArgs obj) { if (Name != obj.Name) { Debug.Trace.Engine.TraceInformation( "TriggerProtoDbObject: '{0}' - Encountered different names for {1}, '{2}' != '{3}'", ts, this.DbId.ToString(), this.Name, obj.Name); } if (ContainsUserClassTypeVar(ts, obj)) { Debug.Trace.Engine.TraceInformation( "TriggerProtoDbObject: {0} - Encountered {1}/{2} which has a UserClassType Var, skipping comparison", ts, DbId.ToString(), Name); return(0); } Contract.Assert(Version == obj.Version); Contract.Assert(Params.Count == obj.Args.Count); int diff = 0; for (int x = 0; x < Params.Count; x++) { int sig = Params[x].SigID; int obj_sig = obj.Args[x].SigID; sig = sig < 0 ? 0 : sig; obj_sig = obj_sig < 0 ? 0 : obj_sig; diff += sig - obj_sig; } return(diff); }
public string GetName(DatabaseObjectKind kind, int id) { Contract.Requires <ArgumentOutOfRangeException>(kind != DatabaseObjectKind.None); switch (kind) { case DatabaseObjectKind.Ability: return(TryGetNameWithUndefined(Abilities, id)); case DatabaseObjectKind.Civ: return(TryGetNameWithUndefined(Civs, id)); case DatabaseObjectKind.DamageType: return(TryGetNameWithUndefined(DamageTypes, id)); case DatabaseObjectKind.Leader: return(TryGetNameWithUndefined(Leaders, id)); case DatabaseObjectKind.Object: return(TryGetNameWithUndefined(Objects, id)); case DatabaseObjectKind.ObjectType: return(TryGetNameWithUndefined(ObjectTypes, id)); case DatabaseObjectKind.Power: return(TryGetNameWithUndefined(Powers, id)); case DatabaseObjectKind.Squad: return(TryGetNameWithUndefined(Squads, id)); case DatabaseObjectKind.Tech: return(TryGetNameWithUndefined(Techs, id)); // TODO: Should just use the Objects DBI AFAICT case DatabaseObjectKind.Unit: return(TryGetNameUnit(id)); case DatabaseObjectKind.UserClass: return(TryGetNameWithUndefined(UserClasses, id)); case DatabaseObjectKind.WeaponType: return(TryGetNameWithUndefined(WeaponTypes, id)); default: throw new Debug.UnreachableException(kind.ToString()); } }
public static void Serialize(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xsi, Collections.BTypeValuesSingle list, BTypeValuesXmlParams <float> @params, string attr_name = null) { Contract.Requires(s != null); Contract.Requires(xsi != null); Contract.Requires(list != null); Contract.Requires(@params != null); BTypeValuesXmlSerializerBase <float> xs; #if NO_TLS_STREAMING if (attr_name == null) { xs = new BTypeValuesSingleXmlSerializer(@params, list); } else { xs = new BTypeValuesSingleAttrHackXmlSerializer(@params, list, attr_name); } #else if (attr_name == null) { xs = BDatabaseXmlSerializerBase.sBTypeValuesSingleXmlSerializer.Value.Reset(@params, list); } else { xs = BDatabaseXmlSerializerBase.sBTypeValuesSingleAttrHackXmlSerializer.Value.Reset(@params, list, attr_name); } #endif using (xs) { xs.StreamXml(s, mode, xsi); } }
public BTypeValuesXmlSerializerBase(BTypeValuesXmlParams <T> @params, Collections.BTypeValuesBase <T> list) : base(@params) { Contract.Requires <ArgumentNullException>(@params != null); Contract.Requires <ArgumentNullException>(list != null); mList = list; }
public DbBuilderSerializerInterface(PhxEngine phx) { Contract.Requires(phx != null); mDatabase = phx.Database; TriggerDb = phx.TriggerDb; }
private ImmutableHashMap <TKey, TValue> AddRange(IEnumerable <KeyValuePair <TKey, TValue> > pairs, bool overwriteOnCollision, bool avoidToHashMap) { Debug.Assert(pairs != null); Contract.Ensures(Contract.Result <ImmutableHashMap <TKey, TValue> >() != null); if (this.IsEmpty && !avoidToHashMap) { // ReSharper disable PossibleMultipleEnumeration if (TryCastToImmutableMap(pairs, out var other)) { return(other.WithComparers(_keyComparer, _valueComparer)); } } var map = this; foreach (var pair in pairs) { map = overwriteOnCollision ? map.SetItem(pair.Key, pair.Value) : map.Add(pair.Key, pair.Value); } // ReSharper restore PossibleMultipleEnumeration return(map); }
/// <summary> /// Initializes a new instance of the <see cref="ImmutableHashMap<TKey, TValue>.HashBucket"/> class. /// </summary> /// <param name="suggestedHashRoll">The suggested hash roll.</param> /// <param name="bucket1">The bucket1.</param> /// <param name="bucket2">The bucket2.</param> internal HashBucket(int suggestedHashRoll, ValueOrListBucket bucket1, ValueOrListBucket bucket2) { Contract.Requires(bucket1 != null); Contract.Requires(bucket2 != null); Contract.Requires(bucket1.Hash != bucket2.Hash); // find next hashRoll that causes these two to be slotted in different buckets var h1 = bucket1.Hash; var h2 = bucket2.Hash; int s1; int s2; for (int i = 0; i < 32; i++) { this.hashRoll = (suggestedHashRoll + i) & 31; s1 = this.ComputeLogicalSlot(h1); s2 = this.ComputeLogicalSlot(h2); if (s1 != s2) { this.count = 2; this.used = (1u << s1) | (1u << s2); this.buckets = new Bucket[2]; this.buckets[this.ComputePhysicalSlot(s1)] = bucket1; this.buckets[this.ComputePhysicalSlot(s2)] = bucket2; return; } } throw new InvalidOperationException(); }
public ImmutableHashMap <TKey, TValue> SetItems(IEnumerable <KeyValuePair <TKey, TValue> > items) { Requires.NotNull(items, "items"); Contract.Ensures(Contract.Result <ImmutableDictionary <TKey, TValue> >() != null); return(this.AddRange(items, overwriteOnCollision: true, avoidToHashMap: false)); }
public int GetId(DatabaseObjectKind kind, string name) { Contract.Requires <ArgumentOutOfRangeException>(kind != DatabaseObjectKind.None); switch (kind) { case DatabaseObjectKind.Ability: return(TryGetIdWithUndefined(m_dbiAbilities, name, Abilities)); case DatabaseObjectKind.Civ: return(TryGetIdWithUndefined(m_dbiCivs, name, Civs)); case DatabaseObjectKind.DamageType: return(TryGetIdWithUndefined(m_dbiDamageTypes, name, DamageTypes)); case DatabaseObjectKind.Leader: return(TryGetIdWithUndefined(m_dbiLeaders, name, Leaders)); case DatabaseObjectKind.Object: return(TryGetIdWithUndefined(m_dbiObjects, name, Objects)); case DatabaseObjectKind.ObjectType: return(TryGetIdWithUndefined(ObjectTypes, name)); case DatabaseObjectKind.Power: return(TryGetIdWithUndefined(m_dbiPowers, name, Powers)); case DatabaseObjectKind.Squad: return(TryGetIdWithUndefined(m_dbiSquads, name, Squads)); case DatabaseObjectKind.Tech: return(TryGetIdWithUndefined(m_dbiTechs, name, Techs)); // TODO: Should just use the Objects DBI AFAICT case DatabaseObjectKind.Unit: return(TryGetIdUnit(name)); case DatabaseObjectKind.UserClass: return(TryGetIdWithUndefined(m_dbiUserClasses, name, UserClasses)); case DatabaseObjectKind.WeaponType: return(TryGetIdWithUndefined(m_dbiWeaponTypes, name, WeaponTypes)); default: throw new Debug.UnreachableException(kind.ToString()); } }
public ImmutableHashMap <TKey, TValue> AddRange(IEnumerable <KeyValuePair <TKey, TValue> > pairs) { Requires.NotNull(pairs, "pairs"); Contract.Ensures(Contract.Result <ImmutableHashMap <TKey, TValue> >() != null); return(this.AddRange(pairs, overwriteOnCollision: false, avoidToHashMap: false)); }
public static void StreamString(KSoft.IO.XmlElementStream s, FA mode, string name, ref string value, bool toLower, XmlNodeType type = kSourceAttr, bool intern = false) { Contract.Requires(KSoft.IO.XmlElementStream.StreamSourceIsValid(type)); Contract.Requires(KSoft.IO.XmlElementStream.StreamSourceRequiresName(type) == (name != null)); if (type == XmlNodeType.Element) { s.StreamElement(mode, name, ref value); } else if (type == XmlNodeType.Attribute) { s.StreamAttribute(mode, name, ref value); } else if (type == XmlNodeType.Text) { s.StreamCursor(mode, ref value); } if (mode == FA.Read) { if (toLower) { value = value.ToLowerInvariant(); } if (intern) { value = string.Intern(value); } } }
/// <summary>Saves the stream's owner so a new one can be specified, but is then later restored to the previous owner, via <see cref="Dispose()"/></summary> /// <param name="stream">The underlying stream for this bookmark</param> /// <param name="new_owner"></param> public IKSoftStreamOwnerBookmark(XmlElementStream stream, object new_owner) { Contract.Requires <ArgumentNullException>(stream != null); m_oldOwner = (m_stream = stream).Owner; m_stream.Owner = new_owner; }
public BListExplicitIndexXmlSerializer(BListExplicitIndexXmlParams <T> @params, Collections.BListExplicitIndex <T> list) : base(@params) { Contract.Requires <ArgumentNullException>(@params != null); Contract.Requires <ArgumentNullException>(list != null); mList = list; }
private ImmutableHashMap <TKey, TValue> AddRange(IEnumerable <KeyValuePair <TKey, TValue> > pairs, bool overwriteOnCollision, bool avoidToHashMap) { Contract.Requires(pairs != null); Contract.Ensures(Contract.Result <ImmutableHashMap <TKey, TValue> >() != null); // Some optimizations may apply if we're an empty list. if (this.IsEmpty && !avoidToHashMap) { // If the items being added actually come from an ImmutableHashMap<TKey, TValue> // then there is no value in reconstructing it. ImmutableHashMap <TKey, TValue> other; if (TryCastToImmutableMap(pairs, out other)) { return(other.WithComparers(this.keyComparer, this.valueComparer)); } } var map = this; foreach (var pair in pairs) { map = overwriteOnCollision ? map.SetItem(pair.Key, pair.Value) : map.Add(pair.Key, pair.Value); } return(map); }
public bool StreamXmlTactic(KSoft.IO.XmlElementStream s, FA mode, string xmlName, Engine.BProtoObject obj, ref bool wasStreamed, XmlNodeType xmlSource = Util.kSourceElement) { Contract.Requires(KSoft.IO.XmlElementStream.StreamSourceIsValid(xmlSource)); Contract.Requires(KSoft.IO.XmlElementStream.StreamSourceRequiresName(xmlSource) == (xmlName != null)); string id_name = null; bool to_lower = false; if (mode == FA.Read) { wasStreamed = Util.StreamStringOpt(s, mode, xmlName, ref id_name, to_lower, xmlSource); if (wasStreamed) { id_name = System.IO.Path.GetFileNameWithoutExtension(id_name); ObjectIdToTacticsMap[obj.AutoID] = id_name; TacticsMap[id_name] = null; } } else if (mode == FA.Write && wasStreamed) { id_name = obj.Name + Engine.BTacticData.kFileExt; Util.StreamStringOpt(s, mode, xmlName, ref id_name, to_lower, xmlSource); } return(wasStreamed); }
/// <summary> /// Initializes a new instance of the <see cref="ImmutableHashMap<TKey, TValue>.ListBucket"/> class. /// </summary> /// <param name="buckets">The buckets.</param> internal ListBucket(ValueBucket[] buckets) : base(buckets[0].Hash) { Contract.Requires(buckets != null); Contract.Requires(buckets.Length >= 2); this.buckets = buckets; }
public static void Serialize(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xsi, Collections.BTypeNames list, BListXmlParams @params, bool forceNoRootElementStreaming = false) { Contract.Requires(s != null); Contract.Requires(xsi != null); Contract.Requires(list != null); Contract.Requires(@params != null); if (forceNoRootElementStreaming) { @params.SetForceNoRootElementStreaming(true); } using (var xs = #if NO_TLS_STREAMING new BTypeNamesXmlSerializer(@params, list) #else BDatabaseXmlSerializerBase.sBTypeNamesXmlSerializer.Value.Reset(@params, list) #endif ) { xs.StreamXml(s, mode, xsi); } if (forceNoRootElementStreaming) { @params.SetForceNoRootElementStreaming(false); } }
public static bool StreamInternStringOpt(KSoft.IO.XmlElementStream s, FA mode, string name, ref string value, bool toLower, XmlNodeType type = kSourceAttr) { Contract.Requires(KSoft.IO.XmlElementStream.StreamSourceIsValid(type)); Contract.Requires(KSoft.IO.XmlElementStream.StreamSourceRequiresName(type) == (name != null)); return(StreamStringOpt(s, mode, name, ref value, toLower, type, true)); }
public BTriggerScriptSerializer(PhxEngine phx, Engine.BScenario scnr = null) { Contract.Requires(phx != null); mDatabase = phx.Database; TriggerDb = phx.TriggerDb; Scenario = scnr; }
public BListArrayXmlSerializer(BListXmlParams @params, Collections.BListArray <T> list) { Contract.Requires <ArgumentNullException>(@params != null); Contract.Requires <ArgumentNullException>(list != null); mParams = @params; mList = list; }
protected void Reset(BTypeValuesXmlParams <T> @params, Collections.BTypeValuesBase <T> list) { Contract.Requires <ArgumentNullException>(@params != null); Contract.Requires <ArgumentNullException>(list != null); base.Reset(@params); mList = list; }
/// <summary>Returns the cursor to a previously saved cursor value</summary> /// <param name="old_cursor">Previously saved cursor. Set to null before the method returns</param> public void RestoreCursor(ref XmlElement old_cursor) { Contract.Ensures(Contract.ValueAtReturn(out old_cursor) == null); Contract.Assert(old_cursor != null, "Can't restore a cursor that wasn't saved!"); Cursor = old_cursor; old_cursor = null; }
public BListOfIDsXmlSerializer(BListOfIDsXmlParams <TContext> @params, Collections.BListOfIDs <TContext> list) { Contract.Requires <ArgumentNullException>(@params != null); Contract.Requires <ArgumentNullException>(list != null); mParams = @params; mList = list; }
public BCostTypeValuesSingleAttrHackXmlSerializer Reset(Collections.BTypeValuesSingle list) { Contract.Requires <ArgumentNullException>(list != null); base.Reset(kParams); mList = list; return(this); }
public static HandleWord GetUndefinedReferenceHandle(HandleWord undefinedRefDataIndex) { Contract.Requires(undefinedRefDataIndex < HandleWord.MaxValue, "Index value would generate a handle that matches the general invalid-handle sentinel"); HandleWordUnsigned index = (HandleWordUnsigned)undefinedRefDataIndex; return((HandleWord)(index | kUndefinedReferenceHandleBitmask)); }
/// <summary> /// Initializes a new instance of the <see cref="ImmutableHashMap<TKey, TValue>"/> class. /// </summary> /// <param name="root">The root.</param> /// <param name="comparer">The comparer.</param> /// <param name="valueComparer">The value comparer.</param> private ImmutableHashMap(Bucket root, IEqualityComparer <TKey> comparer, IEqualityComparer <TValue> valueComparer) : this(comparer, valueComparer) { Contract.Requires(root != null); Contract.Requires(comparer != null); Contract.Requires(valueComparer != null); this.root = root; }
public BBitSetXmlSerializer(BListXmlParams @params, Collections.BBitSet bits) { Contract.Requires <ArgumentNullException>(@params != null); Contract.Requires <ArgumentNullException>(bits != null); Contract.Requires(@Params.UseElementName, "Collection only supports element name filtering"); Params = @params; Bits = bits; }
public BBitSet(BBitSetParams @params) { Contract.Requires <ArgumentNullException>(@params != null); EnabledCount = 0; Params = @params; InitializeFromEnum(null); }
public IEnumerable <string> GetFiles(ContentStorage loc, GameDirectory gameDir, string searchPattern) { Contract.Requires(loc != ContentStorage.UpdateOrGame, "Must iterate storages separately"); Contract.Requires(!string.IsNullOrEmpty(searchPattern)); string dir = GetAbsoluteDirectory(loc, gameDir); return(Directory.GetFiles(dir, searchPattern)); }