Browse code

Various changes:

* Use enum class instead of enum (except for the enums for the resource IDs, not really necessary there).
* For NCSF specifically, included a function to convert an enum class to its underlying integral type (as this is needed for use with the std::bitset class).
* Cleanup headers so all the ones needed in a file are explicitly included even if they may possibly be included in another header.
* Used forward declarations in a few spots.
* Explicitly namespaced all (u)int*_t uses (this might seem like overkill, but it helps me see when the standard types are being used with a simple search for std::).
* Made sure it all builds with MinGW-w64 as well (both gcc and clang).
* Removed some std::move from DialogBuilder.cpp based on clang's warnings for that.
* Replaced use of std::copy_n on strings in DialogBuilder.cpp with my CopyToString functions that use wcscpy.
* Replaced CHAR_MIN/CHAR_MAX in eqstr.h and ltstr.h with std::numeric_limits<char>::min/max().

Naram Qashat authored on 2021/03/21 03:16:45
Showing 1 changed files
... ...
@@ -12,6 +12,7 @@
12 12
 #include <string>
13 13
 #define _USE_MATH_DEFINES
14 14
 #include <cmath>
15
+#include <cstddef>
15 16
 #include <cstdint>
16 17
 #include <cwchar>
17 18
 #include <cstring>
... ...
@@ -25,14 +26,14 @@ template<typename T> inline bool fEqual(T x, T y, int N = 1)
25 26
 	return diff <= tolerance * std::abs(x) && diff <= tolerance * std::abs(y);
26 27
 }
27 28
 
28
-inline uint32_t Get32BitsLE(const uint8_t *input)
29
+inline std::uint32_t Get32BitsLE(const std::uint8_t *input)
29 30
 {
30 31
 	return input[0] | (input[1] << 8) | (input[2] << 16) | (input[3] << 24);
31 32
 }
32 33
 
33
-inline uint32_t Get32BitsLE(std::ifstream &input)
34
+inline std::uint32_t Get32BitsLE(std::ifstream &input)
34 35
 {
35
-	uint8_t bytes[4];
36
+	std::uint8_t bytes[4];
36 37
 	input.read(reinterpret_cast<char *>(bytes), 4);
37 38
 	return Get32BitsLE(bytes);
38 39
 }
... ...
@@ -44,7 +45,7 @@ template<typename T> inline T NextHighestPowerOf2(T value)
44 45
 	if (value < 1)
45 46
 		return 1;
46 47
 	--value;
47
-	for (size_t i = 1; i < sizeof(T) * std::numeric_limits<unsigned char>::digits; i <<= 1)
48
+	for (std::size_t i = 1; i < sizeof(T) * std::numeric_limits<unsigned char>::digits; i <<= 1)
48 49
 		value |= value >> i;
49 50
 	return value + 1;
50 51
 }
... ...
@@ -60,20 +61,20 @@ template<typename T1, typename T2> inline void clamp(T1 &valueToClamp, const T2
60 61
 
61 62
 inline void CopyToString(const std::wstring &src, wchar_t *dst)
62 63
 {
63
-	wcscpy(dst, src.c_str());
64
+	std::wcscpy(dst, src.c_str());
64 65
 }
65 66
 
66 67
 inline void CopyToString(const std::string &src, wchar_t *dst)
67 68
 {
68
-	wcscpy(dst, ConvertFuncs::StringToWString(src).c_str());
69
+	std::wcscpy(dst, ConvertFuncs::StringToWString(src).c_str());
69 70
 }
70 71
 
71 72
 inline void CopyToString(const std::string &src, char *dst)
72 73
 {
73
-	strcpy(dst, src.c_str());
74
+	std::strcpy(dst, src.c_str());
74 75
 }
75 76
 
76 77
 inline void CopyToString(const std::wstring &src, char *dst)
77 78
 {
78
-	strcpy(dst, ConvertFuncs::WStringToString(src).c_str());
79
+	std::strcpy(dst, ConvertFuncs::WStringToString(src).c_str());
79 80
 }
Browse code

Use C++17 std::filesystem functions instead of my own.

Naram Qashat authored on 2021/03/20 20:05:50
Showing 1 changed files
... ...
@@ -9,9 +9,6 @@
9 9
 
10 10
 #include <limits>
11 11
 #include <fstream>
12
-#if defined(_WIN32) && !defined(_MSC_VER)
13
-# include "fstream_wfopen.h"
14
-#endif
15 12
 #include <string>
16 13
 #define _USE_MATH_DEFINES
17 14
 #include <cmath>
... ...
@@ -40,24 +37,6 @@ inline uint32_t Get32BitsLE(std::ifstream &input)
40 37
 	return Get32BitsLE(bytes);
41 38
 }
42 39
 
43
-// This gets the directory for the path, including the final forward/backward slash
44
-template<typename T> inline std::basic_string<T> ExtractDirectoryFromPath(const std::basic_string<T> &fullPath)
45
-{
46
-	auto lastSlash = fullPath.rfind('\\');
47
-	if (lastSlash == std::basic_string<T>::npos)
48
-		lastSlash = fullPath.rfind('/');
49
-	return lastSlash != std::basic_string<T>::npos ? fullPath.substr(0, lastSlash + 1) : std::basic_string<T>();
50
-}
51
-
52
-// This gets the filename for the path
53
-template<typename T> inline std::basic_string<T> ExtractFilenameFromPath(const std::basic_string<T> &fullPath)
54
-{
55
-	auto lastSlash = fullPath.rfind('\\');
56
-	if (lastSlash == std::basic_string<T>::npos)
57
-		lastSlash = fullPath.rfind('/');
58
-	return lastSlash != std::basic_string<T>::npos ? fullPath.substr(lastSlash + 1) : std::basic_string<T>();
59
-}
60
-
61 40
 // Code from the following answer on Stack Overflow:
62 41
 // http://stackoverflow.com/a/15479212
63 42
 template<typename T> inline T NextHighestPowerOf2(T value)
... ...
@@ -79,24 +58,6 @@ template<typename T1, typename T2> inline void clamp(T1 &valueToClamp, const T2
79 58
 		valueToClamp = maxValue;
80 59
 }
81 60
 
82
-inline bool FileExists(const std::string &filename)
83
-{
84
-	std::ifstream file(filename.c_str());
85
-	return !!file;
86
-}
87
-
88
-#ifdef _WIN32
89
-inline bool FileExists(const std::wstring &filename)
90
-{
91
-#ifdef _MSC_VER
92
-	std::ifstream file(filename.c_str());
93
-#else
94
-	ifstream_wfopen file(filename.c_str());
95
-#endif
96
-	return !!file;
97
-}
98
-#endif
99
-
100 61
 inline void CopyToString(const std::wstring &src, wchar_t *dst)
101 62
 {
102 63
 	wcscpy(dst, src.c_str());
Browse code

Remove last modification date from files.

(I never remember to update these and besides, GitHub history can show when they were last modified.)

Naram Qashat authored on 2021/03/19 10:58:12
Showing 1 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 /*
2 2
  * xSF - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-24
5 4
  *
6 5
  * Partially based on the vio*sf framework
7 6
  */
Browse code

Lots of changes in regards to strings, as follows:

* Removed my custom String class, as well as removed the really old
Unicode ConvertUTF, the UTF Converter, and the UTF Encode/Decode
functions.
* Replaced the above with using standard C++ std::wstring_convert and
std::codecvt_utf8.
* Added headers adapted from llvm's libc++ project for allowing the
above C++ classes to exist with GCC and Clang when libc++ isn't being
used.
* Used std::string over std::wstring whenever possible.
* Added header adapted from llvm's libc++ project to create special
versions of the ifstream and ofstream classes that would utilize _wfopen
on non-MSVC Windows compilers, so those compilers could access files on
Windows that use characters outside the current codepage.
* Removed the -static-libgcc and -static-libstdc++ flags from the
Makefile for non-MSVC builds. The generated DLLs will require extra DLLs
from either Cygwin or MinGW (whichever is used to compile), I've only
tested with MinGW and for some reason they crash Winamp on exit, I have
no idea why.

Naram Qashat authored on 2014/09/24 13:58:55
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-17
4
+ * Last modification on 2014-09-24
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -10,10 +10,16 @@
10 10
 
11 11
 #include <limits>
12 12
 #include <fstream>
13
+#if defined(_WIN32) && !defined(_MSC_VER)
14
+# include "fstream_wfopen.h"
15
+#endif
13 16
 #include <string>
14 17
 #define _USE_MATH_DEFINES
15 18
 #include <cmath>
16 19
 #include <cstdint>
20
+#include <cwchar>
21
+#include <cstring>
22
+#include "convert.h"
17 23
 
18 24
 // Code from http://learningcppisfun.blogspot.com/2010/04/comparing-floating-point-numbers.html
19 25
 template<typename T> inline bool fEqual(T x, T y, int N = 1)
... ...
@@ -80,10 +86,34 @@ inline bool FileExists(const std::string &filename)
80 86
 	return !!file;
81 87
 }
82 88
 
83
-#ifdef _MSC_VER
89
+#ifdef _WIN32
84 90
 inline bool FileExists(const std::wstring &filename)
85 91
 {
92
+#ifdef _MSC_VER
86 93
 	std::ifstream file(filename.c_str());
94
+#else
95
+	ifstream_wfopen file(filename.c_str());
96
+#endif
87 97
 	return !!file;
88 98
 }
89 99
 #endif
100
+
101
+inline void CopyToString(const std::wstring &src, wchar_t *dst)
102
+{
103
+	wcscpy(dst, src.c_str());
104
+}
105
+
106
+inline void CopyToString(const std::string &src, wchar_t *dst)
107
+{
108
+	wcscpy(dst, ConvertFuncs::StringToWString(src).c_str());
109
+}
110
+
111
+inline void CopyToString(const std::string &src, char *dst)
112
+{
113
+	strcpy(dst, src.c_str());
114
+}
115
+
116
+inline void CopyToString(const std::wstring &src, char *dst)
117
+{
118
+	strcpy(dst, ConvertFuncs::WStringToString(src).c_str());
119
+}
Browse code

* Fixes for gcc and clang (while they can compile the code, the DLLs made aren't functional, but oh well).

* [2SF] Used more up-to-date asmjit, despite the ugly looking code.

Naram Qashat authored on 2014/09/17 19:51:45
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-08
4
+ * Last modification on 2014-09-17
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -60,7 +60,7 @@ template<typename T> inline T NextHighestPowerOf2(T value)
60 60
 	if (value < 1)
61 61
 		return 1;
62 62
 	--value;
63
-	for (size_t i = 1; i < sizeof(T) * CHAR_BIT; i <<= 1)
63
+	for (size_t i = 1; i < sizeof(T) * std::numeric_limits<unsigned char>::digits; i <<= 1)
64 64
 		value |= value >> i;
65 65
 	return value + 1;
66 66
 }
... ...
@@ -80,7 +80,7 @@ inline bool FileExists(const std::string &filename)
80 80
 	return !!file;
81 81
 }
82 82
 
83
-#ifdef _WIN32
83
+#ifdef _MSC_VER
84 84
 inline bool FileExists(const std::wstring &filename)
85 85
 {
86 86
 	std::ifstream file(filename.c_str());
Browse code

Minor cleanups in the framework.

Naram Qashat authored on 2014/09/08 15:06:52
Showing 1 changed files
... ...
@@ -76,14 +76,14 @@ template<typename T1, typename T2> inline void clamp(T1 &valueToClamp, const T2
76 76
 
77 77
 inline bool FileExists(const std::string &filename)
78 78
 {
79
-	std::ifstream file((filename.c_str()));
79
+	std::ifstream file(filename.c_str());
80 80
 	return !!file;
81 81
 }
82 82
 
83 83
 #ifdef _WIN32
84 84
 inline bool FileExists(const std::wstring &filename)
85 85
 {
86
-	std::ifstream file((filename.c_str()));
86
+	std::ifstream file(filename.c_str());
87 87
 	return !!file;
88 88
 }
89 89
 #endif
Browse code

Use #pragma once instead of include guards.

Naram Qashat authored on 2014/09/08 14:47:36
Showing 1 changed files
... ...
@@ -1,13 +1,12 @@
1 1
 /*
2 2
  * xSF - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-26
4
+ * Last modification on 2014-09-08
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
8 8
 
9
-#ifndef XSFCOMMON_H
10
-#define XSFCOMMON_H
9
+#pragma once
11 10
 
12 11
 #include <limits>
13 12
 #include <fstream>
... ...
@@ -88,5 +87,3 @@ inline bool FileExists(const std::wstring &filename)
88 87
 	return !!file;
89 88
 }
90 89
 #endif
91
-
92
-#endif
Browse code

Fixed up the Lanczos interpolation in NCSF (thanks to kode54), also allowed the NCSF plugin to use 32-bit samples in it's GenerateSamples function.

Naram Qashat authored on 2013/04/26 00:54:28
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-23
4
+ * Last modification on 2013-04-26
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -66,6 +66,15 @@ template<typename T> inline T NextHighestPowerOf2(T value)
66 66
 	return value + 1;
67 67
 }
68 68
 
69
+// Clamp a value between a minimum and maximum value
70
+template<typename T1, typename T2> inline void clamp(T1 &valueToClamp, const T2 &minValue, const T2 &maxValue)
71
+{
72
+	if (valueToClamp < minValue)
73
+		valueToClamp = minValue;
74
+	else if (valueToClamp > maxValue)
75
+		valueToClamp = maxValue;
76
+}
77
+
69 78
 inline bool FileExists(const std::string &filename)
70 79
 {
71 80
 	std::ifstream file((filename.c_str()));
Browse code

Added Lanczos interpolation to the NCSF plugin, and cleaned up a bit of the other code, as well as removing pstdint.h since it's no longer needed.

Naram Qashat authored on 2013/04/23 20:29:21
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-21
4
+ * Last modification on 2013-04-23
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -14,7 +14,7 @@
14 14
 #include <string>
15 15
 #define _USE_MATH_DEFINES
16 16
 #include <cmath>
17
-#include "pstdint.h"
17
+#include <cstdint>
18 18
 
19 19
 // Code from http://learningcppisfun.blogspot.com/2010/04/comparing-floating-point-numbers.html
20 20
 template<typename T> inline bool fEqual(T x, T y, int N = 1)
... ...
@@ -39,7 +39,7 @@ inline uint32_t Get32BitsLE(std::ifstream &input)
39 39
 // This gets the directory for the path, including the final forward/backward slash
40 40
 template<typename T> inline std::basic_string<T> ExtractDirectoryFromPath(const std::basic_string<T> &fullPath)
41 41
 {
42
-	size_t lastSlash = fullPath.rfind('\\');
42
+	auto lastSlash = fullPath.rfind('\\');
43 43
 	if (lastSlash == std::basic_string<T>::npos)
44 44
 		lastSlash = fullPath.rfind('/');
45 45
 	return lastSlash != std::basic_string<T>::npos ? fullPath.substr(0, lastSlash + 1) : std::basic_string<T>();
... ...
@@ -48,7 +48,7 @@ template<typename T> inline std::basic_string<T> ExtractDirectoryFromPath(const
48 48
 // This gets the filename for the path
49 49
 template<typename T> inline std::basic_string<T> ExtractFilenameFromPath(const std::basic_string<T> &fullPath)
50 50
 {
51
-	size_t lastSlash = fullPath.rfind('\\');
51
+	auto lastSlash = fullPath.rfind('\\');
52 52
 	if (lastSlash == std::basic_string<T>::npos)
53 53
 		lastSlash = fullPath.rfind('/');
54 54
 	return lastSlash != std::basic_string<T>::npos ? fullPath.substr(lastSlash + 1) : std::basic_string<T>();
... ...
@@ -56,7 +56,7 @@ template<typename T> inline std::basic_string<T> ExtractFilenameFromPath(const s
56 56
 
57 57
 // Code from the following answer on Stack Overflow:
58 58
 // http://stackoverflow.com/a/15479212
59
-template<typename T> static inline T NextHighestPowerOf2(T value)
59
+template<typename T> inline T NextHighestPowerOf2(T value)
60 60
 {
61 61
 	if (value < 1)
62 62
 		return 1;
Browse code

Fixed getting the path of the filename for XSFFile.

Naram Qashat authored on 2013/03/26 06:58:50
Showing 1 changed files
... ...
@@ -45,6 +45,15 @@ template<typename T> inline std::basic_string<T> ExtractDirectoryFromPath(const
45 45
 	return lastSlash != std::basic_string<T>::npos ? fullPath.substr(0, lastSlash + 1) : std::basic_string<T>();
46 46
 }
47 47
 
48
+// This gets the filename for the path
49
+template<typename T> inline std::basic_string<T> ExtractFilenameFromPath(const std::basic_string<T> &fullPath)
50
+{
51
+	size_t lastSlash = fullPath.rfind('\\');
52
+	if (lastSlash == std::basic_string<T>::npos)
53
+		lastSlash = fullPath.rfind('/');
54
+	return lastSlash != std::basic_string<T>::npos ? fullPath.substr(lastSlash + 1) : std::basic_string<T>();
55
+}
56
+
48 57
 // Code from the following answer on Stack Overflow:
49 58
 // http://stackoverflow.com/a/15479212
50 59
 template<typename T> static inline T NextHighestPowerOf2(T value)
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,74 @@
1
+/*
2
+ * xSF - Common functions
3
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
+ * Last modification on 2013-03-21
5
+ *
6
+ * Partially based on the vio*sf framework
7
+ */
8
+
9
+#ifndef XSFCOMMON_H
10
+#define XSFCOMMON_H
11
+
12
+#include <limits>
13
+#include <fstream>
14
+#include <string>
15
+#define _USE_MATH_DEFINES
16
+#include <cmath>
17
+#include "pstdint.h"
18
+
19
+// Code from http://learningcppisfun.blogspot.com/2010/04/comparing-floating-point-numbers.html
20
+template<typename T> inline bool fEqual(T x, T y, int N = 1)
21
+{
22
+	T diff = std::abs(x - y);
23
+	T tolerance = N * std::numeric_limits<T>::epsilon();
24
+	return diff <= tolerance * std::abs(x) && diff <= tolerance * std::abs(y);
25
+}
26
+
27
+inline uint32_t Get32BitsLE(const uint8_t *input)
28
+{
29
+	return input[0] | (input[1] << 8) | (input[2] << 16) | (input[3] << 24);
30
+}
31
+
32
+inline uint32_t Get32BitsLE(std::ifstream &input)
33
+{
34
+	uint8_t bytes[4];
35
+	input.read(reinterpret_cast<char *>(bytes), 4);
36
+	return Get32BitsLE(bytes);
37
+}
38
+
39
+// This gets the directory for the path, including the final forward/backward slash
40
+template<typename T> inline std::basic_string<T> ExtractDirectoryFromPath(const std::basic_string<T> &fullPath)
41
+{
42
+	size_t lastSlash = fullPath.rfind('\\');
43
+	if (lastSlash == std::basic_string<T>::npos)
44
+		lastSlash = fullPath.rfind('/');
45
+	return lastSlash != std::basic_string<T>::npos ? fullPath.substr(0, lastSlash + 1) : std::basic_string<T>();
46
+}
47
+
48
+// Code from the following answer on Stack Overflow:
49
+// http://stackoverflow.com/a/15479212
50
+template<typename T> static inline T NextHighestPowerOf2(T value)
51
+{
52
+	if (value < 1)
53
+		return 1;
54
+	--value;
55
+	for (size_t i = 1; i < sizeof(T) * CHAR_BIT; i <<= 1)
56
+		value |= value >> i;
57
+	return value + 1;
58
+}
59
+
60
+inline bool FileExists(const std::string &filename)
61
+{
62
+	std::ifstream file((filename.c_str()));
63
+	return !!file;
64
+}
65
+
66
+#ifdef _WIN32
67
+inline bool FileExists(const std::wstring &filename)
68
+{
69
+	std::ifstream file((filename.c_str()));
70
+	return !!file;
71
+}
72
+#endif
73
+
74
+#endif