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 61 | 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 167 | 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  
175 inline void swap(int &arg1, int &arg2){
176 //arg1 ^= arg2;
177 //arg2 ^= arg1;
178 //arg1 ^= arg2;
179 register int swp=arg1;
180 arg1=arg2; arg2=swp;
181 }
182
183 inline void swap(char* &arg1, char* &arg2){ //swap pointers!
184 register char* swp=arg1;
185 arg1=arg2; arg2=swp;
186 }
187
188 inline void swap(uint &arg1, uint &arg2) {
189  register uint swp=arg1;
190  arg1=arg2; arg2=swp;
191  }
192
193 inline void swap(short &arg1, short &arg2) {
194  register short swp=arg1;
195  arg1=arg2; arg2=swp;
196  }
197
198 inline void swap(unsigned short &arg1, unsigned short &arg2) {
199  register unsigned short swp=arg1;
200  arg1=arg2; arg2=swp;
201  }
202
203 inline void swap(long &arg1, long &arg2) {
204  register long swp=arg1;
205  arg1=arg2; arg2=swp;
206  }
207
208 inline void swap(unsigned long &arg1, unsigned long &arg2) {
209  register unsigned long swp=arg1;
210  arg1=arg2; arg2=swp;
211  }
212
213
214 inline void swap(char &arg1, char &arg2) {
215  register char swp=arg1;
216  arg1=arg2; arg2=swp;
217  }
218
219 inline void swap(unsigned char &arg1, unsigned char &arg2) {
220  register unsigned char swp=arg1;
221  arg1=arg2; arg2=swp;
222  }
188  
189   /**************** Memory management ***************************/
190  
# Line 274 | 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
281 < 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 331 | 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 348 | 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 370 | Line 334
334    bool operator==(GSeg& d){
335        return (start==d.start && end==d.end);
336        }
373  bool operator>(GSeg& d){
374     return (start==d.start)?(end>d.end):(start>d.start);
375     }
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