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
636bab2c
Commit
636bab2c
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
functional_write -> local ns
parent
053d89a3
No related branches found
No related tags found
1 merge request
!1629
IO further cleanup
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Device/IO/IOFactory.cpp
+34
-72
34 additions, 72 deletions
Device/IO/IOFactory.cpp
Device/IO/IOFactory.h
+0
-6
0 additions, 6 deletions
Device/IO/IOFactory.h
with
34 additions
and
78 deletions
Device/IO/IOFactory.cpp
+
34
−
72
View file @
636bab2c
...
@@ -76,6 +76,40 @@ std::stringstream file2stream(const std::string& file_name)
...
@@ -76,6 +76,40 @@ std::stringstream file2stream(const std::string& file_name)
return
str
;
return
str
;
}
}
void
functional_write
(
const
std
::
string
&
file_name
,
std
::
function
<
void
(
std
::
ostream
&
)
>
writeData
)
{
using
namespace
DataUtil
::
Format
;
std
::
ofstream
fout
;
std
::
ios_base
::
openmode
openmode
=
std
::
ios
::
out
;
if
(
isTiffFile
(
file_name
)
||
isCompressed
(
file_name
))
openmode
=
std
::
ios
::
out
|
std
::
ios_base
::
binary
;
#ifdef _WIN32
fout
.
open
(
BaseUtil
::
Filesystem
::
convert_utf8_to_utf16
(
file_name
),
openmode
);
#else
fout
.
open
(
file_name
,
openmode
);
#endif
if
(
!
fout
.
is_open
())
throw
std
::
runtime_error
(
"Cannot open file for writing: "
+
file_name
);
if
(
!
fout
.
good
())
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
;
if
(
DataUtil
::
Format
::
isGZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
gzip_compressor
());
else
if
(
DataUtil
::
Format
::
isBZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
bzip2_compressor
());
input_filtered
.
push
(
ss
);
boost
::
iostreams
::
copy
(
input_filtered
,
fout
);
fout
.
close
();
}
}
// namespace
}
// namespace
Datafield
*
IOFactory
::
readDatafield
(
const
std
::
string
&
file_name
,
LoaderSelector
selector
)
Datafield
*
IOFactory
::
readDatafield
(
const
std
::
string
&
file_name
,
LoaderSelector
selector
)
...
@@ -128,41 +162,6 @@ void IOFactory::writeDatafield(const Datafield& data, const std::string& file_na
...
@@ -128,41 +162,6 @@ void IOFactory::writeDatafield(const Datafield& data, const std::string& file_na
}
}
}
}
void
IOFactory
::
functional_write
(
const
std
::
string
&
file_name
,
std
::
function
<
void
(
std
::
ostream
&
)
>
writeData
)
{
using
namespace
DataUtil
::
Format
;
std
::
ofstream
fout
;
std
::
ios_base
::
openmode
openmode
=
std
::
ios
::
out
;
if
(
isTiffFile
(
file_name
)
||
isCompressed
(
file_name
))
openmode
=
std
::
ios
::
out
|
std
::
ios_base
::
binary
;
#ifdef _WIN32
fout
.
open
(
BaseUtil
::
Filesystem
::
convert_utf8_to_utf16
(
file_name
),
openmode
);
#else
fout
.
open
(
file_name
,
openmode
);
#endif
if
(
!
fout
.
is_open
())
throw
std
::
runtime_error
(
"Cannot open file for writing: "
+
file_name
);
if
(
!
fout
.
good
())
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
;
if
(
DataUtil
::
Format
::
isGZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
gzip_compressor
());
else
if
(
DataUtil
::
Format
::
isBZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
bzip2_compressor
());
input_filtered
.
push
(
ss
);
boost
::
iostreams
::
copy
(
input_filtered
,
fout
);
fout
.
close
();
}
bool
IOFactory
::
fileTypeMatchesLoaderSelector
(
const
std
::
string
&
fileName
,
LoaderSelector
selector
)
bool
IOFactory
::
fileTypeMatchesLoaderSelector
(
const
std
::
string
&
fileName
,
LoaderSelector
selector
)
{
{
switch
(
selector
)
{
switch
(
selector
)
{
...
@@ -179,43 +178,6 @@ bool IOFactory::fileTypeMatchesLoaderSelector(const std::string& fileName, Loade
...
@@ -179,43 +178,6 @@ bool IOFactory::fileTypeMatchesLoaderSelector(const std::string& fileName, Loade
return
false
;
return
false
;
}
}
Datafield
*
IOFactory
::
functional_read
(
const
std
::
string
&
file_name
,
std
::
function
<
Datafield
*
(
std
::
istream
&
)
>
readData
)
{
if
(
!
BaseUtil
::
Filesystem
::
IsFileExists
(
file_name
))
throw
std
::
runtime_error
(
"File does not exist: "
+
file_name
);
using
namespace
DataUtil
::
Format
;
std
::
ifstream
input_stream
;
std
::
ios_base
::
openmode
openmode
=
std
::
ios
::
in
;
if
(
isTiffFile
(
file_name
)
||
isCompressed
(
file_name
))
openmode
=
std
::
ios
::
in
|
std
::
ios_base
::
binary
;
#ifdef _WIN32
input_stream
.
open
(
BaseUtil
::
Filesystem
::
convert_utf8_to_utf16
(
file_name
),
openmode
);
#else
input_stream
.
open
(
file_name
,
openmode
);
#endif
if
(
!
input_stream
.
is_open
())
throw
std
::
runtime_error
(
"Cannot open file for reading: "
+
file_name
);
if
(
!
input_stream
.
good
())
throw
std
::
runtime_error
(
"File is not good, probably it is a directory:"
+
file_name
);
boost
::
iostreams
::
filtering_streambuf
<
boost
::
iostreams
::
input
>
input_filtered
;
if
(
DataUtil
::
Format
::
isGZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
gzip_decompressor
());
else
if
(
DataUtil
::
Format
::
isBZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
bzip2_decompressor
());
input_filtered
.
push
(
input_stream
);
// we use stringstream since it provides random access which is important for tiff files
std
::
stringstream
str
;
boost
::
iostreams
::
copy
(
input_filtered
,
str
);
return
readData
(
str
);
}
bool
IOUtil
::
filesAgree
(
const
std
::
string
&
datFileName
,
const
std
::
string
&
refFileName
,
double
tol
)
bool
IOUtil
::
filesAgree
(
const
std
::
string
&
datFileName
,
const
std
::
string
&
refFileName
,
double
tol
)
{
{
std
::
unique_ptr
<
Datafield
>
datDat
;
std
::
unique_ptr
<
Datafield
>
datDat
;
...
...
This diff is collapsed.
Click to expand it.
Device/IO/IOFactory.h
+
0
−
6
View file @
636bab2c
...
@@ -60,12 +60,6 @@ public:
...
@@ -60,12 +60,6 @@ public:
static
void
writeDatafield
(
const
Datafield
&
data
,
const
std
::
string
&
file_name
);
static
void
writeDatafield
(
const
Datafield
&
data
,
const
std
::
string
&
file_name
);
private
:
private
:
static
Datafield
*
functional_read
(
const
std
::
string
&
file_name
,
std
::
function
<
Datafield
*
(
std
::
istream
&
)
>
readData
);
static
void
functional_write
(
const
std
::
string
&
file_name
,
std
::
function
<
void
(
std
::
ostream
&
)
>
writeData
);
static
bool
fileTypeMatchesLoaderSelector
(
const
std
::
string
&
fileName
,
LoaderSelector
selector
);
static
bool
fileTypeMatchesLoaderSelector
(
const
std
::
string
&
fileName
,
LoaderSelector
selector
);
};
};
...
...
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