Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
b2bd3b20
Commit
b2bd3b20
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
functional_write -> stream2file
parent
636bab2c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1629
IO further cleanup
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Device/IO/IOFactory.cpp
+10
-7
10 additions, 7 deletions
Device/IO/IOFactory.cpp
with
10 additions
and
7 deletions
Device/IO/IOFactory.cpp
+
10
−
7
View file @
b2bd3b20
...
@@ -76,7 +76,7 @@ std::stringstream file2stream(const std::string& file_name)
...
@@ -76,7 +76,7 @@ std::stringstream file2stream(const std::string& file_name)
return
str
;
return
str
;
}
}
void
functional_writ
e
(
const
std
::
string
&
file_name
,
std
::
function
<
void
(
std
::
ostream
&
)
>
writeData
)
void
stream2fil
e
(
const
std
::
string
&
file_name
,
std
::
stringstream
&
s
)
{
{
using
namespace
DataUtil
::
Format
;
using
namespace
DataUtil
::
Format
;
...
@@ -95,15 +95,13 @@ void functional_write(const std::string& file_name, std::function<void(std::ostr
...
@@ -95,15 +95,13 @@ void functional_write(const std::string& file_name, std::function<void(std::ostr
throw
std
::
runtime_error
(
"Cannot open file for writing: "
+
file_name
);
throw
std
::
runtime_error
(
"Cannot open file for writing: "
+
file_name
);
if
(
!
fout
.
good
())
if
(
!
fout
.
good
())
throw
std
::
runtime_error
(
"File is not good, probably it is a directory: "
+
file_name
);
throw
std
::
runtime_error
(
"File is not good, probably it is a directory: "
+
file_name
);
std
::
stringstream
ss
;
writeData
(
ss
);
boost
::
iostreams
::
filtering_streambuf
<
boost
::
iostreams
::
input
>
input_filtered
;
boost
::
iostreams
::
filtering_streambuf
<
boost
::
iostreams
::
input
>
input_filtered
;
if
(
DataUtil
::
Format
::
isGZipped
(
file_name
))
if
(
DataUtil
::
Format
::
isGZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
gzip_compressor
());
input_filtered
.
push
(
boost
::
iostreams
::
gzip_compressor
());
else
if
(
DataUtil
::
Format
::
isBZipped
(
file_name
))
else
if
(
DataUtil
::
Format
::
isBZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
bzip2_compressor
());
input_filtered
.
push
(
boost
::
iostreams
::
bzip2_compressor
());
input_filtered
.
push
(
s
s
);
input_filtered
.
push
(
s
);
boost
::
iostreams
::
copy
(
input_filtered
,
fout
);
boost
::
iostreams
::
copy
(
input_filtered
,
fout
);
...
@@ -149,14 +147,19 @@ Datafield* IOFactory::readReflectometryData(const std::string& file_name)
...
@@ -149,14 +147,19 @@ Datafield* IOFactory::readReflectometryData(const std::string& file_name)
void
IOFactory
::
writeDatafield
(
const
Datafield
&
data
,
const
std
::
string
&
file_name
)
void
IOFactory
::
writeDatafield
(
const
Datafield
&
data
,
const
std
::
string
&
file_name
)
{
{
try
{
try
{
std
::
stringstream
s
;
if
(
DataUtil
::
Format
::
isIntFile
(
file_name
))
if
(
DataUtil
::
Format
::
isIntFile
(
file_name
))
functional_write
(
file_name
,
[
&
](
std
::
ostream
&
s
)
{
IO
::
writeBAInt
(
data
,
s
);
});
IO
::
writeBAInt
(
data
,
s
);
#ifdef BA_TIFF_SUPPORT
#ifdef BA_TIFF_SUPPORT
else
if
(
DataUtil
::
Format
::
isTiffFile
(
file_name
))
else
if
(
DataUtil
::
Format
::
isTiffFile
(
file_name
))
functional_write
(
file_name
,
[
&
](
std
::
ostream
&
s
)
{
IO
::
writeTiff
(
data
,
s
);
});
IO
::
writeTiff
(
data
,
s
);
#endif
#endif
else
else
functional_write
(
file_name
,
[
&
](
std
::
ostream
&
s
)
{
IO
::
writeNumpyTxt
(
data
,
s
);
});
IO
::
writeNumpyTxt
(
data
,
s
);
stream2file
(
file_name
,
s
);
}
catch
(
const
std
::
exception
&
ex
)
{
}
catch
(
const
std
::
exception
&
ex
)
{
throw
std
::
runtime_error
(
"Failed writing to "
+
file_name
+
": "
+
ex
.
what
());
throw
std
::
runtime_error
(
"Failed writing to "
+
file_name
+
": "
+
ex
.
what
());
}
}
...
...
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