Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yuhao Liu
ogs
Commits
88be462e
Commit
88be462e
authored
12 years ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
Style.
parent
48bcf28b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
BaseLib/FileTools.cpp
+12
-18
12 additions, 18 deletions
BaseLib/FileTools.cpp
BaseLib/FileTools.h
+8
-9
8 additions, 9 deletions
BaseLib/FileTools.h
with
20 additions
and
27 deletions
BaseLib/FileTools.cpp
+
12
−
18
View file @
88be462e
/**
/**
* \file
* \author Lars Bilke
* \date Apr. 2010
* \brief Filename manipulation routines implementation.
*
* \copyright
* Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org)
* Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
* http://www.opengeosys.org/project/license
*
*
*
* \file FileTools.cpp
*
* Created on 2010-04-26 by Lars Bilke
*
*/
*/
#include
"FileTools.h"
#include
"FileTools.h"
...
@@ -18,7 +19,6 @@
...
@@ -18,7 +19,6 @@
namespace
BaseLib
namespace
BaseLib
{
{
/**
/**
* Returns true if given file exists. From http://www.techbytes.ca/techbyte103.html
* Returns true if given file exists. From http://www.techbytes.ca/techbyte103.html
*/
*/
...
@@ -32,13 +32,10 @@ bool IsFileExisting(const std::string &strFilename)
...
@@ -32,13 +32,10 @@ bool IsFileExisting(const std::string &strFilename)
intStat
=
stat
(
strFilename
.
c_str
(),
&
stFileInfo
);
intStat
=
stat
(
strFilename
.
c_str
(),
&
stFileInfo
);
if
(
intStat
==
0
)
if
(
intStat
==
0
)
{
// We were able to get the file attributes
// We were able to get the file attributes
// so the file obviously exists.
// so the file obviously exists.
blnReturn
=
true
;
blnReturn
=
true
;
}
else
else
{
// We were not able to get the file attributes.
// We were not able to get the file attributes.
// This may mean that we don't have permission to
// This may mean that we don't have permission to
// access the folder which contains this file. If you
// access the folder which contains this file. If you
...
@@ -46,9 +43,8 @@ bool IsFileExisting(const std::string &strFilename)
...
@@ -46,9 +43,8 @@ bool IsFileExisting(const std::string &strFilename)
// return values of stat which will give you
// return values of stat which will give you
// more details on why stat failed.
// more details on why stat failed.
blnReturn
=
false
;
blnReturn
=
false
;
}
return
(
blnReturn
)
;
return
blnReturn
;
}
}
/**
/**
...
@@ -56,8 +52,8 @@ bool IsFileExisting(const std::string &strFilename)
...
@@ -56,8 +52,8 @@ bool IsFileExisting(const std::string &strFilename)
*/
*/
void
truncateFile
(
std
::
string
const
&
filename
)
void
truncateFile
(
std
::
string
const
&
filename
)
{
{
std
::
ofstream
ofs
(
filename
.
c_str
(),
std
::
ios_base
::
trunc
);
std
::
ofstream
ofs
(
filename
.
c_str
(),
std
::
ios_base
::
trunc
);
ofs
.
close
();
ofs
.
close
();
}
}
/** Finds the position of last file path separator.
/** Finds the position of last file path separator.
...
@@ -93,7 +89,7 @@ std::string dropFileExtension(std::string const& filename)
...
@@ -93,7 +89,7 @@ std::string dropFileExtension(std::string const& filename)
std
::
string
extractBaseName
(
std
::
string
const
&
pathname
)
std
::
string
extractBaseName
(
std
::
string
const
&
pathname
)
{
{
const
size_t
p
=
findLastPathSeparator
(
pathname
);
const
size_t
p
=
findLastPathSeparator
(
pathname
);
return
pathname
.
substr
(
p
+
1
);
return
pathname
.
substr
(
p
+
1
);
}
}
std
::
string
extractBaseNameWithoutExtension
(
std
::
string
const
&
pathname
)
std
::
string
extractBaseNameWithoutExtension
(
std
::
string
const
&
pathname
)
...
@@ -113,14 +109,14 @@ std::string getFileExtension(const std::string &path)
...
@@ -113,14 +109,14 @@ std::string getFileExtension(const std::string &path)
bool
hasFileExtension
(
std
::
string
const
&
extension
,
std
::
string
const
&
filename
)
bool
hasFileExtension
(
std
::
string
const
&
extension
,
std
::
string
const
&
filename
)
{
{
std
::
string
ext
=
stringToUpper
(
extension
);
// Copy for modification.
std
::
string
ext
=
stringToUpper
(
extension
);
// Copy for modification.
std
::
string
file_ext
=
stringToUpper
(
getFileExtension
(
filename
));
std
::
string
file_ext
=
stringToUpper
(
getFileExtension
(
filename
));
return
ext
==
file_ext
;
return
ext
==
file_ext
;
}
}
std
::
string
copyPathToFileName
(
const
std
::
string
&
file_name
,
std
::
string
copyPathToFileName
(
const
std
::
string
&
file_name
,
const
std
::
string
&
source
)
const
std
::
string
&
source
)
{
{
// check if file_name already contains a full path
// check if file_name already contains a full path
const
size_t
pos
=
findLastPathSeparator
(
file_name
);
const
size_t
pos
=
findLastPathSeparator
(
file_name
);
...
@@ -135,6 +131,4 @@ std::string extractPath(std::string const& pathname)
...
@@ -135,6 +131,4 @@ std::string extractPath(std::string const& pathname)
const
size_t
pos
=
findLastPathSeparator
(
pathname
);
const
size_t
pos
=
findLastPathSeparator
(
pathname
);
return
pathname
.
substr
(
0
,
pos
+
1
);
return
pathname
.
substr
(
0
,
pos
+
1
);
}
}
}
// end namespace BaseLib
}
// end namespace BaseLib
This diff is collapsed.
Click to expand it.
BaseLib/FileTools.h
+
8
−
9
View file @
88be462e
/**
/**
* \file
* \author Lars Bilke
* \date Apr. 2010
* \brief Filename manipulation routines.
*
* \copyright
* Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org)
* Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
* http://www.opengeosys.org/project/license
*
*
*
* \file FileTools.h
*
* Created on 2010-04-26 by Lars Bilke
*
*/
*/
#ifndef FILETOOLS_H
#ifndef FILETOOLS_H
#define FILETOOLS_H
#define FILETOOLS_H
#include
<string>
#include
<fstream>
#include
<fstream>
#include
<string>
namespace
BaseLib
namespace
BaseLib
{
{
/**
/**
* \brief Returns true if given file exists. From http://www.techbytes.ca/techbyte103.html
* \brief Returns true if given file exists. From http://www.techbytes.ca/techbyte103.html
*
*
...
@@ -37,7 +36,7 @@ bool IsFileExisting(const std::string &strFilename);
...
@@ -37,7 +36,7 @@ bool IsFileExisting(const std::string &strFilename);
*/
*/
template
<
typename
T
>
void
writeValueBinary
(
std
::
ostream
&
out
,
T
const
&
val
)
template
<
typename
T
>
void
writeValueBinary
(
std
::
ostream
&
out
,
T
const
&
val
)
{
{
out
.
write
((
const
char
*
)
&
val
,
sizeof
(
T
));
out
.
write
((
const
char
*
)
&
val
,
sizeof
(
T
));
}
}
/**
/**
...
...
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