Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CompositeIdentifier.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 using System.Collections;
5 using System.Collections.Generic;
6 using System.Text;
7 
8 namespace SiliconStudio.Shaders.Ast.Hlsl
9 {
10  /// <summary>
11  /// A composite identifier.
12  /// </summary>
13  public abstract class CompositeIdentifier : Identifier
14  {
15  #region Constructors and Destructors
16 
17  /// <summary>
18  /// Initializes a new instance of the <see cref = "CompositeIdentifier" /> class.
19  /// </summary>
21  {
22  Identifiers = new List<Identifier>();
23  }
24 
25  #endregion
26 
27  #region Public Properties
28 
29  /// <summary>
30  /// Gets or sets the path.
31  /// </summary>
32  /// <value>
33  /// The path.
34  /// </value>
35  public List<Identifier> Identifiers { get; set; }
36 
37  #endregion
38 
39  #region Public Methods
40 
41  /// <summary>
42  /// Gets the separator.
43  /// </summary>
44  public abstract string Separator { get; }
45 
46  public bool Equals(CompositeIdentifier other)
47  {
48  if (ReferenceEquals(null, other)) return false;
49  if (ReferenceEquals(this, other)) return true;
50 
51  return base.Equals(other) && (Identifiers.Count != other.Identifiers.Count);
52  }
53 
54  /// <inheritdoc/>
55  public override bool Equals(object obj)
56  {
57  if (ReferenceEquals(null, obj)) return false;
58  if (ReferenceEquals(this, obj)) return true;
59  return Equals(obj as CompositeIdentifier);
60  }
61 
62  /// <inheritdoc/>
63  public override int GetHashCode()
64  {
65  unchecked
66  {
67  return (base.GetHashCode() * 397) ^ Identifiers.GetHashCode();
68  }
69  }
70 
71  /// <inheritdoc />
72  public override IEnumerable<Node> Childrens()
73  {
74  return Identifiers;
75  }
76 
77  /// <inheritdoc />
78  public override string ToString()
79  {
80  var ranks = new StringBuilder();
81  if (Indices != null)
82  {
83  foreach (var expression in Indices)
84  {
85  ranks.Append("[").Append(expression).Append("]");
86  }
87  }
88 
89  return string.Format(IsSpecialReference ? "<{0}{1}>" : "{0}{1}", string.Join(Separator, Identifiers), ranks);
90  }
91 
92  #endregion
93  }
94 }
override IEnumerable< Node > Childrens()
Gets the child nodes. An enumeration of child nodes
CompositeIdentifier()
Initializes a new instance of the CompositeIdentifier class.
List< Identifier > Identifiers
Gets or sets the path.