Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
UnaryOperator.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  /// Unary operator used in all binary expressions (except assignment expression).
9  /// </summary>
10  public enum UnaryOperator
11  {
12  /// <summary>
13  /// Logical not operator "!"
14  /// </summary>
15  LogicalNot,
16 
17  /// <summary>
18  /// Bitwise not operator "~"
19  /// </summary>
20  BitwiseNot,
21 
22  /// <summary>
23  /// Minus operator "-"
24  /// </summary>
25  Minus,
26 
27  /// <summary>
28  /// Plus operator "+"
29  /// </summary>
30  Plus,
31 
32  /// <summary>
33  /// Pre-decrement operator "--"
34  /// </summary>
36 
37  /// <summary>
38  /// Pre-inscrment operator "++"
39  /// </summary>
41 
42  /// <summary>
43  /// Post-decrement operator "--"
44  /// </summary>
46 
47  /// <summary>
48  /// Post-increment operator "++"
49  /// </summary>
51  }
52 
53  /// <summary>
54  /// Helper for <see cref="UnaryOperator"/>.
55  /// </summary>
56  public static class UnaryOperatorHelper
57  {
58  /// <summary>
59  /// Converts from string an operator. For post and pre operators, only working for pre.
60  /// </summary>
61  /// <param name="operatorStr">The operator text.</param>
62  /// <exception cref="ArgumentException">If operatorStr is invalid</exception>
63  /// <returns>An unary operator</returns>
64  public static UnaryOperator FromString(string operatorStr)
65  {
66  if (operatorStr == "!")
67  return UnaryOperator.LogicalNot;
68  if (operatorStr == "~")
69  return UnaryOperator.BitwiseNot;
70  if (operatorStr == "-")
71  return UnaryOperator.Minus;
72  if (operatorStr == "+")
73  return UnaryOperator.Plus;
74  if (operatorStr == "--")
75  return UnaryOperator.PreDecrement;
76  if (operatorStr == "++")
77  return UnaryOperator.PreIncrement;
78  throw new ArgumentException(string.Format("Invalid unary operator [{0}]", operatorStr));
79  }
80 
81  /// <summary>
82  /// Determines whether [is post fix] [the specified unary operator].
83  /// </summary>
84  /// <param name="unaryOperator">The unary operator.</param>
85  /// <returns>
86  /// <c>true</c> if [is post fix] [the specified unary operator]; otherwise, <c>false</c>.
87  /// </returns>
88  public static bool IsPostFix(this UnaryOperator unaryOperator)
89  {
90  return unaryOperator == UnaryOperator.PostIncrement || unaryOperator == UnaryOperator.PostDecrement;
91  }
92 
93  /// <summary>
94  /// Converts from operator to string
95  /// </summary>
96  /// <param name="unaryOperator">The unary operator.</param>
97  /// <returns>
98  /// A string representation of an unary operator
99  /// </returns>
100  public static string ConvertToString(this UnaryOperator unaryOperator)
101  {
102  switch (unaryOperator)
103  {
104  case UnaryOperator.LogicalNot:
105  return "!";
106  case UnaryOperator.BitwiseNot:
107  return "~";
108  case UnaryOperator.Minus:
109  return "-";
110  case UnaryOperator.Plus:
111  return "+";
112  case UnaryOperator.PreDecrement:
113  case UnaryOperator.PostDecrement:
114  return "--";
115  case UnaryOperator.PreIncrement:
116  case UnaryOperator.PostIncrement:
117  return "++";
118  }
119  return string.Empty;
120  }
121  }
122 }
static bool IsPostFix(this UnaryOperator unaryOperator)
Determines whether [is post fix] [the specified unary operator].
UnaryOperator
Unary operator used in all binary expressions (except assignment expression).
Pre-decrement operator "--"
Logical not operator "!"
Post-decrement operator "--"
static string ConvertToString(this UnaryOperator unaryOperator)
Converts from operator to string
Post-increment operator "++"
static UnaryOperator FromString(string operatorStr)
Converts from string an operator. For post and pre operators, only working for pre.
Pre-inscrment operator "++"
Bitwise not operator "~"