Skip to content

Commit 5219e71

Browse files
committed
Miscellaneous code cleanup / modernization.
- Make liberal use of C++11 `override` and `final` specifiers. - Replace various `typedef struct` with plain structs and `using` declarations. - Change include hierarchy, now using dedicated forward declaration headers. - Refactor (non-)portable portions of radiosity octree code, and add truly portable alternative implementations. - Some odds and ends.
1 parent 1fa6d36 commit 5219e71

File tree

445 files changed

+11370
-7679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

445 files changed

+11370
-7679
lines changed

platform/unix/syspovfilesystem.cpp

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
//******************************************************************************
2+
///
3+
/// @file platform/unix/syspovfilesystem.cpp
4+
///
5+
/// Unix-specific implementation of file system services.
6+
///
7+
/// @copyright
8+
/// @parblock
9+
///
10+
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
12+
///
13+
/// POV-Ray is free software: you can redistribute it and/or modify
14+
/// it under the terms of the GNU Affero General Public License as
15+
/// published by the Free Software Foundation, either version 3 of the
16+
/// License, or (at your option) any later version.
17+
///
18+
/// POV-Ray is distributed in the hope that it will be useful,
19+
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
/// GNU Affero General Public License for more details.
22+
///
23+
/// You should have received a copy of the GNU Affero General Public License
24+
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
///
26+
/// ----------------------------------------------------------------------------
27+
///
28+
/// POV-Ray is based on the popular DKB raytracer version 2.12.
29+
/// DKBTrace was originally written by David K. Buck.
30+
/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
31+
///
32+
/// @endparblock
33+
///
34+
//******************************************************************************
35+
36+
// Unit header file must be the first file included within POV-Ray *.cpp files (pulls in config)
37+
#include "base/filesystem.h"
38+
#include "syspovfilesystem.h"
39+
40+
// C++ variants of C standard header files
41+
// (none at the moment)
42+
43+
// C++ standard header files
44+
#include <limits>
45+
46+
// POSIX standard header files
47+
#include <fcntl.h>
48+
#include <unistd.h>
49+
50+
// POV-Ray header files (base module)
51+
#include "base/stringutilities.h"
52+
53+
// this must be the last file included
54+
#include "base/povassert.h"
55+
#include "base/povdebug.h"
56+
57+
namespace pov_base
58+
{
59+
60+
namespace Filesystem
61+
{
62+
63+
//******************************************************************************
64+
65+
#if !POV_USE_DEFAULT_DELETEFILE
66+
67+
bool DeleteFile(const UCS2String& fileName)
68+
{
69+
return (unlink(UCS2toSysString(fileName).c_str()) == 0);
70+
}
71+
72+
#endif // POV_USE_DEFAULT_DELETEFILE
73+
74+
//******************************************************************************
75+
76+
#if !POV_USE_DEFAULT_LARGEFILE
77+
78+
#ifndef POVUNIX_LSEEK64
79+
#define POVUNIX_LSEEK64(h,b,o) lseek(h,b,o)
80+
#endif
81+
82+
using Offset = decltype(POVUNIX_LSEEK64(0,0,0));
83+
84+
static_assert(
85+
std::numeric_limits<Offset>::digits > 32,
86+
"Large files (> 2 GiB) not supported, limiting image size to approx. 100 Megapixels. Proceed at your own risk."
87+
);
88+
89+
struct LargeFile::Data final
90+
{
91+
int handle;
92+
Data() : handle(-1) {}
93+
};
94+
95+
LargeFile::LargeFile() :
96+
mpData(new Data)
97+
{}
98+
99+
LargeFile::~LargeFile()
100+
{
101+
Close();
102+
}
103+
104+
bool LargeFile::CreateRW(const UCS2String& fileName)
105+
{
106+
mpData->handle = open(UCS2toSysString(fileName).c_str(),
107+
O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
108+
return (mpData->handle != -1);
109+
}
110+
111+
bool LargeFile::Seek(std::int_least64_t offset)
112+
{
113+
if (mpData->handle == -1)
114+
return false;
115+
if ((offset < 0) || (offset > std::numeric_limits<Offset>::max()))
116+
return false;
117+
return (POVUNIX_LSEEK64(mpData->handle, Offset(offset), SEEK_SET) == offset);
118+
}
119+
120+
std::size_t LargeFile::Read(void* data, std::size_t maxSize)
121+
{
122+
if (mpData->handle == -1)
123+
return false;
124+
return read(mpData->handle, data, int(maxSize));
125+
}
126+
127+
bool LargeFile::Write(const void* data, std::size_t size)
128+
{
129+
if (mpData->handle == -1)
130+
return false;
131+
return (write(mpData->handle, data, int(size)) == size);
132+
}
133+
134+
void LargeFile::Close()
135+
{
136+
if (mpData->handle != -1)
137+
{
138+
close(mpData->handle);
139+
mpData->handle = -1;
140+
}
141+
}
142+
143+
#endif // POV_USE_DEFAULT_LARGEFILE
144+
145+
//******************************************************************************
146+
147+
#if !POV_USE_DEFAULT_TEMPORARYFILE
148+
149+
static UCS2String gTempPath;
150+
151+
void SetTempFilePath(const UCS2String& tempPath)
152+
{
153+
gTempPath = tempPath;
154+
}
155+
156+
UCS2String TemporaryFile::SuggestName()
157+
{
158+
POV_ASSERT(!gTempPath.empty());
159+
160+
// TODO FIXME - This allows only one temporary file per process!
161+
// TODO FIXME - Avoid converting back and forth between UCS-2 and system-specific encoding.
162+
char str [POV_FILENAME_BUFFER_CHARS + 1] = "";
163+
std::snprintf(str, POV_FILENAME_BUFFER_CHARS + 1, "%spov%d", UCS2toSysString(gTempPath).c_str(), int(getpid()));
164+
return SysToUCS2String(str);
165+
}
166+
167+
#endif // POV_USE_DEFAULT_TEMPORARYFILE
168+
169+
//******************************************************************************
170+
171+
}
172+
// end of namespace Filesystem
173+
174+
}
175+
// end of namespace pov_base

platform/unix/syspovfilesystem.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//******************************************************************************
2+
///
3+
/// @file platform/unix/syspovfilesystem.h
4+
///
5+
/// Unix-specific declarations related to file system services.
6+
///
7+
/// @note
8+
/// Most of @ref platform/unix/syspovfilesystem.cpp is declared in
9+
/// @ref base/filesystem.h. This file contains only a few extra
10+
/// platform-specific declarations.
11+
///
12+
/// @copyright
13+
/// @parblock
14+
///
15+
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
16+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
17+
///
18+
/// POV-Ray is free software: you can redistribute it and/or modify
19+
/// it under the terms of the GNU Affero General Public License as
20+
/// published by the Free Software Foundation, either version 3 of the
21+
/// License, or (at your option) any later version.
22+
///
23+
/// POV-Ray is distributed in the hope that it will be useful,
24+
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
/// GNU Affero General Public License for more details.
27+
///
28+
/// You should have received a copy of the GNU Affero General Public License
29+
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
30+
///
31+
/// ----------------------------------------------------------------------------
32+
///
33+
/// POV-Ray is based on the popular DKB raytracer version 2.12.
34+
/// DKBTrace was originally written by David K. Buck.
35+
/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
36+
///
37+
/// @endparblock
38+
///
39+
//******************************************************************************
40+
41+
#ifndef POVRAY_UNIX_SYSPOVFILESYSTEM_H
42+
#define POVRAY_UNIX_SYSPOVFILESYSTEM_H
43+
44+
// Module config header file must be the first file included within POV-Ray unit header files
45+
#include "base/configbase.h"
46+
47+
// C++ variants of C standard header files
48+
// C++ standard header files
49+
// (none at the moment)
50+
51+
// POV-Ray header files (base module)
52+
#include "base/stringtypes.h"
53+
54+
namespace pov_base
55+
{
56+
57+
namespace Filesystem
58+
{
59+
60+
#if !POV_USE_DEFAULT_TEMPORARYFILE
61+
62+
void SetTempFilePath(const UCS2String& tempPath);
63+
64+
#endif // POV_USE_DEFAULT_TEMPORARYFILE
65+
66+
}
67+
// end of namespace Filesystem
68+
69+
}
70+
// end of namespace pov_base
71+
72+
#endif // POVRAY_UNIX_SYSPOVFILESYSTEM_H

platform/unix/syspovtimer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// @parblock
1010
///
1111
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
12-
/// Copyright 1991-2018 Persistence of Vision Raytracer Pty. Ltd.
12+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1313
///
1414
/// POV-Ray is free software: you can redistribute it and/or modify
1515
/// it under the terms of the GNU Affero General Public License as
@@ -50,6 +50,7 @@
5050
#include <sys/time.h>
5151
#endif
5252

53+
#include "base/povassert.h"
5354
#include "base/types.h"
5455

5556
// this must be the last file included
@@ -305,3 +306,4 @@ bool Timer::HasValidThreadCPUTime () const
305306
//******************************************************************************
306307

307308
}
309+
// end of namespace pov_base

platform/unix/syspovtimer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// @parblock
1010
///
1111
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
12-
/// Copyright 1991-2017 Persistence of Vision Raytracer Pty. Ltd.
12+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1313
///
1414
/// POV-Ray is free software: you can redistribute it and/or modify
1515
/// it under the terms of the GNU Affero General Public License as
@@ -62,7 +62,7 @@ void Delay(unsigned int msec);
6262
/// in the order of an hour (any system with a 32-bit `clock_t` and a standard `CLOCKS_PER_SEC`
6363
/// of 1,000,000).
6464
///
65-
class Timer
65+
class Timer final
6666
{
6767
public:
6868

@@ -105,5 +105,6 @@ class Timer
105105
#endif // !POV_USE_DEFAULT_TIMER
106106

107107
}
108+
// end of namespace pov_base
108109

109110
#endif // POVRAY_UNIX_SYSPOVTIMER_H

platform/windows/osversioninfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// @parblock
99
///
1010
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11-
/// Copyright 1991-2017 Persistence of Vision Raytracer Pty. Ltd.
11+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1212
///
1313
/// POV-Ray is free software: you can redistribute it and/or modify
1414
/// it under the terms of the GNU Affero General Public License as
@@ -60,3 +60,4 @@ bool WindowsVersionDetector::IsVersion (int major, int minor) const
6060
}
6161

6262
}
63+
// end of namespace pov_base

platform/windows/osversioninfo.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// @parblock
99
///
1010
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11-
/// Copyright 1991-2017 Persistence of Vision Raytracer Pty. Ltd.
11+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1212
///
1313
/// POV-Ray is free software: you can redistribute it and/or modify
1414
/// it under the terms of the GNU Affero General Public License as
@@ -43,7 +43,7 @@
4343
namespace pov_base
4444
{
4545

46-
class WindowsVersionDetector
46+
class WindowsVersionDetector final
4747
{
4848
public:
4949

@@ -74,5 +74,6 @@ class WindowsVersionDetector
7474
};
7575

7676
}
77+
// end of namespace pov_base
7778

7879
#endif // POVRAY_WINDOWS_OSVERSIONINFO_H

0 commit comments

Comments
 (0)