Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Node.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.Generic;
5 using System.Runtime.Serialization;
6 using System.Threading;
7 
9 
10 namespace SiliconStudio.Shaders.Ast
11 {
12  /// <summary>
13  /// Abstract node.
14  /// </summary>
15  public abstract class Node
16  {
17  /// <summary>
18  /// list of childrens for ast navigation.
19  /// </summary>
20  [VisitorIgnore]
21  private List<Node> childrenList = null;
22  private Dictionary<object, object> tags;
23 
24  /// <summary>
25  /// Initializes a new instance of the <see cref="Node"/> class.
26  /// </summary>
27  protected Node()
28  {
29  }
30 
31  /// <summary>
32  /// Gets or sets the source span.
33  /// </summary>
34  /// <value>
35  /// The source span.
36  /// </value>
37  public SourceSpan Span { get; set; }
38 
39 
40  public override bool Equals(object against)
41  {
42  return base.Equals(against);
43  }
44 
45  public override int GetHashCode()
46  {
47  return base.GetHashCode();
48  }
49 
50  public static bool operator ==(Node left, Node right)
51  {
52  return Equals(left, right);
53  }
54 
55  public static bool operator !=(Node left, Node right)
56  {
57  return !Equals(left, right);
58  }
59 
60  /// <summary>
61  /// Gets the childrens.
62  /// </summary>
63  protected List<Node> ChildrenList
64  {
65  get
66  {
67  if (childrenList == null)
68  childrenList = new List<Node>();
69  return childrenList;
70  }
71  }
72 
73  /// <summary>
74  /// Gets a tag value associated to this node..
75  /// </summary>
76  /// <param name="tagKey">The tag key.</param>
77  /// <returns>The tag value</returns>
78  public object GetTag(object tagKey)
79  {
80  if (tags == null) return null;
81  object result;
82  tags.TryGetValue(tagKey, out result);
83  return result;
84  }
85 
86 
87  /// <summary>
88  /// Gets a tag value associated to this node..
89  /// </summary>
90  /// <param name="tagKey">The tag key.</param>
91  /// <returns>The tag value</returns>
92  public bool RemoveTag(object tagKey)
93  {
94  if (tags == null) return true;
95  return tags.Remove(tagKey);
96  }
97 
98  /// <summary>
99  /// Determines whether the specified instance contains this tag.
100  /// </summary>
101  /// <param name="tagKey">The tag key.</param>
102  /// <returns>
103  /// <c>true</c> if the specified instance contains this tag; otherwise, <c>false</c>.
104  /// </returns>
105  public bool ContainsTag(object tagKey)
106  {
107  if (tags == null) return false;
108  return tags.ContainsKey(tagKey);
109  }
110 
111  /// <summary>
112  /// Sets a tag value associated to this node.
113  /// </summary>
114  /// <param name="tagKey">The tag key.</param>
115  /// <param name="tagValue">The tag value.</param>
116  public void SetTag(object tagKey, object tagValue)
117  {
118  if (tags == null) tags = new Dictionary<object, object>();
119  tags.Remove(tagKey);
120  tags.Add(tagKey, tagValue);
121  }
122 
123  /// <summary>
124  /// Gets the child nodes.
125  /// </summary>
126  /// <returns>An enumeration of child nodes</returns>
127  public virtual IEnumerable<Node> Childrens()
128  {
129  return ChildrenList;
130  }
131 
132  /// <inheritdoc/>
133  public override string ToString()
134  {
135  return GetType().Name;
136  }
137  }
138 }
bool ContainsTag(object tagKey)
Determines whether the specified instance contains this tag.
Definition: Node.cs:105
virtual IEnumerable< Node > Childrens()
Gets the child nodes.
Definition: Node.cs:127
bool RemoveTag(object tagKey)
Gets a tag value associated to this node..
Definition: Node.cs:92
Abstract node.
Definition: Node.cs:15
void SetTag(object tagKey, object tagValue)
Sets a tag value associated to this node.
Definition: Node.cs:116
SiliconStudio.Shaders.Ast.SourceSpan SourceSpan
Definition: Node.cs:8
Node()
Initializes a new instance of the Node class.
Definition: Node.cs:27
override string ToString()
Definition: Node.cs:133
override int GetHashCode()
Definition: Node.cs:45
override bool Equals(object against)
Definition: Node.cs:40
object GetTag(object tagKey)
Gets a tag value associated to this node..
Definition: Node.cs:78