92
|
1 namespace Implab.Diagnostics {
|
|
2 struct OperationContext {
|
|
3 readonly LogicalOperation m_initial;
|
|
4 public readonly static OperationContext EMPTY = new OperationContext(LogicalOperation.EMPTY, false);
|
|
5 LogicalOperation m_current;
|
|
6 readonly bool m_ownership;
|
|
7
|
|
8 public OperationContext(LogicalOperation operation, bool ownership) {
|
|
9 Safe.ArgumentNotNull(operation, "operation");
|
|
10
|
|
11 m_initial = operation;
|
|
12 m_current = operation;
|
|
13 m_ownership = ownership;
|
|
14 }
|
|
15
|
|
16 public LogicalOperation CurrentOperation {
|
|
17 get { return m_current; }
|
|
18 }
|
|
19
|
|
20 public void BeginLogicalOperation(string name) {
|
|
21 m_current = new LogicalOperation(name, m_current);
|
|
22 }
|
|
23
|
|
24 public LogicalOperation DetachLogicalOperation() {
|
|
25 var detached = m_current;
|
|
26 if (m_current != LogicalOperation.EMPTY) {
|
|
27 if (m_current != m_initial)
|
|
28 m_current = m_current.Parent;
|
|
29 else if (m_ownership)
|
|
30 m_current = LogicalOperation.EMPTY;
|
93
|
31 else {
|
|
32 TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context");
|
92
|
33 detached = LogicalOperation.EMPTY;
|
93
|
34 }
|
|
35 } else {
|
|
36 TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context");
|
92
|
37 }
|
93
|
38
|
92
|
39 return detached;
|
|
40 }
|
|
41
|
|
42 public void EndLogicalOperation() {
|
|
43 if (m_current != m_initial) {
|
|
44 m_current = m_current.Parent;
|
93
|
45 } else if (m_current != LogicalOperation.EMPTY && m_ownership) {
|
|
46 m_current = LogicalOperation.EMPTY;
|
92
|
47 } else {
|
|
48 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
|
|
49 }
|
|
50 }
|
93
|
51
|
|
52 public void Leave() {
|
|
53
|
|
54 if ((m_ownership && m_current != LogicalOperation.EMPTY) || (!m_ownership && m_current != m_initial) )
|
|
55 TraceLog.TraceWarning("Trying to leave unfinished logical operation {0}", m_current.Name);
|
|
56 }
|
92
|
57 }
|
|
58 }
|
|
59
|