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
Snippets
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
Özgür Ozan Sen
ogs
Commits
33a2d946
Commit
33a2d946
authored
8 years ago
by
Norihiro Watanabe
Browse files
Options
Downloads
Patches
Plain Diff
add FileFinder constructor taking a path and move definitions to cpp
parent
48a61d63
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/FileFinder.cpp
+66
-0
66 additions, 0 deletions
BaseLib/FileFinder.cpp
BaseLib/FileFinder.h
+11
-38
11 additions, 38 deletions
BaseLib/FileFinder.h
with
77 additions
and
38 deletions
BaseLib/FileFinder.cpp
0 → 100644
+
66
−
0
View file @
33a2d946
/**
* \file
* \author Karsten Rink
* \date 2010-10-26
* \brief Definition of the FileFinder class.
*
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include
"FileFinder.h"
#include
<fstream>
#include
<logog/include/logog.hpp>
namespace
BaseLib
{
FileFinder
::
FileFinder
()
{
addDirectory
(
"."
);
}
FileFinder
::
FileFinder
(
std
::
string
const
&
dir
)
{
addDirectory
(
"."
);
addDirectory
(
dir
);
}
void
FileFinder
::
addDirectory
(
std
::
string
const
&
dir
)
{
if
(
dir
.
empty
())
return
;
if
(
dir
[
dir
.
size
()
-
1
]
!=
'/'
)
_directories
.
push_back
(
std
::
string
(
dir
+
"/"
));
else
_directories
.
push_back
(
dir
);
}
std
::
string
FileFinder
::
getPath
(
std
::
string
const
&
filename
)
const
{
if
(
_directories
.
empty
())
ERR
(
"FileFinder::getPath(): No directories set."
);
for
(
auto
const
&
dir
:
_directories
)
{
std
::
string
testDir
(
dir
);
std
::
ifstream
is
(
testDir
.
append
(
filename
).
c_str
());
if
(
is
.
good
())
{
is
.
close
();
return
testDir
;
}
}
ERR
(
"FileFinder::getPath(): File not found."
);
return
filename
;
}
}
// end namespace BaseLib
This diff is collapsed.
Click to expand it.
BaseLib/FileFinder.h
+
11
−
38
View file @
33a2d946
...
...
@@ -15,12 +15,9 @@
#ifndef FILEFINDER_H
#define FILEFINDER_H
#include
<fstream>
#include
<string>
#include
<vector>
#include
"BuildInfo.h"
#include
<logog/include/logog.hpp>
namespace
BaseLib
{
...
...
@@ -32,52 +29,28 @@ namespace BaseLib
class
FileFinder
{
public:
/// Constructor
FileFinder
()
{
addDirectory
(
"."
);
addDirectory
(
BuildInfo
::
source_path
+
"/GeoLib/IO/XmlIO"
);
addDirectory
(
BuildInfo
::
source_path
+
"/Applications/FileIO/XmlIO"
);
}
/// Constructor having current directory as the search-space
FileFinder
();
/**
* Construct with the given directory paths in addition to current directory
*
* @param dirs a vector of directory paths to the search-space
*/
explicit
FileFinder
(
std
::
string
const
&
dir
);
/**
* \brief Adds another directory to the search-space.
* If the given directory does not end with a slash one will be appended.
*/
void
addDirectory
(
std
::
string
const
&
dir
)
{
if
(
dir
.
empty
())
return
;
if
(
dir
[
dir
.
size
()
-
1
]
!=
'/'
)
_directories
.
push_back
(
std
::
string
(
dir
+
"/"
));
else
_directories
.
push_back
(
dir
);
}
void
addDirectory
(
std
::
string
const
&
dir
);
/**
* Given a filename, this method will return the complete path where this file can be found.
* If the file is located in more than one of the directories in the search list, only the
* first location will be returned.
*/
std
::
string
getPath
(
std
::
string
const
&
filename
)
const
{
if
(
_directories
.
empty
())
ERR
(
"FileFinder::getPath(): No directories set."
);
for
(
auto
it
=
_directories
.
begin
();
it
!=
_directories
.
end
();
++
it
)
{
std
::
string
testDir
(
*
it
);
std
::
ifstream
is
(
testDir
.
append
(
filename
).
c_str
());
if
(
is
.
good
())
{
is
.
close
();
return
testDir
;
}
}
ERR
(
"FileFinder::getPath(): File not found."
);
return
filename
;
}
std
::
string
getPath
(
std
::
string
const
&
filename
)
const
;
private:
std
::
vector
<
std
::
string
>
_directories
;
...
...
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