@@ -39,18 +39,16 @@ int clustal_state::CheckAlignment(std::istream* origin)
39
39
origin->seekg (0 );
40
40
origin->clear ();
41
41
char *firstWord = nullptr , *line = nullptr ;
42
-
42
+ std::string buffer;
43
43
44
44
/* Read first valid line in a safer way */
45
45
do {
46
- delete[] line;
47
- line = utils::readLine (*origin);
46
+ line = utils::readLine (*origin, buffer);
48
47
} while ((line == nullptr ) && (!origin->eof ()));
49
48
50
49
/* If the file end is reached without a valid line, warn about it */
51
50
if (origin->eof ())
52
51
{
53
- delete [] line;
54
52
return false ;
55
53
}
56
54
@@ -60,33 +58,22 @@ int clustal_state::CheckAlignment(std::istream* origin)
60
58
/* Clustal Format */
61
59
if ((!strcmp (firstWord, " CLUSTAL" )) || (!strcmp (firstWord, " clustal" )))
62
60
{
63
- delete [] line;
64
61
return 1 ;
65
62
}
66
-
67
- delete[] line;
68
63
69
64
return 0 ;
70
65
}
71
66
72
- Alignment* clustal_state::LoadAlignment (const std::string &filename )
67
+ Alignment* clustal_state::LoadAlignment (std::istream &file )
73
68
{
74
69
Alignment* alignment = new Alignment ();
75
70
int i, seqLength, pos, firstBlock;
76
71
char *str, *line = nullptr ;
77
- std::ifstream file;
78
- file.open (filename, std::ifstream::in);
79
-
80
- /* Store some details about input file to be used in posterior format
81
- * conversions */
82
- // alignment.filename.append("!Title ");
83
- alignment->filename .append (filename);
84
- alignment->filename .append (" ;" );
72
+ std::string buffer;
85
73
86
74
/* The first valid line corresponding to CLUSTAL label is ignored */
87
75
do {
88
- delete [] line;
89
- line = utils::readLine (file);
76
+ line = utils::readLine (file, buffer);
90
77
} while ((line == nullptr ) && (!file.eof ()));
91
78
92
79
/* If the file end is reached without a valid line, warn about it */
@@ -95,12 +82,8 @@ Alignment* clustal_state::LoadAlignment(const std::string &filename)
95
82
96
83
/* Ignore blank lines before first sequence block starts */
97
84
while (!file.eof ()) {
98
-
99
- /* Deallocate previously used dynamic memory */
100
- delete [] line;
101
-
102
85
/* Read lines in safe way */
103
- line = utils::readLine (file);
86
+ line = utils::readLine (file, buffer );
104
87
105
88
if (line != nullptr )
106
89
break ;
@@ -130,15 +113,10 @@ Alignment* clustal_state::LoadAlignment(const std::string &filename)
130
113
break ;
131
114
alignment->numberOfSequences ++;
132
115
133
- /* Deallocate previously used dynamic memory */
134
- delete [] line;
135
-
136
116
/* Read lines in safe way */
137
- line = utils::readLine (file);
117
+ line = utils::readLine (file, buffer );
138
118
}
139
119
140
- delete [] line;
141
-
142
120
/* Finish to preprocess the input file. */
143
121
file.clear ();
144
122
file.seekg (0 );
@@ -148,19 +126,16 @@ Alignment* clustal_state::LoadAlignment(const std::string &filename)
148
126
alignment->sequences = new std::string[alignment->numberOfSequences ];
149
127
150
128
/* Read the title line and store it */
151
- line = utils::readLine (file);
129
+ line = utils::readLine (file, buffer );
152
130
if (line == nullptr )
153
131
return nullptr ;
154
132
alignment->alignmentInfo .append (line, strlen (line));
155
133
156
134
/* Ignore blank lines before first sequence block starts */
157
135
while (!file.eof ()) {
158
136
159
- /* Deallocate previously used dynamic memory */
160
- delete [] line;
161
-
162
137
/* Read lines in safe way */
163
- line = utils::readLine (file);
138
+ line = utils::readLine (file, buffer );
164
139
165
140
if (line != nullptr )
166
141
break ;
@@ -181,7 +156,7 @@ Alignment* clustal_state::LoadAlignment(const std::string &filename)
181
156
if (i == 0 )
182
157
firstBlock = false ;
183
158
/* Read current line and analyze it*/
184
- line = utils::readLine (file);
159
+ line = utils::readLine (file, buffer );
185
160
continue ;
186
161
}
187
162
@@ -196,11 +171,8 @@ Alignment* clustal_state::LoadAlignment(const std::string &filename)
196
171
if (pos == seqLength) {
197
172
firstBlock = false ;
198
173
199
- /* Deallocate dinamic memory if it has been used before */
200
- delete [] line;
201
-
202
174
/* Read current line and analyze it*/
203
- line = utils::readLine (file);
175
+ line = utils::readLine (file, buffer );
204
176
205
177
continue ;
206
178
}
@@ -220,19 +192,10 @@ Alignment* clustal_state::LoadAlignment(const std::string &filename)
220
192
i = (i + 1 ) % alignment->numberOfSequences ;
221
193
}
222
194
223
- /* Deallocate dinamic memory if it has been used before */
224
- delete [] line;
225
-
226
195
/* Read current line and analyze it*/
227
- line = utils::readLine (file);
196
+ line = utils::readLine (file, buffer );
228
197
}
229
198
230
- /* Close the input file */
231
- file.close ();
232
-
233
- /* Deallocate dinamic memory */
234
- delete [] line;
235
-
236
199
/* Check the matrix's content */
237
200
alignment->fillMatrices (true );
238
201
alignment->originalNumberOfSequences = alignment->numberOfSequences ;
0 commit comments