Skip to content

Commit 9f5f2cf

Browse files
committed
windows: support dll library for oopertis-core
add export or import declarations, to be able to build libraries as dll
1 parent 06e7daf commit 9f5f2cf

File tree

14 files changed

+116
-68
lines changed

14 files changed

+116
-68
lines changed

src/libs/core/game/mino.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "../helper/point.hpp"
44
#include "../helper/types.hpp"
5+
#include "../helper/windows.hpp"
56
#include "./grid_properties.hpp"
67
#include "./tetromino_type.hpp"
78

@@ -16,15 +17,17 @@ struct Mino final {
1617
helper::TetrominoType m_type;
1718

1819
public:
19-
explicit constexpr Mino(GridPoint position, helper::TetrominoType type) : m_position{ position }, m_type{ type } { }
20+
OOPETRIS_EXPORTED explicit constexpr Mino(GridPoint position, helper::TetrominoType type)
21+
: m_position{ position },
22+
m_type{ type } { }
2023

21-
[[nodiscard]] helper::TetrominoType type() const;
24+
OOPETRIS_EXPORTED [[nodiscard]] helper::TetrominoType type() const;
2225

23-
[[nodiscard]] const GridPoint& position() const;
26+
OOPETRIS_EXPORTED [[nodiscard]] const GridPoint& position() const;
2427

25-
[[nodiscard]] GridPoint& position();
28+
OOPETRIS_EXPORTED [[nodiscard]] GridPoint& position();
2629

27-
[[nodiscard]] bool operator==(const Mino& other) const;
30+
OOPETRIS_EXPORTED [[nodiscard]] bool operator==(const Mino& other) const;
2831

29-
[[nodiscard]] bool operator!=(const Mino& other) const;
32+
OOPETRIS_EXPORTED [[nodiscard]] bool operator!=(const Mino& other) const;
3033
};

src/libs/core/game/mino_stack.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "../helper/types.hpp"
4+
#include "../helper/windows.hpp"
45
#include "./mino.hpp"
56

67
#include <vector>
@@ -13,17 +14,19 @@ struct MinoStack final {
1314
std::vector<Mino> m_minos;
1415

1516
public:
16-
void clear_row_and_let_sink(u8 row);
17-
[[nodiscard]] bool is_empty(GridPoint coordinates) const;
18-
void set(GridPoint coordinates, helper::TetrominoType type);
17+
OOPETRIS_EXPORTED void clear_row_and_let_sink(u8 row);
1918

20-
[[nodiscard]] u32 num_minos() const;
19+
OOPETRIS_EXPORTED [[nodiscard]] bool is_empty(GridPoint coordinates) const;
2120

22-
[[nodiscard]] const std::vector<Mino>& minos() const;
21+
OOPETRIS_EXPORTED void set(GridPoint coordinates, helper::TetrominoType type);
2322

24-
[[nodiscard]] bool operator==(const MinoStack& other) const;
23+
OOPETRIS_EXPORTED [[nodiscard]] u32 num_minos() const;
2524

26-
[[nodiscard]] bool operator!=(const MinoStack& other) const;
25+
OOPETRIS_EXPORTED [[nodiscard]] const std::vector<Mino>& minos() const;
26+
27+
OOPETRIS_EXPORTED [[nodiscard]] bool operator==(const MinoStack& other) const;
28+
29+
OOPETRIS_EXPORTED [[nodiscard]] bool operator!=(const MinoStack& other) const;
2730
};
2831

29-
std::ostream& operator<<(std::ostream& ostream, const MinoStack& mino_stack);
32+
OOPETRIS_EXPORTED std::ostream& operator<<(std::ostream& ostream, const MinoStack& mino_stack);

src/libs/core/game/tetromino_type.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "../helper/color.hpp"
44
#include "../helper/types.hpp"
5+
#include "../helper/windows.hpp"
56

67
namespace helper {
78

@@ -16,8 +17,8 @@ namespace helper {
1617
LastType = Z,
1718
};
1819

19-
[[nodiscard]] Color get_foreground_color(TetrominoType type, u8 alpha);
20+
OOPETRIS_EXPORTED [[nodiscard]] Color get_foreground_color(TetrominoType type, u8 alpha);
2021

21-
[[nodiscard]] Color get_background_color(TetrominoType type, u8 alpha);
22+
OOPETRIS_EXPORTED [[nodiscard]] Color get_background_color(TetrominoType type, u8 alpha);
2223

2324
} // namespace helper

src/libs/core/hash-library/sha256.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@
1717
typedef unsigned __int8 uint8_t;
1818
typedef unsigned __int32 uint32_t;
1919
typedef unsigned __int64 uint64_t;
20+
21+
#if defined(HASH_LIBRARY_EXPORT)
22+
#define HASH_LIBRARY_EXPORTED __declspec(dllexport)
23+
#else
24+
#define HASH_LIBRARY_EXPORTED __declspec(dllimport)
25+
#endif
26+
2027
#else
2128
// GCC
2229
#include <stdint.h>
30+
31+
#define HASH_LIBRARY_EXPORTED
2332
#endif
2433

2534
namespace hash_library {
@@ -44,23 +53,23 @@ namespace hash_library {
4453
enum { BlockSize = 512 / 8, HashBytes = 32 };
4554

4655
/// same as reset()
47-
SHA256();
56+
HASH_LIBRARY_EXPORTED SHA256();
4857

4958
/// compute SHA256 of a memory block
50-
std::string operator()(const void* data, size_t numBytes);
59+
HASH_LIBRARY_EXPORTED std::string operator()(const void* data, size_t numBytes);
5160
/// compute SHA256 of a string, excluding final zero
52-
std::string operator()(const std::string& text);
61+
HASH_LIBRARY_EXPORTED std::string operator()(const std::string& text);
5362

5463
/// add arbitrary number of bytes
55-
void add(const void* data, size_t numBytes);
64+
HASH_LIBRARY_EXPORTED void add(const void* data, size_t numBytes);
5665

5766
/// return latest hash as 64 hex characters
58-
std::string getHash();
67+
HASH_LIBRARY_EXPORTED std::string getHash();
5968
/// return latest hash as bytes
60-
void getHash(unsigned char buffer[HashBytes]);
69+
HASH_LIBRARY_EXPORTED void getHash(unsigned char buffer[HashBytes]);
6170

6271
/// restart
63-
void reset();
72+
HASH_LIBRARY_EXPORTED void reset();
6473

6574
private:
6675
/// process 64 bytes

src/libs/core/helper/color.hpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "./expected.hpp"
55
#include "./types.hpp"
66
#include "./utils.hpp"
7+
#include "./windows.hpp"
78

89
#include <algorithm>
910
#include <cmath>
@@ -61,17 +62,20 @@ struct HSVColor {
6162

6263
constexpr HSVColor() : HSVColor{ 0.0, 0.0, 0.0, 0 } { }
6364

64-
[[nodiscard]] static helper::expected<HSVColor, std::string> from_string(const std::string& value);
65+
OOPETRIS_EXPORTED [[nodiscard]] static helper::expected<HSVColor, std::string> from_string(const std::string& value
66+
);
6567

6668
using InfoType = std::tuple<HSVColor, color::SerializeMode, bool>;
6769

68-
[[nodiscard]] static helper::expected<InfoType, std::string> from_string_with_info(const std::string& value);
70+
OOPETRIS_EXPORTED [[nodiscard]] static helper::expected<InfoType, std::string> from_string_with_info(
71+
const std::string& value
72+
);
6973

70-
[[nodiscard]] Color to_rgb_color() const;
74+
OOPETRIS_EXPORTED [[nodiscard]] Color to_rgb_color() const;
7175

72-
[[nodiscard]] std::string to_string(bool force_alpha = false) const;
76+
OOPETRIS_EXPORTED [[nodiscard]] std::string to_string(bool force_alpha = false) const;
7377

74-
std::ostream& operator<<(std::ostream& os) const;
78+
OOPETRIS_EXPORTED std::ostream& operator<<(std::ostream& os) const;
7579
};
7680

7781
namespace { //NOLINT(cert-dcl59-cpp,google-build-namespaces)
@@ -135,14 +139,16 @@ struct Color {
135139

136140
constexpr Color(u8 red, u8 green, u8 blue) : Color{ red, green, blue, 0xFF } { }
137141

138-
[[nodiscard]] static helper::expected<Color, std::string> from_string(const std::string& value);
142+
OOPETRIS_EXPORTED [[nodiscard]] static helper::expected<Color, std::string> from_string(const std::string& value);
139143

140144
using InfoType = std::tuple<Color, color::SerializeMode, bool>;
141145

142-
[[nodiscard]] static helper::expected<InfoType, std::string> from_string_with_info(const std::string& value);
146+
OOPETRIS_EXPORTED [[nodiscard]] static helper::expected<InfoType, std::string> from_string_with_info(
147+
const std::string& value
148+
);
143149

144150

145-
[[nodiscard]] HSVColor to_hsv_color() const;
151+
OOPETRIS_EXPORTED [[nodiscard]] HSVColor to_hsv_color() const;
146152

147153
constexpr Color(const HSVColor& color) { //NOLINT(google-explicit-constructor)
148154

@@ -257,5 +263,5 @@ struct Color {
257263
[[nodiscard]] std::string to_string(color::SerializeMode mode = color::SerializeMode::RGB, bool force_alpha = false)
258264
const;
259265

260-
std::ostream& operator<<(std::ostream& os) const;
266+
OOPETRIS_EXPORTED std::ostream& operator<<(std::ostream& os) const;
261267
};

src/libs/core/helper/date.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "./expected.hpp"
44
#include "./types.hpp"
5+
#include "./windows.hpp"
56

67
#include <ctime>
78
#include <string>
@@ -17,14 +18,14 @@ namespace date {
1718
static constexpr const char* iso_8601_format_string = "%Y%m%dT%H%M%S";
1819

1920
public:
20-
ISO8601Date(u64 value);
21+
OOPETRIS_EXPORTED ISO8601Date(u64 value);
2122

22-
static ISO8601Date now();
23-
static helper::expected<ISO8601Date, std::string> from_string(const std::string& input);
23+
OOPETRIS_EXPORTED static ISO8601Date now();
24+
OOPETRIS_EXPORTED static helper::expected<ISO8601Date, std::string> from_string(const std::string& input);
2425

25-
[[nodiscard]] helper::expected<std::string, std::string> to_string() const;
26+
OOPETRIS_EXPORTED [[nodiscard]] helper::expected<std::string, std::string> to_string() const;
2627

27-
[[nodiscard]] u64 value() const;
28+
OOPETRIS_EXPORTED [[nodiscard]] u64 value() const;
2829

2930
private:
3031
[[nodiscard]] static helper::expected<std::tm, std::string> get_tm_struct(std::time_t value);

src/libs/core/helper/errors.hpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#pragma once
44

5+
#include "./windows.hpp"
6+
57
#include <exception>
68
#include <string>
79

@@ -17,40 +19,40 @@ namespace helper {
1719
error::Severity m_severity;
1820

1921
public:
20-
GeneralError(const std::string& message, error::Severity severity) noexcept;
22+
OOPETRIS_EXPORTED GeneralError(const std::string& message, error::Severity severity) noexcept;
2123

22-
GeneralError(std::string&& message, error::Severity severity) noexcept;
24+
OOPETRIS_EXPORTED GeneralError(std::string&& message, error::Severity severity) noexcept;
2325

24-
~GeneralError();
26+
OOPETRIS_EXPORTED ~GeneralError();
2527

26-
GeneralError(const GeneralError& error) noexcept;
28+
OOPETRIS_EXPORTED GeneralError(const GeneralError& error) noexcept;
2729
[[nodiscard]] GeneralError& operator=(const GeneralError& error) noexcept;
2830

29-
GeneralError(GeneralError&& error) noexcept;
30-
[[nodiscard]] GeneralError& operator=(GeneralError&& error) noexcept;
31+
OOPETRIS_EXPORTED GeneralError(GeneralError&& error) noexcept;
32+
OOPETRIS_EXPORTED [[nodiscard]] GeneralError& operator=(GeneralError&& error) noexcept;
3133

32-
[[nodiscard]] const std::string& message() const;
33-
[[nodiscard]] error::Severity severity() const;
34+
OOPETRIS_EXPORTED [[nodiscard]] const std::string& message() const;
35+
OOPETRIS_EXPORTED [[nodiscard]] error::Severity severity() const;
3436

35-
[[nodiscard]] const char* what() const noexcept override;
37+
OOPETRIS_EXPORTED [[nodiscard]] const char* what() const noexcept override;
3638
};
3739

3840
struct FatalError : public GeneralError {
39-
explicit FatalError(const std::string& message) noexcept;
41+
OOPETRIS_EXPORTED explicit FatalError(const std::string& message) noexcept;
4042

41-
explicit FatalError(std::string&& message) noexcept;
43+
OOPETRIS_EXPORTED explicit FatalError(std::string&& message) noexcept;
4244
};
4345

4446
struct MajorError : public GeneralError {
45-
explicit MajorError(const std::string& message) noexcept;
47+
OOPETRIS_EXPORTED explicit MajorError(const std::string& message) noexcept;
4648

47-
explicit MajorError(std::string&& message) noexcept;
49+
OOPETRIS_EXPORTED explicit MajorError(std::string&& message) noexcept;
4850
};
4951

5052
struct MinorError : public GeneralError {
51-
explicit MinorError(const std::string& message) noexcept;
53+
OOPETRIS_EXPORTED explicit MinorError(const std::string& message) noexcept;
5254

53-
explicit MinorError(std::string&& message) noexcept;
55+
OOPETRIS_EXPORTED explicit MinorError(std::string&& message) noexcept;
5456
};
5557

5658
using InitializationError = FatalError;

src/libs/core/helper/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ _header_files = files(
2828
'types.hpp',
2929
'utils.hpp',
3030
'versions.hpp',
31+
'windows.hpp',
3132
)
3233
core_header_files += _header_files
3334

src/libs/core/helper/parse_json.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <nlohmann/json.hpp>
1010

1111
#include "./expected.hpp"
12-
12+
#include "./windows.hpp"
1313

1414
#include <filesystem>
1515
#include <fmt/format.h>
@@ -130,9 +130,10 @@ namespace json {
130130
}
131131

132132

133-
std::string get_json_type(const nlohmann::json::value_t& type);
133+
OOPETRIS_EXPORTED std::string get_json_type(const nlohmann::json::value_t& type);
134134

135-
void check_for_no_additional_keys(const nlohmann::json& obj, const std::vector<std::string>& keys);
135+
OOPETRIS_EXPORTED void
136+
check_for_no_additional_keys(const nlohmann::json& obj, const std::vector<std::string>& keys);
136137

137138

138139
} // namespace json

src/libs/core/helper/random.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "./utils.hpp"
4+
#include "./windows.hpp"
45

56
#include <random>
67

@@ -14,17 +15,20 @@ struct Random {
1415
std::uniform_real_distribution<double> m_uniform_real_distribution;
1516

1617
public:
17-
Random();
18-
explicit Random(std::mt19937_64::result_type seed);
18+
OOPETRIS_EXPORTED Random();
19+
OOPETRIS_EXPORTED explicit Random(std::mt19937_64::result_type seed);
1920

2021
template<utils::integral Integer>
2122
[[nodiscard]] Integer random(const Integer upper_bound_exclusive) {
2223
auto distribution = std::uniform_int_distribution<Integer>{ 0, upper_bound_exclusive - 1 };
2324
return distribution(m_generator);
2425
}
2526

26-
[[nodiscard]] double random();
27-
[[nodiscard]] Seed seed() const;
28-
void seed(Seed seed);
29-
static Seed generate_seed();
27+
OOPETRIS_EXPORTED [[nodiscard]] double random();
28+
29+
OOPETRIS_EXPORTED [[nodiscard]] Seed seed() const;
30+
31+
OOPETRIS_EXPORTED void seed(Seed seed);
32+
33+
OOPETRIS_EXPORTED static Seed generate_seed();
3034
};

0 commit comments

Comments
 (0)