Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AssignmentOperator.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  /// Assignment operator used in assignment expression (a = b) or statements (a = b;)
9  /// </summary>
10  public enum AssignmentOperator
11  {
12  /// <summary>
13  /// Operator =
14  /// </summary>
15  Default,
16 
17  /// <summary>
18  /// Operator +=
19  /// </summary>
20  Addition,
21 
22  /// <summary>
23  /// Operator -=
24  /// </summary>
25  Subtraction,
26 
27  /// <summary>
28  /// Operator *=
29  /// </summary>
31 
32  /// <summary>
33  /// Operator /=
34  /// </summary>
35  Division,
36 
37  /// <summary>
38  /// Operator %=
39  /// </summary>
40  Modulo,
41 
42  /// <summary>
43  /// Operator &amp;=
44  /// </summary>
45  BitwiseAnd,
46 
47  /// <summary>
48  /// Operator |=
49  /// </summary>
50  BitwiseOr,
51 
52  /// <summary>
53  /// Operator ^=
54  /// </summary>
55  BitwiseXor,
56 
57  /// <summary>
58  /// Operator &lt;&lt;=
59  /// </summary>
61 
62  /// <summary>
63  /// Operator >>=
64  /// </summary>
66  }
67 
68  /// <summary>
69  /// Helper for <see cref="AssignmentOperator"/>.
70  /// </summary>
71  public static class AssignmentOperatorHelper
72  {
73  #region Public Methods
74 
75  /// <summary>
76  /// Converts from operator to string
77  /// </summary>
78  /// <param name="assignmentOperator">
79  /// The assignment operator.
80  /// </param>
81  /// <returns>
82  /// A string representation of an assignment operator
83  /// </returns>
84  public static string ConvertToString(this AssignmentOperator assignmentOperator)
85  {
86  switch (assignmentOperator)
87  {
88  case AssignmentOperator.Default:
89  return "=";
90  case AssignmentOperator.Addition:
91  return "+=";
92  case AssignmentOperator.Subtraction:
93  return "-=";
94  case AssignmentOperator.Multiplication:
95  return "*=";
96  case AssignmentOperator.Division:
97  return "/=";
98  case AssignmentOperator.Modulo:
99  return "%=";
100  case AssignmentOperator.BitwiseAnd:
101  return "&=";
102  case AssignmentOperator.BitwiseOr:
103  return "|=";
104  case AssignmentOperator.BitwiseXor:
105  return "^=";
106  case AssignmentOperator.BitwiseShiftLeft:
107  return "<<=";
108  case AssignmentOperator.BitwiseShiftRight:
109  return ">>=";
110  }
111 
112  return string.Empty;
113  }
114 
115  /// <summary>
116  /// Converts from string an operator.
117  /// </summary>
118  /// <param name="operatorStr">
119  /// The operator text.
120  /// </param>
121  /// <exception cref="ArgumentException">
122  /// If operatorStr is invalid
123  /// </exception>
124  /// <returns>
125  /// An assignment operator
126  /// </returns>
127  public static AssignmentOperator FromString(string operatorStr)
128  {
129  if (operatorStr == "=")
130  {
131  return AssignmentOperator.Default;
132  }
133 
134  if (operatorStr == "+=")
135  {
136  return AssignmentOperator.Addition;
137  }
138 
139  if (operatorStr == "-=")
140  {
141  return AssignmentOperator.Subtraction;
142  }
143 
144  if (operatorStr == "*=")
145  {
146  return AssignmentOperator.Multiplication;
147  }
148 
149  if (operatorStr == "/=")
150  {
151  return AssignmentOperator.Division;
152  }
153 
154  if (operatorStr == "%=")
155  {
156  return AssignmentOperator.Modulo;
157  }
158 
159  if (operatorStr == "&=")
160  {
161  return AssignmentOperator.BitwiseAnd;
162  }
163 
164  if (operatorStr == "|=")
165  {
166  return AssignmentOperator.BitwiseOr;
167  }
168 
169  if (operatorStr == "^=")
170  {
171  return AssignmentOperator.BitwiseXor;
172  }
173 
174  if (operatorStr == "<<=")
175  {
176  return AssignmentOperator.BitwiseShiftLeft;
177  }
178 
179  if (operatorStr == ">>=")
180  {
181  return AssignmentOperator.BitwiseShiftRight;
182  }
183 
184  throw new ArgumentException(string.Format("Invalid assigment operator [{0}]", operatorStr));
185  }
186 
187  #endregion
188  }
189 }
static string ConvertToString(this AssignmentOperator assignmentOperator)
Converts from operator to string
AssignmentOperator
Assignment operator used in assignment expression (a = b) or statements (a = b;)
static AssignmentOperator FromString(string operatorStr)
Converts from string an operator.