1 #Region "Microsoft.VisualBasic::ef16285bcf1dd1e43c4720a98796fe49, Microsoft.VisualBasic.Core\Language\Value\Pointer.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Class Pointer
35     
36     '         Constructor: (+3 OverloadsSub New
37     '         FunctionToString
38     '         Operators: (+2 Overloads) -, (+4 Overloads) +, <, <<, <=
39     '                    >, >=
40     
41     
42     ' /********************************************************************************/
43
44 #End Region
45
46 Imports System.Runtime.CompilerServices
47
48 Namespace Language
49
50     ''' <summary>
51     ''' Type of <see cref="Int32"/> pointer class to the <see cref="Array"/> class.
52     ''' (<see cref="Int32"/>类型,一般用来进行数组操作的)
53     ''' </summary>
54     Public Class Pointer
55
56         ''' <summary>
57         ''' Current read position
58         ''' </summary>
59         Protected index As Integer
60         ''' <summary>
61         ''' 指针移动的步进值
62         ''' </summary>
63         Protected ReadOnly [step] As Integer
64
65         ''' <summary>
66         ''' Construct a pointer class and then assign a initial <see cref="Int32"/> value.
67         ''' (构造一个指针对象,并且赋值其初始值)
68         ''' </summary>
69         ''' <param name="n">The initial value.</param>
70         Sub New(n As Integer)
71             index = n
72             [step] = 1
73         End Sub
74
75         Public Sub New(n As Integer, [step] As Integer)
76             index = n
77             Me.step = [step]
78         End Sub
79
80         ''' <summary>
81         ''' Creates a new <see cref="Integer"/> type pointer object in VisualBasic with its initial value is ZERO.(构造一个初始值为零的整形数指针对象)
82         ''' </summary>
83         Sub New()
84             Call Me.New(Scan0)
85         End Sub
86
87         Public Overrides Function ToString() As String
88             Return index
89         End Function
90
91         <MethodImpl(MethodImplOptions.AggressiveInlining)>
92         Public Shared Widening Operator CType(n As IntegerAs Pointer
93             Return New Pointer(n)
94         End Operator
95
96         Public Shared Narrowing Operator CType(n As Pointer) As Integer
97             Return n.index
98         End Operator
99
100         Public Overloads Shared Operator +(n As Pointer, x As IntegerAs Pointer
101             n.index += x
102             Return n
103         End Operator
104
105         Public Overloads Shared Operator +(x As Integer, n As Pointer) As Pointer
106             n.index += x
107             Return n
108         End Operator
109
110         Public Overloads Shared Operator +(x As Pointer, n As Pointer) As Pointer
111             Return New Pointer(n.index + x.index)
112         End Operator
113
114         ''' <summary>
115         ''' ``<see cref="index"/> &lt; <paramref name="n"/>``
116         ''' </summary>
117         ''' <param name="x"></param>
118         ''' <param name="n"></param>
119         ''' <returns></returns>
120         Public Overloads Shared Operator <(x As Pointer, n As IntegerAs Boolean
121             Return x.index < n
122         End Operator
123
124         Public Overloads Shared Operator >(x As Pointer, n As IntegerAs Boolean
125             Return x.index > n
126         End Operator
127
128         Public Shared Operator -(x As Pointer, n As IntegerAs Integer
129             Dim p As Integer = x.index
130             x.index -= n
131             Return p
132         End Operator
133
134         ''' <summary>
135         ''' 移动n,然后返回之前的数值
136         ''' </summary>
137         ''' <param name="x"></param>
138         ''' <param name="n"></param>
139         ''' <returns></returns>
140         Public Shared Operator <<(x As Pointer, n As IntegerAs Integer
141             Dim value As Integer = x.index
142             x.index += n
143             Return value
144         End Operator
145
146         ''' <summary>
147         ''' Automatically increasing self +1 and then returns the previous value.(自增1,然后返回之前的数值)
148         ''' </summary>
149         ''' <param name="x"></param>
150         ''' <returns></returns>
151         Public Overloads Shared Operator +(x As Pointer) As Integer
152             Dim p As Integer = x.index
153             x.index += x.step
154             Return p
155         End Operator
156
157         ''' <summary>
158         ''' 自减1,然后返回之前的数值
159         ''' </summary>
160         ''' <param name="x"></param>
161         ''' <returns></returns>
162         Public Overloads Shared Operator -(x As Pointer) As Integer
163             Dim p As Integer = x.index
164             x.index -= x.step
165             Return p
166         End Operator
167
168         ''' <summary>
169         ''' Less than or equals
170         ''' </summary>
171         ''' <param name="x"></param>
172         ''' <param name="n"></param>
173         ''' <returns></returns>
174         Public Shared Operator <=(x As Pointer, n As IntegerAs Boolean
175             Return x.index <= n
176         End Operator
177
178         ''' <summary>
179         ''' Greater than or equals
180         ''' </summary>
181         ''' <param name="x"></param>
182         ''' <param name="n"></param>
183         ''' <returns></returns>
184         Public Shared Operator >=(x As Pointer, n As IntegerAs Boolean
185             Return x.index >= n
186         End Operator
187     End Class
188 End Namespace