ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/GBase.h
(Generate patch)
# Line 25 | Line 25
25    #define CHPATHSEP '\\'
26    #undef off_t
27    #define off_t int64_t
28 +  #ifndef popen
29 +   #define popen _popen
30 +  #endif
31    #ifdef _fseeki64
32      #define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin)
33    #else
# Line 48 | Line 51
51    #include <unistd.h>
52   #endif
53  
54 + #ifndef fseeko
55 + #define fseeko fseek
56 + #endif
57 + #ifndef ftello
58 + #define ftello ftell
59 + #endif
60  
61   #ifdef DEBUG
62   #undef NDEBUG
# Line 55 | Line 64
64  
65   typedef int32_t int32;
66   typedef uint32_t uint32;
67 + typedef int16_t int16;
68 + typedef uint16_t uint16;
69  
70   typedef unsigned char uchar;
71   typedef unsigned char byte;
# Line 161 | Line 172
172    return a-b;
173   }
174  
175 < int Gstrcmp(char* a, char* b);
175 > int Gstrcmp(const char* a, const char* b, int n=-1);
176   //same as strcmp but doesn't crash on NULL pointers
177  
178 < int Gstricmp(const char* a, const char* b);
178 > int Gstricmp(const char* a, const char* b, int n=-1);
179 >
180 > //basic swap template function
181 > template<class T> void Gswap(T& lhs, T& rhs) {
182 > //register T tmp=lhs;
183 > T tmp=lhs; //requires copy operator
184 > lhs=rhs;
185 > rhs=tmp;
186 > }
187  
169 inline void swap(int &arg1, int &arg2){
170 //arg1 ^= arg2;
171 //arg2 ^= arg1;
172 //arg1 ^= arg2;
173 register int swp=arg1;
174 arg1=arg2; arg2=swp;
175 }
176
177 inline void swap(char* &arg1, char* &arg2){ //swap pointers!
178 register char* swp=arg1;
179 arg1=arg2; arg2=swp;
180 }
181
182 inline void swap(uint &arg1, uint &arg2) {
183  register uint swp=arg1;
184  arg1=arg2; arg2=swp;
185  }
186
187 inline void swap(short &arg1, short &arg2) {
188  register short swp=arg1;
189  arg1=arg2; arg2=swp;
190  }
191
192 inline void swap(unsigned short &arg1, unsigned short &arg2) {
193  register unsigned short swp=arg1;
194  arg1=arg2; arg2=swp;
195  }
196
197 inline void swap(long &arg1, long &arg2) {
198  register long swp=arg1;
199  arg1=arg2; arg2=swp;
200  }
201
202 inline void swap(unsigned long &arg1, unsigned long &arg2) {
203  register unsigned long swp=arg1;
204  arg1=arg2; arg2=swp;
205  }
206
207
208 inline void swap(char &arg1, char &arg2) {
209  register char swp=arg1;
210  arg1=arg2; arg2=swp;
211  }
212
213 inline void swap(unsigned char &arg1, unsigned char &arg2) {
214  register unsigned char swp=arg1;
215  arg1=arg2; arg2=swp;
216  }
188  
189   /**************** Memory management ***************************/
190  
# Line 268 | Line 239
239   char* strchrs(const char* s, const char* chrs);
240   //strchr but with a set of chars instead of only one
241  
242 < char* rstrfind(const char* str, const char *substr); /* like rindex() but for strings
243 < or like the right side version of strstr()
244 < */
245 < //reverse character string or
275 < char* reverseChars(char* str, int slen=0);
242 > char* rstrfind(const char* str, const char *substr);
243 > // like rindex() but for strings;  right side version of strstr()
244 >
245 > char* reverseChars(char* str, int slen=0); //in place reversal of string
246  
247   char* rstrstr(const char* rstart, const char *lend, const char* substr);
248   /*the reversed, rightside equivalent of strstr: starts searching
# Line 325 | Line 295
295       }
296  
297    bool overlap(uint s, uint e) {
298 <     if (s>e) { swap(s,e); }
298 >     if (s>e) { Gswap(s,e); }
299       //return start<s ? (s<=end) : (start<=e);
300       return (start<=e && end>=s);
301       }
# Line 342 | Line 312
312          }
313       }
314    int overlapLen(uint rstart, uint rend) {
315 <     if (rstart>rend) { swap(rstart,rend); }
315 >     if (rstart>rend) { Gswap(rstart,rend); }
316       if (start<rstart) {
317          if (rstart>end) return 0;
318          return (rend>end) ? end-rstart+1 : rend-rstart+1;
# Line 364 | Line 334
334    bool operator==(GSeg& d){
335        return (start==d.start && end==d.end);
336        }
367  bool operator>(GSeg& d){
368     return (start==d.start)?(end>d.end):(start>d.start);
369     }
337    bool operator<(GSeg& d){
338       return (start==d.start)?(end<d.end):(start<d.start);
339       }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines