root/trunk/SubversionSharp/dev/src/SvnOptRevision.cs

Revision 93, 9.0 kB (checked in by DenisG, 3 years ago)

Fix structure packing under Windows. Rules followed under windows seems to be that most structure has a packing size of 4, except those having long values that have a packing size of 8. However, this fix is not nice, hope to find a better way to fix this later.

  • Property svn:eol-style set to native
Line 
1 //  SubversionSharp, a wrapper library around the Subversion client API
2 #region Copyright (C) 2004 SOFTEC sa.
3 //
4 //  This library is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU Lesser General Public
6 //  License as published by the Free Software Foundation; either
7 //  version 2.1 of the License, or (at your option) any later version.
8 //
9 //  This library is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 //  Lesser General Public License for more details.
13 //
14 //  You should have received a copy of the GNU Lesser General Public
15 //  License along with this library; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 //
18 //  Sources, support options and lastest version of the complete library
19 //  is available from:
20 //              http://www.softec.st/SubversionSharp
21 //              Support@softec.st
22 //
23 //  Initial authors :
24 //              Denis Gervalle
25 //              Olivier Desaive
26 #endregion
27 //
28 using System;
29 using System.Diagnostics;
30 using System.Runtime.InteropServices;
31 using Softec.AprSharp;
32
33 namespace Softec.SubversionSharp
34 {
35     public class SvnRevision
36     {
37                 Svn.Revision mKind;
38                 int mNumber;
39                 long mDate;
40                
41                 #region Ctors
42                 public SvnRevision(Svn.Revision kind)
43                 {
44                         mKind = kind;
45                         mNumber = 0;
46                         mDate = 0;
47                 }
48
49                 public SvnRevision(int number)
50                 {
51                         mKind = Svn.Revision.Number;
52                         mNumber = number;
53                         mDate = 0;
54                 }
55
56                 public SvnRevision(long date)
57                 {
58                         mKind = Svn.Revision.Date;
59                         mNumber = 0;
60                         mDate = date;
61                 }
62                
63                 public SvnRevision(SvnOptRevision rev)
64                 {
65                 mKind = rev.Kind;
66             if(mKind == Svn.Revision.Number)
67                 mNumber = rev.Number;
68             else if(mKind == Svn.Revision.Date)
69                 mDate = rev.Date;
70                 }
71                 #endregion
72
73                 #region Operators
74         public static implicit operator SvnRevision(Svn.Revision revision)
75         {
76             return new SvnRevision(revision);
77         }
78        
79         public static implicit operator SvnRevision(int revision)
80         {
81             return new SvnRevision(revision);
82         }
83        
84         public static implicit operator SvnRevision(long revision)
85         {
86             return new SvnRevision(revision);
87         }
88        
89         public static implicit operator SvnRevision(SvnOptRevision revision)
90         {
91             return new SvnRevision(revision);
92         }
93                 #endregion
94                
95                 #region Methods
96                 public SvnOptRevision ToSvnOpt(AprPool pool)
97                 {
98                         return(new SvnOptRevision(this,pool));
99                 }
100
101                 public SvnOptRevision ToSvnOpt(out GCHandle handle)
102                 {
103                         return(new SvnOptRevision(this, out handle));
104                 }
105                 #endregion
106
107                 #region Properties
108                 public Svn.Revision Kind
109                 {
110                         get
111                         {
112                                 return(mKind);
113                         }
114                         set
115                         {
116                                 mKind = value;
117                         }
118                 }
119
120                 public int Number
121                 {
122                         get
123                         {
124                     if( mKind != Svn.Revision.Number )
125                         throw new AprNullReferenceException();
126                                 return(mNumber);
127                         }
128                         set
129                         {
130                                 mKind = Svn.Revision.Number;
131                                 mNumber = value;
132                         }
133                 }
134
135                 public long Date
136                 {
137                         get
138                         {
139                     if( mKind != Svn.Revision.Date )
140                         throw new AprNullReferenceException();
141                                 return(mDate);
142                         }
143                         set
144                         {
145                                 mKind = Svn.Revision.Date;
146                                 mDate = value;
147                         }
148                 }
149
150                 public SvnOptRevision Revision
151                 {
152                         set
153                         {
154                         mKind = value.Kind;
155                     if(mKind == Svn.Revision.Number)
156                         mNumber = value.Number;
157                     else if(mKind == Svn.Revision.Date)
158                         mDate = value.Date;
159                         }
160                 }
161                 #endregion
162         }
163        
164     public unsafe struct SvnOptRevision : IAprUnmanaged
165     {
166         private svn_opt_revision_t *mOptRevision;
167
168         [StructLayout( LayoutKind.Explicit )]
169                 private struct svn_opt_revision_t
170                 {
171                         [FieldOffset(0)]public int kind;
172 #if WIN32
173                         [FieldOffset(8)]public int number;
174                         [FieldOffset(8)]public long date;
175 #else
176                         [FieldOffset(4)]public int number;
177                 [FieldOffset(4)]public long date;
178 #endif
179                 }
180
181         #region Generic embedding functions of an IntPtr
182         private SvnOptRevision(svn_opt_revision_t *ptr)
183         {
184             mOptRevision = ptr;
185         }
186        
187         public SvnOptRevision(IntPtr ptr)
188         {
189             mOptRevision = (svn_opt_revision_t *) ptr.ToPointer();
190         }
191        
192         public SvnOptRevision(AprPool pool)
193         {
194             mOptRevision = (svn_opt_revision_t *) pool.CAlloc(sizeof(svn_opt_revision_t));
195         }
196        
197         public SvnOptRevision(Svn.Revision revKind, AprPool pool)
198         {
199             mOptRevision = (svn_opt_revision_t *) pool.CAlloc(sizeof(svn_opt_revision_t));
200             Kind = revKind;
201         }
202
203         public SvnOptRevision(int revNum, AprPool pool)
204         {
205             mOptRevision = (svn_opt_revision_t *) pool.CAlloc(sizeof(svn_opt_revision_t));
206             Number = revNum;
207         }
208        
209         public SvnOptRevision(long revDate, AprPool pool)
210         {
211             mOptRevision = (svn_opt_revision_t *) pool.CAlloc(sizeof(svn_opt_revision_t));
212             Date = revDate;
213         }
214
215         public SvnOptRevision(SvnRevision rev, AprPool pool)
216         {
217             mOptRevision = (svn_opt_revision_t *) pool.CAlloc(sizeof(svn_opt_revision_t));
218             Revision = rev;
219         }
220        
221         public SvnOptRevision(out GCHandle handle)
222         {
223             handle = GCHandle.Alloc(new svn_opt_revision_t(),GCHandleType.Pinned);
224             mOptRevision = (svn_opt_revision_t *)handle.AddrOfPinnedObject().ToPointer();
225         }
226        
227         public SvnOptRevision(Svn.Revision revKind, out GCHandle handle)
228         {
229             handle = GCHandle.Alloc(new svn_opt_revision_t(),GCHandleType.Pinned);
230             mOptRevision = (svn_opt_revision_t *)handle.AddrOfPinnedObject().ToPointer();
231             Kind = revKind;
232         }
233        
234         public SvnOptRevision(int revNum, out GCHandle handle)
235         {
236             handle = GCHandle.Alloc(new svn_opt_revision_t(),GCHandleType.Pinned);
237             mOptRevision = (svn_opt_revision_t *)handle.AddrOfPinnedObject().ToPointer();
238             Number = revNum;
239         }
240        
241         public SvnOptRevision(long revDate, out GCHandle handle)
242         {
243             handle = GCHandle.Alloc(new svn_opt_revision_t(),GCHandleType.Pinned);
244             mOptRevision = (svn_opt_revision_t *)handle.AddrOfPinnedObject().ToPointer();
245             Date = revDate;
246         }
247        
248         public SvnOptRevision(SvnRevision rev, out GCHandle handle)
249         {
250             handle = GCHandle.Alloc(new svn_opt_revision_t(),GCHandleType.Pinned);
251             mOptRevision = (svn_opt_revision_t *)handle.AddrOfPinnedObject().ToPointer();
252             Revision = rev;
253         }
254        
255         public bool IsNull
256         {
257                 get
258                 {
259                 return( mOptRevision == null );
260             }
261         }
262
263         private void CheckPtr()
264         {
265             if( IsNull )
266                 throw new AprNullReferenceException();
267         }
268
269         public void ClearPtr()
270         {
271             mOptRevision = null;
272         }
273
274         public IntPtr ToIntPtr()
275         {
276             return new IntPtr(mOptRevision);
277         }
278        
279                 public bool ReferenceEquals(IAprUnmanaged obj)
280                 {
281                         return(obj.ToIntPtr() == ToIntPtr());
282                 }
283                
284         public static implicit operator IntPtr(SvnOptRevision revision)
285         {
286             return new IntPtr(revision.mOptRevision);
287         }
288        
289         public static implicit operator SvnOptRevision(IntPtr ptr)
290         {
291             return new SvnOptRevision(ptr);
292         }
293
294         public override string ToString()
295         {
296             return("[svn_opt_revision_t:"+(new IntPtr(mOptRevision)).ToInt32().ToString("X")+"]");
297         }
298         #endregion
299                
300                 #region Properties wrappers
301                 public Svn.Revision Kind
302                 {
303                         get
304                         {
305                                 CheckPtr();
306                                 return((Svn.Revision)mOptRevision->kind);
307                         }
308                         set
309                         {
310                                 CheckPtr();
311                                 mOptRevision->kind = (int) value;
312                         }
313                 }
314
315                 public int Number
316                 {
317                         get
318                         {
319                                 CheckPtr();
320                     if( (Svn.Revision) mOptRevision->kind != Svn.Revision.Number )
321                         throw new AprNullReferenceException();
322                                 return(mOptRevision->number);
323                         }
324                         set
325                         {
326                                 CheckPtr();
327                     mOptRevision->kind = (int) Revision.Number;
328                                 mOptRevision->number = value;
329                         }
330                 }
331
332                 public long Date
333                 {
334                         get
335                         {
336                                 CheckPtr();
337                     if((Svn.Revision)mOptRevision->kind != Svn.Revision.Date )
338                         throw new AprNullReferenceException();
339                                 return(mOptRevision->date);
340                         }
341                         set
342                         {
343                                 CheckPtr();
344                     mOptRevision->kind = (int) Revision.Date;
345                                 mOptRevision->date = value;
346                         }
347                 }
348                
349                 public SvnRevision Revision
350                 {
351                         get
352                         {
353                                 CheckPtr();
354                                 return(new SvnRevision(this));
355                         }
356                         set
357                         {
358                                 CheckPtr();
359                         mOptRevision->kind = (int) value.Kind;
360                     if((Svn.Revision)mOptRevision->kind == Svn.Revision.Number)
361                         mOptRevision->number = value.Number;
362                     else if((Svn.Revision)mOptRevision->kind == Svn.Revision.Date)
363                         mOptRevision->date = value.Date;
364                         }
365                 }
366                 #endregion
367         }
368 }
Note: See TracBrowser for help on using the browser.