Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
data_importer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IA2
data_importer
Commits
13f5aafd
Commit
13f5aafd
authored
11 years ago
by
Marco De Marco
Browse files
Options
Downloads
Patches
Plain Diff
Clean up method added to file wrapper
parent
091f50bd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/FileWrapper.cpp
+29
-13
29 additions, 13 deletions
src/FileWrapper.cpp
src/FileWrapper.h
+11
-3
11 additions, 3 deletions
src/FileWrapper.h
with
40 additions
and
16 deletions
src/FileWrapper.cpp
+
29
−
13
View file @
13f5aafd
...
@@ -11,30 +11,30 @@ FileWrapper::FileWrapper(Tango::DeviceImpl* deviceImpl_p,
...
@@ -11,30 +11,30 @@ FileWrapper::FileWrapper(Tango::DeviceImpl* deviceImpl_p,
std
::
string
fileName
,
boost
::
uint64_t
totalFileSize
)
throw
(
std
::
logic_error
)
std
::
string
fileName
,
boost
::
uint64_t
totalFileSize
)
throw
(
std
::
logic_error
)
:
Tango
::
LogAdapter
(
deviceImpl_p
),
m_storagePath
(
storagePath
),
:
Tango
::
LogAdapter
(
deviceImpl_p
),
m_storagePath
(
storagePath
),
m_filePath
(
filePath
),
m_fileVersion
(
fileVersion
),
m_fileName
(
fileName
),
m_filePath
(
filePath
),
m_fileVersion
(
fileVersion
),
m_fileName
(
fileName
),
m_
total
FileSize
(
totalFileSize
)
m_
expected
FileSize
(
totalFileSize
)
{
{
DEBUG_STREAM
<<
"FileWrapper::FileWrapper()"
<<
endl
;
DEBUG_STREAM
<<
"FileWrapper::FileWrapper()"
<<
endl
;
boost
::
filesystem
::
path
destPath
(
storagePath
)
;
m_outputFilePath
/=
storagePath
;
dest
Path
/=
filePath
;
m_outputFile
Path
/=
filePath
;
std
::
stringstream
fileStream
;
std
::
stringstream
fileStream
;
fileStream
<<
"/"
<<
fileVersion
;
fileStream
<<
"/"
<<
fileVersion
;
dest
Path
/=
fileStream
.
str
();
m_outputFile
Path
/=
fileStream
.
str
();
if
(
!
boost
::
filesystem
::
exists
(
dest
Path
))
if
(
!
boost
::
filesystem
::
exists
(
m_outputFile
Path
))
boost
::
filesystem
::
create_directories
(
dest
Path
);
boost
::
filesystem
::
create_directories
(
m_outputFile
Path
);
if
(
!
boost
::
filesystem
::
is_directory
(
dest
Path
))
if
(
!
boost
::
filesystem
::
is_directory
(
m_outputFile
Path
))
throw
std
::
logic_error
(
"Destination path
\'
"
throw
std
::
logic_error
(
"Destination path
\'
"
+
dest
Path
.
string
()
+
"
\'
is not a directory"
);
+
m_outputFile
Path
.
string
()
+
"
\'
is not a directory"
);
dest
Path
/=
fileName
;
m_outputFile
Path
/=
fileName
;
m_outputFileStream
.
open
(
dest
Path
.
string
(),
std
::
ios
::
binary
);
m_outputFileStream
.
open
(
m_outputFile
Path
.
string
(),
std
::
ios
::
binary
);
}
}
//==============================================================================
//==============================================================================
...
@@ -122,7 +122,7 @@ bool FileWrapper::isBad()
...
@@ -122,7 +122,7 @@ bool FileWrapper::isBad()
//==============================================================================
//==============================================================================
bool
FileWrapper
::
isCompleted
()
bool
FileWrapper
::
isCompleted
()
{
{
return
(
boost
::
uint64_t
)
m_outputFileStream
.
tellp
()
>=
m_
total
FileSize
;
return
(
boost
::
uint64_t
)
m_outputFileStream
.
tellp
()
>=
m_
expected
FileSize
;
}
}
//==============================================================================
//==============================================================================
...
@@ -130,15 +130,31 @@ bool FileWrapper::isCompleted()
...
@@ -130,15 +130,31 @@ bool FileWrapper::isCompleted()
//==============================================================================
//==============================================================================
boost
::
uint64_t
FileWrapper
::
getLeftToWrite
()
boost
::
uint64_t
FileWrapper
::
getLeftToWrite
()
{
{
return
m_
total
FileSize
-
(
boost
::
uint64_t
)
m_outputFileStream
.
tellp
();
return
m_
expected
FileSize
-
(
boost
::
uint64_t
)
m_outputFileStream
.
tellp
();
}
}
//==============================================================================
//==============================================================================
// FileWrapper::
read
()
// FileWrapper::
write
()
//==============================================================================
//==============================================================================
void
FileWrapper
::
write
(
std
::
vector
<
char
>&
writeBuff
,
boost
::
uint64_t
&
recvBytes
)
void
FileWrapper
::
write
(
std
::
vector
<
char
>&
writeBuff
,
boost
::
uint64_t
&
recvBytes
)
{
{
m_outputFileStream
.
write
(
&
writeBuff
[
0
],
(
std
::
streamsize
)
recvBytes
);
m_outputFileStream
.
write
(
&
writeBuff
[
0
],
(
std
::
streamsize
)
recvBytes
);
}
}
//==============================================================================
// FileWrapper::cleanUp()
//==============================================================================
void
FileWrapper
::
cleanUp
()
{
DEBUG_STREAM
<<
"FileWrapper::cleanUp()"
<<
endl
;
if
(
m_outputFileStream
.
is_open
())
m_outputFileStream
.
close
();
boost
::
system
::
error_code
errorCode
;
if
(
boost
::
filesystem
::
exists
(
m_outputFilePath
))
boost
::
filesystem
::
remove
(
m_outputFilePath
,
errorCode
);
}
}
}
//namespace
This diff is collapsed.
Click to expand it.
src/FileWrapper.h
+
11
−
3
View file @
13f5aafd
...
@@ -64,6 +64,11 @@ public:
...
@@ -64,6 +64,11 @@ public:
virtual
void
write
(
std
::
vector
<
char
>&
,
boost
::
uint64_t
&
);
virtual
void
write
(
std
::
vector
<
char
>&
,
boost
::
uint64_t
&
);
//------------------------------------------------------------------------------
// [Public] Clean up method
//------------------------------------------------------------------------------
virtual
void
cleanUp
();
protected
:
protected
:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// [Protected] Class variables
// [Protected] Class variables
...
@@ -80,10 +85,13 @@ protected:
...
@@ -80,10 +85,13 @@ protected:
//File name property
//File name property
const
std
::
string
m_fileName
;
const
std
::
string
m_fileName
;
//Input file size
//Expected file size
boost
::
uint64_t
m_totalFileSize
;
boost
::
uint64_t
m_expectedFileSize
;
//Output file path
boost
::
filesystem
::
path
m_outputFilePath
;
//
In
put file stream
//
Out
put file stream
std
::
ofstream
m_outputFileStream
;
std
::
ofstream
m_outputFileStream
;
};
};
...
...
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