Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
partons
core
elementary-utils
Commits
5bbcd614
Commit
5bbcd614
authored
Sep 27, 2016
by
Bryan Berthou
Browse files
refs#16
In ElementaryUtils (trunk) : - Refactor FileUtils : add open file mode.
parent
8c58af81
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/ElementaryUtils/file_utils/FileUtils.h
View file @
5bbcd614
...
...
@@ -28,17 +28,28 @@ public:
static
bool
isReadable
(
const
std
::
string
&
filePath
);
/**
* By default open a file in write mode.
* If the file exists its content is deleted.
*
* @param fileOutputStream
* @param filePath
* @param openMode : by default open in write mode and content is deleted.z
* @return
*/
static
bool
open
(
std
::
ofstream
&
fileOutputStream
,
const
std
::
string
&
filePath
);
static
void
writef
(
std
::
ofstream
&
fileOutputStream
,
const
std
::
string
&
filePath
,
const
std
::
ios_base
::
openmode
&
openMode
=
std
::
ios_base
::
out
|
std
::
ios_base
::
trunc
);
static
void
writeAndFlush
(
std
::
ofstream
&
fileOutputStream
,
const
std
::
string
&
str
);
static
void
write
(
std
::
ofstream
&
fileOutputStream
,
const
std
::
string
&
str
);
static
void
flush
(
std
::
ofstream
&
fileOutputStream
);
static
void
close
(
std
::
ofstream
&
fileOutputStream
);
static
void
write
(
const
std
::
string
&
filePath
,
const
std
::
string
&
str
);
static
void
writeLine
(
const
std
::
string
&
filePath
,
const
std
::
string
&
str
);
//
static void write(const std::string & filePath, const std::string & str);
//
static void writeLine(const std::string & filePath, const std::string & str);
static
std
::
string
read
(
const
std
::
string
&
filePath
);
static
std
::
vector
<
std
::
string
>
readByLine
(
const
std
::
string
&
filePath
);
static
std
::
ifstream
::
pos_type
getFileSize
(
const
std
::
string
&
filetPath
);
...
...
src/ElementaryUtils/file_utils/FileUtils.cpp
View file @
5bbcd614
...
...
@@ -13,21 +13,21 @@ bool FileUtils::isReadable(const std::string & filePath) {
return
!
file
.
fail
();
}
void
FileUtils
::
write
(
const
std
::
string
&
filePath
,
const
std
::
string
&
str
)
{
std
::
ofstream
file
(
filePath
.
c_str
(),
std
::
ios_base
::
app
);
if
(
file
)
{
file
<<
str
;
}
}
void
FileUtils
::
writeLine
(
const
std
::
string
&
filePath
,
const
std
::
string
&
str
)
{
std
::
ofstream
file
(
filePath
.
c_str
(),
std
::
ios_base
::
app
);
if
(
file
)
{
file
<<
str
<<
'\n'
;
}
}
//
void FileUtils::write(const std::string & filePath, const std::string & str) {
//
std::ofstream file(filePath.c_str(), std::ios_base::app);
//
//
if (file) {
//
file << str;
//
}
//
}
//
//
void FileUtils::writeLine(const std::string & filePath, const std::string & str) {
//
std::ofstream file(filePath.c_str(), std::ios_base::app);
//
//
if (file) {
//
file << str << '\n';
//
}
//
}
std
::
string
FileUtils
::
read
(
const
std
::
string
&
filePath
)
{
std
::
string
str
=
StringUtils
::
EMPTY
;
...
...
@@ -79,9 +79,8 @@ std::ifstream::pos_type FileUtils::getFileSize(const std::string & filetPath) {
}
bool
FileUtils
::
open
(
std
::
ofstream
&
fileOutputStream
,
const
std
::
string
&
filePath
)
{
fileOutputStream
.
open
(
filePath
.
c_str
(),
std
::
ofstream
::
out
|
std
::
ofstream
::
app
);
const
std
::
string
&
filePath
,
const
std
::
ios_base
::
openmode
&
openMode
)
{
fileOutputStream
.
open
(
filePath
.
c_str
(),
openMode
);
return
fileOutputStream
.
is_open
();
}
...
...
@@ -89,7 +88,7 @@ void FileUtils::write(std::ofstream& fileOutputStream, const std::string& str) {
fileOutputStream
<<
str
;
}
void
FileUtils
::
write
f
(
std
::
ofstream
&
fileOutputStream
,
void
FileUtils
::
write
AndFlush
(
std
::
ofstream
&
fileOutputStream
,
const
std
::
string
&
str
)
{
fileOutputStream
<<
str
;
FileUtils
::
flush
(
fileOutputStream
);
...
...
src/ElementaryUtils/logger/LoggerManager.cpp
View file @
5bbcd614
...
...
@@ -40,8 +40,6 @@ LoggerManager::~LoggerManager() {
// flush remaining buffer
flushBuffer
();
std
::
cerr
<<
"(LoggerManager::flushBuffer()) Buffer flushed"
<<
std
::
endl
;
//TODO close file when exception throw
FileUtils
::
close
(
m_fileOutputStream
);
...
...
@@ -250,7 +248,7 @@ void LoggerManager::writeConsole() {
}
void
LoggerManager
::
writeFile
()
{
FileUtils
::
write
f
(
m_fileOutputStream
,
m_buffer
);
FileUtils
::
write
AndFlush
(
m_fileOutputStream
,
m_buffer
);
}
void
LoggerManager
::
run
()
{
...
...
Write
Preview
Supports
Markdown
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