using System.Collections.Generic; namespace Chernobyl.Threading { /// /// A for value types. Use this for simple, small /// value types (like char, float, small structs, etc) or if you don't have /// the time/need for a faster, more powerful . /// class ValueTypeAccessor : DataAccessor where DataType : struct { /// /// Constructor. /// /// The to attach to. /// The rights granted to this accessor. public ValueTypeAccessor(DataSafe attachTo, AccessRights accessRights) : base(attachTo, accessRights) { } /// /// Returns the current value of the held data. /// public DataType Read() { return _theData; } /// /// Sets the current value of the held data. Only /// call this method when you have to. Fewer calls /// to this method will help performance. /// public void Write(DataType newValue) { _theData = newValue; MyDataSafe.RecordChange(this, (ref DataType oldValue) => oldValue = _theData); } /// /// This method is called when the DataSafe is synchronized. /// The passed in changeRecords are to be run on the accessors /// data so that it can have it's data synchronized with the other /// accessors. /// /// The change records to run on the internal /// data. public override void Synchronize(Queue.ChangeRecord> changeRecords) { foreach (DataSafe.ChangeRecord cr in changeRecords) { cr(ref _theData); } } /// /// A copy of the data in the DataSafe. /// DataType _theData; } }