aboutsummaryrefslogtreecommitdiffstats
path: root/biology/ssaha/files/patch-GlobalDefinitions.h
blob: 49d686d331b5edfb01a41cb7f26c849ae590c5a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--- ./Global/GlobalDefinitions.h.orig   2004-03-01 13:51:28.000000000 -0300
+++ ./Global/GlobalDefinitions.h    2008-06-12 15:39:31.000000000 -0300
@@ -79,7 +79,8 @@
 #include <map>
 #include <utility>
 #include <sys/types.h>
-#include <stdio.h>
+#include <cstdio>
+#include <cstring>
 #include <sys/file.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -726,8 +727,6 @@
 template <typename T> class Allocator
 {
 public:
-  typedef T MyType;
-
   Allocator( T** ptr, const string& name, ostream& monStream=cerr ) : 
     ptr_(ptr), name_(name), size_(0), isAllocated_(false), 
     monStream_( monStream )
@@ -788,32 +787,34 @@
  
   virtual void allocate( unsigned long size )
   {
-    size_=size;
-    (*ptr_)=new T[size_];
-    isAllocated_=true;
+    Allocator<T>::size_=size;
+    (*Allocator<T>::ptr_)=new T[Allocator<T>::size_];
+    Allocator<T>::isAllocated_=true;
   }
 
   virtual void allocateAndZero( unsigned long size ) 
   {
     const unsigned char zero(0);
     allocate(size);
-    memset( (void*)(*ptr_), zero, size_*sizeof(MyType) );
+    memset( (void*)(*Allocator<T>::ptr_), zero, Allocator<T>::size_*sizeof(T) );
   }
   virtual void load( unsigned long size )
   {
     allocate(size);
-    loadFromFile( name_, (char*)(*ptr_), size_*sizeof(MyType), monStream_ );
+    loadFromFile( Allocator<T>::name_, (char*)(*Allocator<T>::ptr_),
+        Allocator<T>::size_*sizeof(T), Allocator<T>::monStream_ );
   }
   virtual void save()
   {
-    saveToFile( name_, (char*)(*ptr_), size_*sizeof(MyType), monStream_ );
+    saveToFile( Allocator<T>::name_, (char*)(*Allocator<T>::ptr_),
+        Allocator<T>::size_*sizeof(T), Allocator<T>::monStream_ );
   }
 
   virtual void deallocate()
   {
-    if (!isAllocated_) return;
-    delete [] (*ptr_);
-    isAllocated_=false;
+    if (!Allocator<T>::isAllocated_) return;
+    delete [] (*Allocator<T>::ptr_);
+    Allocator<T>::isAllocated_=false;
   }
 protected:
 };
@@ -892,7 +893,7 @@
     if (isAllocated_) return;
     mode_ = MemoryMapper::createMap;
     size_ = size;
-    (*ptr_) = (T*) linkToMap(mode_,name_,size_*sizeof(MyType));
+    (*ptr_) = (T*) linkToMap(mode_,name_,size_*sizeof(T));
     isAllocated_ = true;
   }
 
@@ -908,7 +909,7 @@
     if (isAllocated_) return;
     mode_ = MemoryMapper::readMap;
     size_ = size;
-    (*ptr_) = (T*) linkToMap(mode_,name_,size_*sizeof(MyType));
+    (*ptr_) = (T*) linkToMap(mode_,name_,size_*sizeof(T));
     isAllocated_ = true;
   }
 
@@ -921,7 +922,7 @@
   virtual void deallocate()
   {
     if (!isAllocated_) return;
-    if(munmap((caddr_t)(*ptr_), size_*sizeof(MyType)) < 0)
+    if(munmap((caddr_t)(*ptr_), size_*sizeof(T)) < 0)
       perror("unmap error"); // don't throw - called from destructor!
     close(fileDesc_);
     if (mode_.deleteFileOnExit) shm_unlink(name_.c_str());