Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ClassType.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  /// Definition of a class.
12  /// </summary>
14  {
15  #region Constructors and Destructors
16 
17  /// <summary>
18  /// Initializes a new instance of the <see cref = "ClassType" /> class.
19  /// </summary>
20  public ClassType()
21  : this(null)
22  {
23  }
24 
25  /// <summary>
26  /// Initializes a new instance of the <see cref="ClassType"/> class.
27  /// </summary>
28  /// <param name="name">
29  /// The name.
30  /// </param>
31  public ClassType(string name)
32  : base(name)
33  {
34  BaseClasses = new List<TypeName>();
35  Members = new List<Node>();
36  GenericParameters = new List<TypeBase>();
37  GenericArguments = new List<TypeBase>();
38  }
39 
40  #endregion
41 
42  #region Public Properties
43 
44  /// <summary>
45  /// Gets or sets the base classes.
46  /// </summary>
47  /// <value>
48  /// The base classes.
49  /// </value>
50  public List<TypeName> BaseClasses { get; set; }
51 
52  /// <inheritdoc/>
53  public List<TypeBase> GenericParameters { get; set; }
54 
55  /// <inheritdoc/>
56  public List<TypeBase> GenericArguments { get; set; }
57 
58  /// <summary>
59  /// Gets or sets the members.
60  /// </summary>
61  /// <value>
62  /// The members.
63  /// </value>
64  public List<Node> Members { get; set; }
65 
66  #endregion
67 
68  #region Public Methods
69 
70  /// <inheritdoc />
71  public override IEnumerable<Node> Childrens()
72  {
73  ChildrenList.Clear();
74  ChildrenList.Add(Name);
75  ChildrenList.AddRange(BaseClasses);
76  ChildrenList.AddRange(Members);
77  return ChildrenList;
78  }
79 
80  /// <inheritdoc />
81  public override string ToString()
82  {
83  var bases = new StringBuilder();
84  foreach (var baseClass in BaseClasses)
85  {
86  bases.Append(" : ").Append(baseClass);
87  }
88  var generics = new StringBuilder();
89  if (GenericParameters.Count > 0)
90  {
91  generics.Append("<");
92  for (int i = 0; i < GenericParameters.Count; i++)
93  {
94  var genericArgument = GenericArguments.Count == GenericParameters.Count ? GenericArguments[i] : GenericParameters[i];
95  if (i > 0) generics.Append(", ");
96  generics.Append(genericArgument);
97  }
98  generics.Append(">");
99  }
100 
101  return string.Format("class {0}{1}{2} {{...}}", Name, generics, bases);
102  }
103 
104  /// <inheritdoc/>
105  public bool Equals(ClassType other)
106  {
107  return base.Equals(other);
108  }
109 
110  /// <inheritdoc/>
111  public override bool Equals(object obj)
112  {
113  if (ReferenceEquals(null, obj))
114  {
115  return false;
116  }
117  if (ReferenceEquals(this, obj))
118  {
119  return true;
120  }
121  return Equals(obj as ClassType);
122  }
123 
124  /// <inheritdoc/>
125  public override int GetHashCode()
126  {
127  return base.GetHashCode();
128  }
129 
130  /// <summary>
131  /// Implements the operator ==.
132  /// </summary>
133  /// <param name="left">The left.</param>
134  /// <param name="right">The right.</param>
135  /// <returns>
136  /// The result of the operator.
137  /// </returns>
138  public static bool operator ==(ClassType left, ClassType right)
139  {
140  return Equals(left, right);
141  }
142 
143  /// <summary>
144  /// Implements the operator !=.
145  /// </summary>
146  /// <param name="left">The left.</param>
147  /// <param name="right">The right.</param>
148  /// <returns>
149  /// The result of the operator.
150  /// </returns>
151  public static bool operator !=(ClassType left, ClassType right)
152  {
153  return !Equals(left, right);
154  }
155 
156  #endregion
157  }
158 }
ClassType()
Initializes a new instance of the ClassType class.
Definition: ClassType.cs:20
A tag interface to identify a container for scope declarations.
An interface used by generic definitions and instance.
Definition: IGenerics.cs:10
override bool Equals(object obj)
Definition: ClassType.cs:111
override IEnumerable< Node > Childrens()
Gets the child nodes. An enumeration of child nodes
Definition: ClassType.cs:71
ClassType(string name)
Initializes a new instance of the ClassType class.
Definition: ClassType.cs:31
Toplevel interface for a declaration.
Definition: IDeclaration.cs:8