Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ScalarType.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.Shaders.Ast
6 {
7  /// <summary>
8  /// A Scalar type
9  /// </summary>
10  public class ScalarType : TypeBase
11  {
12  #region Constants and Fields
13 
14  /// <summary>
15  /// Scalar bool.
16  /// </summary>
17  public static readonly ScalarType Bool = new ScalarType("bool", typeof(bool));
18 
19  /// <summary>
20  /// Scalar double.
21  /// </summary>
22  public static readonly ScalarType Double = new ScalarType("double", typeof(double));
23 
24  /// <summary>
25  /// Sclar float.
26  /// </summary>
27  public static readonly ScalarType Float = new ScalarType("float", typeof(float));
28 
29  /// <summary>
30  /// Scalar half.
31  /// </summary>
32  public static readonly ScalarType Half = new ScalarType("half");
33 
34  /// <summary>
35  /// Scalar int.
36  /// </summary>
37  public static readonly ScalarType Int = new ScalarType("int", typeof(int));
38 
39  /// <summary>
40  /// Scalar unsigned int.
41  /// </summary>
42  public static readonly ScalarType UInt = new ScalarType("uint", typeof(uint));
43 
44  #endregion
45 
46  #region Constructors and Destructors
47 
48  /// <summary>
49  /// Initializes a new instance of the <see cref = "ScalarType" /> class.
50  /// </summary>
51  public ScalarType()
52  {
53  }
54 
55  /// <summary>
56  /// Initializes a new instance of the <see cref="ScalarType"/> class.
57  /// </summary>
58  /// <param name="name">
59  /// The name.
60  /// </param>
61  public ScalarType(string name)
62  : base(name)
63  {
64  }
65 
66  /// <summary>
67  /// Initializes a new instance of the <see cref="ScalarType"/> class.
68  /// </summary>
69  /// <param name="name">
70  /// The name.
71  /// </param>
72  /// <param name="type">
73  /// The type.
74  /// </param>
75  public ScalarType(string name, Type type)
76  : base(name)
77  {
78  Type = type;
79  }
80 
81  #endregion
82 
83  #region Public Properties
84 
85  /// <summary>
86  /// Gets or sets the type.
87  /// </summary>
88  /// <value>
89  /// The type.
90  /// </value>
91  public Type Type { get; set; }
92 
93  /// <summary>
94  /// Gets a boolean indicating if this scalar is an unsigned type.
95  /// </summary>
96  public bool IsUnsigned
97  {
98  get
99  {
100  return Type == typeof(uint);
101  }
102  }
103 
104  #endregion
105 
106  #region Public Methods
107 
108  /// <summary>
109  /// Equalses the specified other.
110  /// </summary>
111  /// <param name="other">
112  /// The other.
113  /// </param>
114  /// <returns>
115  /// <c>true</c> if the specified <see cref="ScalarType"/> is equal to this instance; otherwise, <c>false</c>.
116  /// </returns>
117  public bool Equals(ScalarType other)
118  {
119  if (ReferenceEquals(null, other))
120  {
121  return false;
122  }
123 
124  if (ReferenceEquals(this, other))
125  {
126  return true;
127  }
128 
129  return base.Equals(other) && Equals(other.Type, Type);
130  }
131 
132  /// <inheritdoc />
133  public override bool Equals(object obj)
134  {
135  if (ReferenceEquals(null, obj))
136  {
137  return false;
138  }
139 
140  if (ReferenceEquals(this, obj))
141  {
142  return true;
143  }
144 
145  return Equals(obj as ScalarType);
146  }
147 
148  /// <inheritdoc />
149  public override int GetHashCode()
150  {
151  unchecked
152  {
153  return (base.GetHashCode() * 397) ^ (Type != null ? Type.GetHashCode() : 0);
154  }
155  }
156 
157  #endregion
158 
159  #region Operators
160 
161  /// <summary>
162  /// Determines whether the specified type is a float/half/double.
163  /// </summary>
164  /// <param name="type">The type.</param>
165  /// <returns>
166  /// <c>true</c> if the specified type is float/half/double; otherwise, <c>false</c>.
167  /// </returns>
168  public static bool IsFloat(TypeBase type)
169  {
170  return type == Float || type == Double || type == Half;
171  }
172 
173  /// <summary>
174  /// Determines whether the specified type is an integer.
175  /// </summary>
176  /// <param name="type">The type.</param>
177  /// <returns>
178  /// <c>true</c> if the specified type is an integer; otherwise, <c>false</c>.
179  /// </returns>
180  public static bool IsInteger(TypeBase type)
181  {
182  return type == Int || type == UInt;
183  }
184 
185  /// <summary>
186  /// Implements the operator ==.
187  /// </summary>
188  /// <param name = "left">The left.</param>
189  /// <param name = "right">The right.</param>
190  /// <returns>
191  /// The result of the operator.
192  /// </returns>
193  public static bool operator ==(ScalarType left, ScalarType right)
194  {
195  return Equals(left, right);
196  }
197 
198  /// <summary>
199  /// Implements the operator !=.
200  /// </summary>
201  /// <param name = "left">The left.</param>
202  /// <param name = "right">The right.</param>
203  /// <returns>
204  /// The result of the operator.
205  /// </returns>
206  public static bool operator !=(ScalarType left, ScalarType right)
207  {
208  return !Equals(left, right);
209  }
210 
211  #endregion
212  }
213 }
bool Equals(ScalarType other)
Equalses the specified other.
Definition: ScalarType.cs:117
Type Type
Gets or sets the type.
Definition: ScalarType.cs:91
SiliconStudio.Paradox.Games.Mathematics.Half Half
override bool Equals(object obj)
Definition: ScalarType.cs:133
ScalarType()
Initializes a new instance of the ScalarType class.
Definition: ScalarType.cs:51
Base type for all types.
Definition: TypeBase.cs:11
static bool IsFloat(TypeBase type)
Determines whether the specified type is a float/half/double.
Definition: ScalarType.cs:168
ScalarType(string name, Type type)
Initializes a new instance of the ScalarType class.
Definition: ScalarType.cs:75
ScalarType(string name)
Initializes a new instance of the ScalarType class.
Definition: ScalarType.cs:61
static bool IsInteger(TypeBase type)
Determines whether the specified type is an integer.
Definition: ScalarType.cs:180