-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteCounter.cs
More file actions
25 lines (23 loc) · 829 Bytes
/
WriteCounter.cs
File metadata and controls
25 lines (23 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BuildTask
{
internal struct WriteCounter<T>
{
public bool HasValue { get => writing_count_ > 0; }
public bool WasCrashed { get => writing_count_ > 1; }
public T Value { get => value_; set { SetValue(value); } }
public uint WritingCount => writing_count_;
private uint writing_count_;
private T value_;
public T GetValueOrDefault(T _default_value) => HasValue ? Value : _default_value;
private void SetValue(T _value) { value_ = _value; writing_count_++; }
public override string ToString()
{
return $"{(HasValue? (WasCrashed ? $"!CRASHED! {value_}" : $"{value_}") : "(unset)")}";
}
}
}