Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
34cd1031
Commit
34cd1031
authored
13 years ago
by
Bienchen
Browse files
Options
Downloads
Patches
Plain Diff
Made StarParser sensible to problems on file opening.
parent
bb2b9454
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
modules/io/src/mol/star_parser.cc
+16
-2
16 additions, 2 deletions
modules/io/src/mol/star_parser.cc
modules/io/src/mol/star_parser.hh
+1
-0
1 addition, 0 deletions
modules/io/src/mol/star_parser.hh
modules/io/tests/test_star_parser.cc
+11
-1
11 additions, 1 deletion
modules/io/tests/test_star_parser.cc
with
28 additions
and
3 deletions
modules/io/src/mol/star_parser.cc
+
16
−
2
View file @
34cd1031
...
...
@@ -33,18 +33,23 @@ namespace ost { namespace io {
StarParser
::
StarParser
(
std
::
istream
&
stream
,
bool
items_as_row
)
:
filename_
(
"<stream>"
),
line_num_
(
0
),
has_current_line_
(
false
),
current_line_
(),
items_row_header_
(),
items_row_columns_
(),
items_row_header_
(),
file_open_
(
true
),
items_row_columns_
(),
items_row_values_
()
{
items_as_row_
=
items_as_row
;
if
(
!
stream
)
{
file_open_
=
false
;
}
stream_
.
push
(
stream
);
}
StarParser
::
StarParser
(
const
String
&
filename
,
bool
items_as_row
)
:
fstream_
(
filename
.
c_str
()),
filename_
(
filename
),
line_num_
(
0
),
has_current_line_
(
false
),
current_line_
(),
items_row_header_
(),
items_row_columns_
(),
items_row_values_
()
items_row_header_
(),
file_open_
(
true
),
items_row_columns_
(),
items_row_values_
()
{
items_as_row_
=
items_as_row
;
...
...
@@ -54,6 +59,10 @@ StarParser::StarParser(const String& filename, bool items_as_row):
}
stream_
.
push
(
fstream_
);
if
(
!
fstream_
)
{
file_open_
=
false
;
}
}
String
StarParser
::
FormatDiagnostic
(
StarDiagType
type
,
const
String
&
message
,
...
...
@@ -536,6 +545,11 @@ void StarParser::ParseGlobal()
void
StarParser
::
Parse
()
{
if
(
!
file_open_
)
{
throw
IOException
(
this
->
FormatDiagnostic
(
STAR_DIAG_ERROR
,
"Failed to open file '"
+
filename_
+
"'!"
));
}
StringRef
line
;
std
::
stringstream
ss
;
while
(
this
->
GetLine
(
line
))
{
...
...
This diff is collapsed.
Click to expand it.
modules/io/src/mol/star_parser.hh
+
1
−
0
View file @
34cd1031
...
...
@@ -277,6 +277,7 @@ private:
String
current_line_
;
bool
items_as_row_
;
StarLoopDesc
items_row_header_
;
bool
file_open_
;
std
::
vector
<
StringRef
>
items_row_columns_
;
std
::
vector
<
String
>
items_row_values_
;
};
...
...
This diff is collapsed.
Click to expand it.
modules/io/tests/test_star_parser.cc
+
11
−
1
View file @
34cd1031
...
...
@@ -238,11 +238,12 @@ BOOST_AUTO_TEST_CASE(star_data_item)
BOOST_MESSAGE
(
" Running star_data_item tests..."
);
std
::
ifstream
s
(
"testfiles/data-item.cif"
);
DataItemTestParser
star_p
(
s
);
star_p
.
Parse
();
BOOST_CHECK_NO_THROW
(
star_p
.
Parse
()
)
;
BOOST_CHECK_EQUAL
(
star_p
.
s1
,
"a"
);
BOOST_CHECK_EQUAL
(
star_p
.
s2
,
"a b c"
);
BOOST_CHECK_EQUAL
(
star_p
.
s3
,
"a
\n
b
\n
c"
);
BOOST_CHECK_EQUAL
(
star_p
.
s4
,
"a'b"
);
BOOST_MESSAGE
(
" done."
);
}
BOOST_AUTO_TEST_CASE
(
format_diag_stream
)
...
...
@@ -450,5 +451,14 @@ BOOST_AUTO_TEST_CASE(star_try_bool_conversions)
IOException
);
BOOST_MESSAGE
(
" done."
);
}
BOOST_AUTO_TEST_CASE
(
star_wrong_filename
)
{
BOOST_MESSAGE
(
" Running star_wrong_filename tests..."
);
DataItemTestParser
star_p
(
"testfiles/doesnotexist.foo"
);
BOOST_CHECK_THROW
(
star_p
.
Parse
(),
IOException
);
BOOST_MESSAGE
(
" done."
);
}
BOOST_AUTO_TEST_SUITE_END
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment