Skip to content

Commit dc67350

Browse files
committed
windows: support dll library for oopertis-recordings
add export or import declarations, to be able to build libraries as dll also make RecordingReader an iterator
1 parent 962e6cf commit dc67350

File tree

9 files changed

+89
-52
lines changed

9 files changed

+89
-52
lines changed

src/libs/core/helper/parse_json.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,9 @@ namespace json {
129129
}
130130
}
131131

132-
133132
OOPETRIS_EXPORTED std::string get_json_type(const nlohmann::json::value_t& type);
134133

135134
OOPETRIS_EXPORTED void
136135
check_for_no_additional_keys(const nlohmann::json& obj, const std::vector<std::string>& keys);
137136

138-
139137
} // namespace json

src/libs/recordings/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ liboopetris_recordings = library(
1717
include_directories: recordings_lib.get('inc_dirs'),
1818
dependencies: recordings_lib.get('deps'),
1919
cpp_args: recordings_lib.get('compile_args'),
20+
cpp_shared_args: ['-DOOPETRIS_LIBRARY_EXPORT'],
2021
override_options: {
2122
'warning_level': '3',
2223
'werror': true,

src/libs/recordings/utility/additional_information.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "./helper.hpp"
66
#include <core/helper/expected.hpp>
77
#include <core/helper/types.hpp>
8+
#include <core/helper/windows.hpp>
89

910
#include <fmt/format.h>
1011
#include <fmt/ranges.h>
@@ -64,7 +65,7 @@ namespace recorder {
6465
return m_value;
6566
}
6667

67-
[[nodiscard]] std::string to_string(u32 recursion_depth = 0) const;
68+
OOPETRIS_EXPORTED [[nodiscard]] std::string to_string(u32 recursion_depth = 0) const;
6869

6970
template<typename T>
7071
[[nodiscard]] bool operator==(const T& other) const { // NOLINT(misc-no-recursion)
@@ -114,13 +115,13 @@ namespace recorder {
114115
);
115116
}
116117

117-
static helper::expected<std::pair<std::string, InformationValue>, std::string> read_from_istream(
118+
OOPETRIS_EXPORTED static helper::expected<std::pair<std::string, InformationValue>, std::string> read_from_istream(
118119
std::istream& istream
119120
);
120121

121-
[[nodiscard]] helper::expected<std::vector<char>, std::string> to_bytes(u32 recursion_depth = 0) const;
122+
OOPETRIS_EXPORTED[[nodiscard]] helper::expected<std::vector<char>, std::string> to_bytes(u32 recursion_depth = 0) const;
122123

123-
[[nodiscard]] static std::vector<char> string_to_bytes(const std::string& value);
124+
OOPETRIS_EXPORTED [[nodiscard]] static std::vector<char> string_to_bytes(const std::string& value);
124125

125126
private:
126127
static helper::expected<std::string, std::string> read_string_from_istream(std::istream& istream);
@@ -141,22 +142,21 @@ namespace recorder {
141142
explicit AdditionalInformation(UnderlyingContainer&& values);
142143

143144
public:
144-
explicit AdditionalInformation();
145+
OOPETRIS_EXPORTED explicit AdditionalInformation();
145146

146-
static helper::expected<AdditionalInformation, std::string> from_istream(std::istream& istream);
147+
OOPETRIS_EXPORTED static helper::expected<AdditionalInformation, std::string> from_istream(std::istream& istream);
147148

148-
149-
void add_value(const std::string& key, const InformationValue& value, bool overwrite = false);
149+
OOPETRIS_EXPORTED void add_value(const std::string& key, const InformationValue& value, bool overwrite = false);
150150

151151
template<typename T>
152152
void add(const std::string& key, const T& raw_value, bool overwrite = false) {
153153
const auto value = InformationValue{ raw_value };
154154
add_value(key, value, overwrite);
155155
}
156156

157-
[[nodiscard]] std::optional<InformationValue> get(const std::string& key) const;
157+
OOPETRIS_EXPORTED [[nodiscard]] std::optional<InformationValue> get(const std::string& key) const;
158158

159-
[[nodiscard]] bool has(const std::string& key) const;
159+
OOPETRIS_EXPORTED [[nodiscard]] bool has(const std::string& key) const;
160160

161161
template<typename T>
162162
[[nodiscard]] std::optional<T> get_if(const std::string& key) const {
@@ -174,9 +174,9 @@ namespace recorder {
174174
return value.as<T>();
175175
}
176176

177-
[[nodiscard]] helper::expected<std::vector<char>, std::string> to_bytes() const;
177+
OOPETRIS_EXPORTED [[nodiscard]] helper::expected<std::vector<char>, std::string> to_bytes() const;
178178

179-
[[nodiscard]] helper::expected<Sha256Stream::Checksum, std::string> get_checksum() const;
179+
OOPETRIS_EXPORTED [[nodiscard]] helper::expected<Sha256Stream::Checksum, std::string> get_checksum() const;
180180

181181
// iterator trait
182182
using iterator = UnderlyingContainer::iterator; //NOLINT(readability-identifier-naming)
@@ -188,13 +188,13 @@ namespace recorder {
188188
using iterator_category = std::bidirectional_iterator_tag; //NOLINT(readability-identifier-naming)
189189

190190

191-
[[nodiscard]] iterator begin();
191+
OOPETRIS_EXPORTED [[nodiscard]] iterator begin();
192192

193-
[[nodiscard]] const_iterator begin() const;
193+
OOPETRIS_EXPORTED [[nodiscard]] const_iterator begin() const;
194194

195-
[[nodiscard]] iterator end();
195+
OOPETRIS_EXPORTED [[nodiscard]] iterator end();
196196

197-
[[nodiscard]] const_iterator end() const;
197+
OOPETRIS_EXPORTED [[nodiscard]] const_iterator end() const;
198198
};
199199

200200
STATIC_ASSERT_WITH_MESSAGE(

src/libs/recordings/utility/checksum_helper.hpp

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

55
#include <core/hash-library/sha256.h>
66
#include <core/helper/utils.hpp>
7+
#include <core/helper/windows.hpp>
78

89
#include <array>
910
#include <string>
@@ -27,7 +28,7 @@ struct Sha256Stream {
2728
return *this;
2829
}
2930

30-
Sha256Stream& operator<<(const std::string& value);
31+
OOPETRIS_EXPORTED Sha256Stream& operator<<(const std::string& value);
3132

3233
template<typename T>
3334
Sha256Stream& operator<<(const std::vector<T>& values) {
@@ -47,5 +48,5 @@ struct Sha256Stream {
4748
return *this;
4849
}
4950

50-
[[nodiscard]] Checksum get_hash();
51+
OOPETRIS_EXPORTED [[nodiscard]] Checksum get_hash();
5152
};

src/libs/recordings/utility/recording.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <core/helper/input_event.hpp>
44
#include <core/helper/random.hpp>
55
#include <core/helper/types.hpp>
6+
#include <core/helper/windows.hpp>
67

78
#include "./additional_information.hpp"
89
#include "./checksum_helper.hpp"
@@ -36,7 +37,7 @@ namespace recorder {
3637
Random::Seed seed;
3738
u32 starting_level;
3839

39-
TetrionHeader(Random::Seed seed, u32 starting_level);
40+
OOPETRIS_EXPORTED TetrionHeader(Random::Seed seed, u32 starting_level);
4041
};
4142

4243
struct Recording {
@@ -57,11 +58,11 @@ namespace recorder {
5758
Recording& operator=(Recording&&) = delete;
5859
virtual ~Recording() = default;
5960

60-
[[nodiscard]] const std::vector<TetrionHeader>& tetrion_headers() const;
61+
OOPETRIS_EXPORTED [[nodiscard]] const std::vector<TetrionHeader>& tetrion_headers() const;
6162

62-
[[nodiscard]] const AdditionalInformation& information() const;
63+
OOPETRIS_EXPORTED [[nodiscard]] const AdditionalInformation& information() const;
6364

64-
[[nodiscard]] static Sha256Stream::Checksum get_header_checksum(
65+
OOPETRIS_EXPORTED [[nodiscard]] static Sha256Stream::Checksum get_header_checksum(
6566
u8 version_number,
6667
const std::vector<TetrionHeader>& tetrion_headers,
6768
const AdditionalInformation& information

src/libs/recordings/utility/recording_reader.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
recorder::RecordingReader::RecordingReader(
1212
std::vector<TetrionHeader>&& tetrion_headers,
1313
AdditionalInformation&& information,
14-
std::vector<Record>&& records,
14+
UnderlyingContainer&& records,
1515
std::vector<TetrionSnapshot>&& snapshots
1616
)
1717
: Recording{ std::move(tetrion_headers), std::move(information) },
@@ -166,11 +166,19 @@ helper::expected<recorder::RecordingReader, std::string> recorder::RecordingRead
166166
return m_records.size();
167167
}
168168

169-
[[nodiscard]] auto recorder::RecordingReader::begin() const {
169+
[[nodiscard]] recorder::RecordingReader::iterator recorder::RecordingReader::begin() {
170+
return m_records.begin();
171+
}
172+
173+
[[nodiscard]] recorder::RecordingReader::const_iterator recorder::RecordingReader::begin() const {
170174
return m_records.cbegin();
171175
}
172176

173-
[[nodiscard]] auto recorder::RecordingReader::end() const {
177+
[[nodiscard]] recorder::RecordingReader::iterator recorder::RecordingReader::end() {
178+
return m_records.end();
179+
}
180+
181+
[[nodiscard]] recorder::RecordingReader::const_iterator recorder::RecordingReader::end() const {
174182
return m_records.cend();
175183
}
176184

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

3+
#include <core/helper/windows.hpp>
4+
35
#include "./helper.hpp"
46

57
#include "./recording.hpp"
@@ -11,35 +13,54 @@ namespace recorder {
1113

1214
struct RecordingReader : public Recording {
1315
private:
14-
std::vector<Record> m_records;
16+
using UnderlyingContainer = std::vector<Record>;
17+
18+
UnderlyingContainer m_records;
1519
std::vector<TetrionSnapshot> m_snapshots;
1620

1721
explicit RecordingReader(
1822
std::vector<TetrionHeader>&& tetrion_headers,
1923
AdditionalInformation&& information,
20-
std::vector<Record>&& records,
24+
UnderlyingContainer&& records,
2125
std::vector<TetrionSnapshot>&& snapshots
2226
);
2327

2428
public:
25-
RecordingReader(RecordingReader&& old) noexcept;
29+
OOPETRIS_EXPORTED RecordingReader(RecordingReader&& old) noexcept;
2630

27-
static helper::expected<RecordingReader, std::string> from_path(const std::filesystem::path& path);
31+
OOPETRIS_EXPORTED static helper::expected<RecordingReader, std::string> from_path(
32+
const std::filesystem::path& path
33+
);
2834

29-
[[nodiscard]] const Record& at(usize index) const;
35+
OOPETRIS_EXPORTED [[nodiscard]] const Record& at(usize index) const;
3036

31-
[[nodiscard]] usize num_records() const;
32-
[[nodiscard]] auto begin() const;
33-
[[nodiscard]] auto end() const;
37+
OOPETRIS_EXPORTED [[nodiscard]] usize num_records() const;
3438

35-
[[nodiscard]] const std::vector<Record>& records() const;
39+
OOPETRIS_EXPORTED [[nodiscard]] const UnderlyingContainer& records() const;
3640

37-
[[nodiscard]] const std::vector<TetrionSnapshot>& snapshots() const;
41+
OOPETRIS_EXPORTED [[nodiscard]] const std::vector<TetrionSnapshot>& snapshots() const;
3842

39-
[[nodiscard]] static helper::
43+
OOPETRIS_EXPORTED [[nodiscard]] static helper::
4044
expected<std::pair<recorder::AdditionalInformation, std::vector<recorder::TetrionHeader>>, std::string>
4145
is_header_valid(const std::filesystem::path& path);
4246

47+
// iterator trait
48+
using iterator = UnderlyingContainer::iterator; //NOLINT(readability-identifier-naming)
49+
using const_iterator = UnderlyingContainer::const_iterator; //NOLINT(readability-identifier-naming)
50+
using difference_type = UnderlyingContainer::difference_type; //NOLINT(readability-identifier-naming)
51+
using value_type = UnderlyingContainer::value_type; //NOLINT(readability-identifier-naming)
52+
using pointer = UnderlyingContainer::pointer; //NOLINT(readability-identifier-naming)
53+
using reference = UnderlyingContainer::reference; //NOLINT(readability-identifier-naming)
54+
using iterator_category = std::bidirectional_iterator_tag; //NOLINT(readability-identifier-naming)
55+
56+
OOPETRIS_EXPORTED [[nodiscard]] iterator begin();
57+
58+
OOPETRIS_EXPORTED [[nodiscard]] const_iterator begin() const;
59+
60+
OOPETRIS_EXPORTED [[nodiscard]] iterator end();
61+
62+
OOPETRIS_EXPORTED [[nodiscard]] const_iterator end() const;
63+
4364
private:
4465
[[nodiscard]] static helper::expected<
4566
std::tuple<std::ifstream, std::vector<TetrionHeader>, recorder::AdditionalInformation>,
@@ -53,4 +74,6 @@ namespace recorder {
5374
[[nodiscard]] static helper::reader::ReadResult<Record> read_record_from_file(std::ifstream& file);
5475
};
5576

77+
STATIC_ASSERT_WITH_MESSAGE(utils::IsIterator<RecordingReader>::value, "RecordingReader has to be an iterator");
78+
5679
} // namespace recorder

src/libs/recordings/utility/recording_writer.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "./helper.hpp"
55
#include "./recording.hpp"
66
#include "./tetrion_core_information.hpp"
7+
78
#include <core/helper/expected.hpp>
9+
#include <core/helper/windows.hpp>
810

911
#include <filesystem>
1012

@@ -21,21 +23,22 @@ namespace recorder {
2123
);
2224

2325
public:
24-
RecordingWriter(RecordingWriter&& old) noexcept;
26+
OOPETRIS_EXPORTED RecordingWriter(RecordingWriter&& old) noexcept;
2527

26-
static helper::expected<RecordingWriter, std::string> get_writer(
28+
OOPETRIS_EXPORTED static helper::expected<RecordingWriter, std::string> get_writer(
2729
const std::filesystem::path& path,
2830
std::vector<TetrionHeader>&& tetrion_headers,
2931
AdditionalInformation&& information,
3032
bool overwrite = false
3133
);
3234

33-
[[nodiscard]] helper::expected<void, std::string> add_record(
35+
OOPETRIS_EXPORTED [[nodiscard]] helper::expected<void, std::string> add_record(
3436
u8 tetrion_index, // NOLINT(bugprone-easily-swappable-parameters)
3537
u64 simulation_step_index,
3638
InputEvent event
3739
);
38-
[[nodiscard]] helper::expected<void, std::string>
40+
41+
OOPETRIS_EXPORTED [[nodiscard]] helper::expected<void, std::string>
3942
add_snapshot(u64 simulation_step_index, std::unique_ptr<TetrionCoreInformation> information);
4043

4144
private:

src/libs/recordings/utility/tetrion_snapshot.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <core/game/mino_stack.hpp>
44
#include <core/helper/expected.hpp>
55
#include <core/helper/utils.hpp>
6+
#include <core/helper/windows.hpp>
67

78
#include "./tetrion_core_information.hpp"
89

@@ -29,7 +30,7 @@ struct TetrionSnapshot final {
2930
using MinoCount = u64;
3031
using Coordinate = u8;
3132

32-
TetrionSnapshot(
33+
OOPETRIS_EXPORTED TetrionSnapshot(
3334
u8 tetrion_index,
3435
Level level,
3536
Score score,
@@ -38,23 +39,24 @@ struct TetrionSnapshot final {
3839
MinoStack mino_stack
3940
);
4041

41-
static helper::expected<TetrionSnapshot, std::string> from_istream(std::istream& istream);
42+
OOPETRIS_EXPORTED static helper::expected<TetrionSnapshot, std::string> from_istream(std::istream& istream);
4243

44+
OOPETRIS_EXPORTED
4345
TetrionSnapshot(std::unique_ptr<TetrionCoreInformation> information, SimulationStep simulation_step_index);
4446

45-
[[nodiscard]] u8 tetrion_index() const;
47+
OOPETRIS_EXPORTED [[nodiscard]] u8 tetrion_index() const;
4648

47-
[[nodiscard]] Level level() const;
49+
OOPETRIS_EXPORTED [[nodiscard]] Level level() const;
4850

49-
[[nodiscard]] Score score() const;
51+
OOPETRIS_EXPORTED [[nodiscard]] Score score() const;
5052

51-
[[nodiscard]] LineCount lines_cleared() const;
53+
OOPETRIS_EXPORTED [[nodiscard]] LineCount lines_cleared() const;
5254

53-
[[nodiscard]] u64 simulation_step_index() const;
55+
OOPETRIS_EXPORTED [[nodiscard]] u64 simulation_step_index() const;
5456

55-
[[nodiscard]] const MinoStack& mino_stack() const;
57+
OOPETRIS_EXPORTED [[nodiscard]] const MinoStack& mino_stack() const;
5658

57-
[[nodiscard]] std::vector<char> to_bytes() const;
59+
OOPETRIS_EXPORTED [[nodiscard]] std::vector<char> to_bytes() const;
5860

59-
[[nodiscard]] helper::expected<void, std::string> compare_to(const TetrionSnapshot& other) const;
61+
OOPETRIS_EXPORTED [[nodiscard]] helper::expected<void, std::string> compare_to(const TetrionSnapshot& other) const;
6062
};

0 commit comments

Comments
 (0)