Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SavePoint.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 namespace SiliconStudio.ActionStack
6 {
7  /// <summary>
8  /// Represents a save point marker in the undo/redo action items stack.
9  /// </summary>
10  /// <remarks>A save point does not hold any reference to an action item or an action stack. It only stores the identifier of the related action item</remarks>
11  public sealed class SavePoint : IEquatable<SavePoint>
12  {
13  /// <summary>
14  /// Initializes a new instance of the <see cref="SavePoint"/> class.
15  /// </summary>
16  /// <param name="identifier">Identifier of the action item pointed by this save point.</param>
17  internal SavePoint(Guid identifier)
18  {
19  ActionItemIdentifier = identifier;
20  }
21 
22  /// <summary>
23  /// Gets the identifier of the action item pointed by the current marker.
24  /// </summary>
25  public Guid ActionItemIdentifier { get; private set; }
26 
27  /// <summary>
28  /// Empty save point.
29  /// </summary>
30  public static readonly SavePoint Empty = new SavePoint(Guid.Empty);
31 
32  /// <inheritdoc/>
33  public override int GetHashCode()
34  {
35  return ActionItemIdentifier.GetHashCode();
36  }
37 
38  /// <inheritdoc/>
39  public override bool Equals(object obj)
40  {
41  return obj != null && Equals(obj as SavePoint);
42  }
43 
44  /// <inheritdoc/>
45  public bool Equals(SavePoint other)
46  {
47  if ((object)other == null)
48  return false;
49 
50  // return equality check of the guids
51  return ActionItemIdentifier == other.ActionItemIdentifier;
52  }
53 
54  /// <summary>
55  /// Compares two <see cref="SavePoint"/> by their identifier and returns <c>true</c> if they are equal.
56  /// </summary>
57  /// <param name="left">The first save point to compare.</param>
58  /// <param name="right">The second save point to compare.</param>
59  /// <returns><c>true</c> if the save points are equal, <c>false</c> otherwise.</returns>
60  public static bool operator ==(SavePoint left, SavePoint right)
61  {
62  // first check reference equality (if references are equal, then the value are equal)
63  // it returns true if both references are null
64  if (ReferenceEquals(left, right))
65  return true;
66 
67  // if one reference is null, then they cannot be equal
68  if ((object)left == null || (object)right == null)
69  return false;
70 
71  // return equality check of the guids
72  return left.ActionItemIdentifier == right.ActionItemIdentifier;
73  }
74 
75  /// <summary>
76  /// Compares two <see cref="SavePoint"/> by their identifier and returns <c>true</c> if they are different.
77  /// </summary>
78  /// <param name="left">The first save point to compare.</param>
79  /// <param name="right">The second save point to compare.</param>
80  /// <returns><c>true</c> if the save points are different, <c>false</c> otherwise.</returns>
81  public static bool operator !=(SavePoint left, SavePoint right)
82  {
83  return !(left == right);
84  }
85  }
86 }
override bool Equals(object obj)
Definition: SavePoint.cs:39
Represents a save point marker in the undo/redo action items stack.
Definition: SavePoint.cs:11
bool Equals(SavePoint other)
Definition: SavePoint.cs:45