command line options, and dos2unix
[mono.git] / mcs / class / Mono.PEToolkit / RVA.cs
1 \r
2 //\r
3 // Permission is hereby granted, free of charge, to any person obtaining\r
4 // a copy of this software and associated documentation files (the\r
5 // "Software"), to deal in the Software without restriction, including\r
6 // without limitation the rights to use, copy, modify, merge, publish,\r
7 // distribute, sublicense, and/or sell copies of the Software, and to\r
8 // permit persons to whom the Software is furnished to do so, subject to\r
9 // the following conditions:\r
10 // \r
11 // The above copyright notice and this permission notice shall be\r
12 // included in all copies or substantial portions of the Software.\r
13 // \r
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21 //\r
22 /*\r
23  * Copyright (c) 2002 Sergey Chaban <serge@wildwestsoftware.com>\r
24  */\r
25 \r
26 using System;\r
27 using System.IO;\r
28 \r
29 namespace Mono.PEToolkit {\r
30 \r
31         /// <summary>\r
32         /// Relative Virtual Address.\r
33         /// </summary>\r
34         public struct RVA {\r
35 \r
36                 public static readonly RVA Null;\r
37 \r
38                 public uint value;\r
39 \r
40                 static RVA()\r
41                 {\r
42                         Null = new RVA(0);\r
43                 }\r
44 \r
45 \r
46                 public RVA(uint val)\r
47                 {\r
48                         value = val;\r
49                 }\r
50 \r
51 \r
52                 public uint Value {\r
53                         get {\r
54                                 return value;\r
55                         }\r
56                         set {\r
57                                 this.value = value;\r
58                         }\r
59                 }\r
60 \r
61                 public void Write (BinaryWriter writer)\r
62                 {\r
63                         writer.Write (value);\r
64                 }\r
65 \r
66                 public static implicit operator RVA (uint val)\r
67                 {\r
68                         return new RVA(val);\r
69                 }\r
70 \r
71                 public static implicit operator uint (RVA rva)\r
72                 {\r
73                         return rva.value;\r
74                 }\r
75 \r
76                 public override int GetHashCode()\r
77                 {\r
78                         return (int) value;\r
79                 }\r
80 \r
81                 public override bool Equals(object o)\r
82                 {\r
83                         bool res = o is RVA;\r
84                         if (res) res = (this.value == ((RVA)o).value);\r
85                         return res;\r
86                 }\r
87 \r
88                 public static bool operator == (RVA rva1, RVA rva2)\r
89                 {\r
90                         return rva1.Equals(rva2);\r
91                 }\r
92 \r
93                 public static bool operator != (RVA rva1, RVA rva2)\r
94                 {\r
95                         return !rva1.Equals(rva2);\r
96                 }\r
97 \r
98                 public static bool operator < (RVA rva1, RVA rva2)\r
99                 {\r
100                         return (rva1.value < rva2.value);\r
101                 }\r
102 \r
103                 public static bool operator > (RVA rva1, RVA rva2) {\r
104                         return (rva1.value > rva2.value);\r
105                 }\r
106 \r
107                 public static bool operator <= (RVA rva1, RVA rva2)\r
108                 {\r
109                         return (rva1.value <= rva2.value);\r
110                 }\r
111 \r
112                 public static bool operator >= (RVA rva1, RVA rva2)\r
113                 {\r
114                         return (rva1.value >= rva2.value);\r
115                 }\r
116 \r
117                 public static RVA operator + (RVA rva, uint x)\r
118                 {\r
119                         return new RVA (rva.value + x);\r
120                 }\r
121 \r
122                 public static RVA operator - (RVA rva, uint x)\r
123                 {\r
124                         return new RVA (rva.value - x);\r
125                 }\r
126 \r
127 \r
128                 public override string ToString()\r
129                 {\r
130                         if (this == Null) return "NULL";\r
131                         return ("0x" + value.ToString("X"));\r
132                 }\r
133 \r
134                 unsafe public static int Size {\r
135                         get {\r
136                                 return sizeof (uint);\r
137                         }\r
138                 }\r
139 \r
140         }\r
141 \r
142 }\r
143 \r