Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tlibs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Scientific Software
Takin
tlibs
Commits
259a143c
Commit
259a143c
authored
Feb 07, 2020
by
Tobias WEBER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file loading
parent
27d8a14c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
2 deletions
+32
-2
file/file.h
file/file.h
+32
-2
No files found.
file/file.h
View file @
259a143c
/**
* file helper
* @author Tobias Weber <t
obias.weber@tum.de
>
* @date 2013-20
16
* @author Tobias Weber <t
weber@ill.fr
>
* @date 2013-20
20
* @license GPLv2 or GPLv3
*/
...
...
@@ -59,6 +59,36 @@ inline std::size_t get_file_size(const std::basic_string<typename fs::path::valu
return
fs
::
file_size
(
fs
::
path
(
strFile
));
}
/**
* reads a part of the file in a buffer
* @param istr: input stream
* @param offs: file offset in bytes
* @param len: length in size of T
*/
template
<
class
T
,
class
t_char
=
char
>
std
::
pair
<
bool
,
std
::
shared_ptr
<
T
[]
>>
get_file_mem
(
std
::
basic_istream
<
t_char
>&
istr
,
std
::
size_t
offs
,
std
::
size_t
len
=
1
)
{
bool
ok
=
true
;
std
::
shared_ptr
<
T
[]
>
ptr
(
new
T
[
len
]);
if
(
!
ptr
)
return
std
::
make_pair
(
false
,
ptr
);
std
::
streampos
posOrig
=
istr
.
tellg
();
istr
.
seekg
(
offs
,
std
::
ios_base
::
beg
);
istr
.
read
((
char
*
)
ptr
.
get
(),
len
*
sizeof
(
T
));
if
(
istr
.
gcount
()
!=
len
*
sizeof
(
T
))
ok
=
false
;
// move back to original position
istr
.
seekg
(
posOrig
,
std
::
ios_base
::
beg
);
return
std
::
make_pair
(
ok
,
ptr
);
}
// ----------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment