Skip to content

Commit 9261a33

Browse files
committed
Fix build
1 parent 8bfaac3 commit 9261a33

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

Common/Cpp/Containers/SparseArray.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void SparseArray::write(size_t address, size_t bytes, const void* data){
2020
m_data.emplace(
2121
std::piecewise_construct,
2222
std::forward_as_tuple(address),
23-
std::forward_as_tuple((uint8_t*)data, (uint8_t*)data + bytes)
23+
std::forward_as_tuple((char*)data, (char*)data + bytes)
2424
);
2525
return;
2626
}
@@ -32,7 +32,7 @@ void SparseArray::write(size_t address, size_t bytes, const void* data){
3232
m_data.emplace(
3333
std::piecewise_construct,
3434
std::forward_as_tuple(address),
35-
std::forward_as_tuple((uint8_t*)data, (uint8_t*)data + bytes)
35+
std::forward_as_tuple((char*)data, (char*)data + bytes)
3636
);
3737
return;
3838
}
@@ -43,7 +43,7 @@ void SparseArray::write(size_t address, size_t bytes, const void* data){
4343
m_data.emplace(
4444
std::piecewise_construct,
4545
std::forward_as_tuple(address),
46-
std::forward_as_tuple((uint8_t*)data, (uint8_t*)data + bytes)
46+
std::forward_as_tuple((char*)data, (char*)data + bytes)
4747
);
4848
return;
4949
}
@@ -72,7 +72,7 @@ void SparseArray::write(size_t address, size_t bytes, const void* data){
7272
lowest = std::min(lowest, address);
7373
highest = std::max(highest, top);
7474

75-
std::vector<uint8_t> block(highest - lowest);
75+
std::string block(highest - lowest, 0);
7676

7777
// Copy in the partial blocks.
7878
bool one_block = lower == upper;
@@ -161,7 +161,7 @@ void SparseArray::read(size_t address, size_t bytes, void* data) const{
161161
// cout << "address = " << address << endl;
162162
// cout << "block = " << block << endl;
163163

164-
const uint8_t* ptr = lower->second.data();
164+
const char* ptr = lower->second.data();
165165
size_t len = lower->second.size();
166166

167167
if (block < address){

Common/Cpp/Containers/SparseArray.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,25 @@
77
#ifndef PokemonAutomation_SparseArray_H
88
#define PokemonAutomation_SparseArray_H
99

10+
#include <string.h>
1011
#include <string>
11-
#include <vector>
1212
#include <map>
1313

1414
namespace PokemonAutomation{
1515

1616

1717
struct SparseArrayBlock{
1818
size_t address;
19-
size_t bytes;
20-
const void* data;
19+
std::string data;
20+
21+
SparseArrayBlock(size_t p_address, const char* str)
22+
: address(p_address)
23+
, data(str, str + strlen(str))
24+
{}
25+
SparseArrayBlock(size_t p_address, std::initializer_list<char> p_data)
26+
: address(p_address)
27+
, data(p_data)
28+
{}
2129
};
2230

2331

@@ -26,7 +34,7 @@ class SparseArray{
2634
SparseArray() = default;
2735
SparseArray(std::initializer_list<SparseArrayBlock> list){
2836
for (auto& item : list){
29-
write(item.address, item.bytes, item.data);
37+
write(item.address, item.data.size(), item.data.data());
3038
}
3139
}
3240

@@ -42,15 +50,15 @@ class SparseArray{
4250
ret += " : ";
4351
ret += std::to_string(item.first + item.second.size());
4452
ret += "} = ";
45-
ret += std::string((const char*)item.second.data(), item.second.size());
53+
ret += item.second;
4654
ret += "\n";
4755
}
4856
return ret;
4957
}
5058
#endif
5159

5260
private:
53-
std::map<size_t, std::vector<uint8_t>> m_data;
61+
std::map<size_t, std::string> m_data;
5462
};
5563

5664

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,11 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco
273273

274274
using namespace std::chrono_literals;
275275

276+
277+
276278
SparseArray data{
277-
{100, 10, "0123456789"},
278-
{120, 8, "asdfzxcv"},
279+
{100, "0123456789"},
280+
{120, {'a', 0x20, 'd'}},
279281
};
280282
// data.set_data(100, "0123456789", 10);
281283
// data.set_data(120, "asdfzxcv", 8);

0 commit comments

Comments
 (0)