Skip to content

Commit 24ef7af

Browse files
committed
const fixes + noexcept in path_utils
1 parent 2aa2f31 commit 24ef7af

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

src/common/os/path_utils.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ class PathUtils
4646
static const char dir_sep;
4747

4848
/// String used to point to current directory
49-
static const char* curr_dir_link;
49+
static const char* const curr_dir_link;
5050
static const size_t curr_dir_link_len;
5151

5252
/// String used to point to parent directory
53-
static const char* up_dir_link;
53+
static const char* const up_dir_link;
5454
static const size_t up_dir_link_len;
5555

5656
/// The directory list separator for the platform.
@@ -78,6 +78,13 @@ class PathUtils
7878
// Destructor provided for memory cleanup
7979
virtual ~DirIterator() {}
8080

81+
// Default constructor is not allowed
82+
DirIterator() = delete;
83+
// Copy constructor is not allowed
84+
DirIterator(const DirIterator&) = delete;
85+
// Assignment operator is not allowed
86+
const DirIterator& operator=(const DirIterator&) = delete;
87+
8188
// The prefix increment operator (++itr) advances the iteration by
8289
// one and returns a reference to itself to allow cascading operations
8390
virtual const DirIterator& operator++() = 0;
@@ -86,24 +93,16 @@ class PathUtils
8693
// item in the iteration. This path is prefixed with the path of
8794
// the directory. If the last element of the path is wanted use
8895
// PathUtils::splitLastComponent on the result of this function.
89-
virtual const Firebird::PathName& operator*() = 0;
96+
virtual const Firebird::PathName& operator*() noexcept = 0;
9097

9198
// Tests if the iterator has reached the end of the iteration.
9299
// It is implemented in such a way to make the following loop work correctly:
93100
// for (DirIterator *itr = PathUtils::newDirIterator(); *itr; ++(*itr))
94-
virtual operator bool() = 0;
101+
virtual operator bool() noexcept = 0;
95102

96103
protected:
97104
// Stores the path to the directory as given in the constructor
98105
const Firebird::PathName dirPrefix;
99-
100-
private:
101-
// Default constructor is not allowed
102-
DirIterator();
103-
// Copy constructor is not allowed
104-
DirIterator(const DirIterator&);
105-
// Assignment operator is not allowed
106-
const DirIterator& operator=(const DirIterator&);
107106
};
108107

109108
/** isRelative returns true if the given path is relative, and false if not.
@@ -141,9 +140,9 @@ class PathUtils
141140
static void ensureSeparator(Firebird::PathName& in_out);
142141

143142
// Ensure the path separators are correct for the current platform
144-
static void fixupSeparators(char* path);
143+
static void fixupSeparators(char* path) noexcept;
145144

146-
static void fixupSeparators(Firebird::PathName& path)
145+
static void fixupSeparators(Firebird::PathName& path) noexcept
147146
{
148147
fixupSeparators(path.begin());
149148
}

src/common/os/posix/path_utils.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@
3232
#include <sys/stat.h>
3333
#include <dirent.h>
3434
#include <unistd.h>
35+
#include <string>
3536

3637
using namespace Firebird;
3738

3839
/// The POSIX implementation of the path_utils abstraction.
3940

4041
const char PathUtils::dir_sep = '/';
41-
const char* PathUtils::curr_dir_link = ".";
42-
const char* PathUtils::up_dir_link = "..";
42+
const char* const PathUtils::curr_dir_link = ".";
43+
const char* const PathUtils::up_dir_link = "..";
4344
const char PathUtils::dir_list_sep = ':';
44-
const size_t PathUtils::curr_dir_link_len = strlen(curr_dir_link);
45-
const size_t PathUtils::up_dir_link_len = strlen(up_dir_link);
45+
const size_t PathUtils::curr_dir_link_len = std::char_traits<char>::length(curr_dir_link);
46+
const size_t PathUtils::up_dir_link_len = std::char_traits<char>::length(up_dir_link);
4647

4748
class PosixDirIterator : public PathUtils::DirIterator
4849
{
@@ -61,9 +62,9 @@ class PosixDirIterator : public PathUtils::DirIterator
6162

6263
~PosixDirIterator();
6364

64-
const PosixDirIterator& operator++();
65-
const PathName& operator*() { return file; }
66-
operator bool() { return !done; }
65+
const PosixDirIterator& operator++() override;
66+
const PathName& operator*() noexcept override { return file; }
67+
operator bool() noexcept override { return !done; }
6768

6869
private:
6970
DIR* dir;
@@ -220,7 +221,7 @@ void PathUtils::ensureSeparator(PathName& in_out)
220221
in_out += PathUtils::dir_sep;
221222
}
222223

223-
void PathUtils::fixupSeparators(char* path)
224+
void PathUtils::fixupSeparators(char* path) noexcept
224225
{
225226
for (; *path; ++path)
226227
{

src/common/os/win32/path_utils.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
#include "../common/os/path_utils.h"
44
#include <io.h> // _access
55
#include <direct.h> // _mkdir
6+
#include <string>
67

78
using namespace Firebird;
89

910
/// The Win32 implementation of the path_utils abstraction.
1011

1112
const char PathUtils::dir_sep = '\\';
12-
const char* PathUtils::curr_dir_link = ".";
13-
const char* PathUtils::up_dir_link = "..";
13+
const char* const PathUtils::curr_dir_link = ".";
14+
const char* const PathUtils::up_dir_link = "..";
1415
const char PathUtils::dir_list_sep = ';';
15-
const size_t PathUtils::curr_dir_link_len = strlen(curr_dir_link);
16-
const size_t PathUtils::up_dir_link_len = strlen(up_dir_link);
16+
const size_t PathUtils::curr_dir_link_len = std::char_traits<char>::length(curr_dir_link);
17+
const size_t PathUtils::up_dir_link_len = std::char_traits<char>::length(up_dir_link);
1718

18-
class Win32DirIterator : public PathUtils::DirIterator
19+
class Win32DirIterator final : public PathUtils::DirIterator
1920
{
2021
public:
2122
Win32DirIterator(MemoryPool& p, const PathName& path)
@@ -32,9 +33,9 @@ class Win32DirIterator : public PathUtils::DirIterator
3233

3334
~Win32DirIterator();
3435

35-
const PathUtils::DirIterator& operator++();
36-
const PathName& operator*() { return file; }
37-
operator bool() { return !done; }
36+
const PathUtils::DirIterator& operator++() override;
37+
const PathName& operator*() noexcept override { return file; }
38+
operator bool() noexcept override { return !done; }
3839

3940
private:
4041
HANDLE dir;
@@ -202,7 +203,7 @@ void PathUtils::ensureSeparator(PathName& in_out)
202203
in_out += PathUtils::dir_sep;
203204
}
204205

205-
void PathUtils::fixupSeparators(char* path)
206+
void PathUtils::fixupSeparators(char* path) noexcept
206207
{
207208
for (; *path; ++path)
208209
{

0 commit comments

Comments
 (0)