Clean up and formatting

This commit is contained in:
Maschell
2020-12-26 14:17:50 +01:00
parent 0467178650
commit e9bd4651ca
30 changed files with 283 additions and 325 deletions

View File

@@ -1,5 +1,8 @@
#include "PluginData.h"
#include <utility>
#include <malloc.h>
#include "../utils/logger.h"
PluginData::PluginData(const PluginData &obj) {
this->buffer = obj.buffer;
@@ -9,7 +12,7 @@ PluginData::PluginData(const PluginData &obj) {
}
void PluginData::freeMemory() {
if (buffer == NULL) {
if (buffer == nullptr) {
return;
}
@@ -17,29 +20,29 @@ void PluginData::freeMemory() {
default:
case eMemTypeExpHeap:
MEMFreeToExpHeap(this->heapHandle, buffer);
this->buffer = NULL;
this->buffer = nullptr;
break;
case eMemTypeMEM2:
free(this->buffer);
this->buffer = NULL;
this->buffer = nullptr;
break;
}
}
PluginData::PluginData(std::vector<uint8_t> buffer) : PluginData(buffer, 0, eMemTypeMEM2) {
PluginData::PluginData(const std::vector<uint8_t>& buffer) : PluginData(buffer, nullptr, eMemTypeMEM2) {
}
PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
PluginData::PluginData(const std::vector<uint8_t>& input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
heapHandle(heapHandle),
memoryType(memoryType),
length(input.size()) {
void *data_copy = NULL;
void *data_copy = nullptr;
switch (memoryType) {
default:
case eMemTypeExpHeap:
data_copy = MEMAllocFromExpHeapEx(heapHandle, length, 4);
DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", length / 1024);
if (data_copy == NULL) {
if (data_copy == nullptr) {
DEBUG_FUNCTION_LINE("Failed to allocate space on exp heap");
} else {
memcpy(data_copy, &input[0], length);
@@ -49,7 +52,7 @@ PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMe
break;
case eMemTypeMEM2:
data_copy = memalign(length, 4);
if (data_copy == NULL) {
if (data_copy == nullptr) {
DEBUG_FUNCTION_LINE("Failed to allocate space on default heap");
} else {
memcpy(data_copy, &input[0], length);
@@ -57,8 +60,4 @@ PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMe
this->buffer = data_copy;
break;
}
}
std::optional<PluginData> PluginData::createFromExistingData(const void *buffer, MEMHeapHandle heapHandle, eMemoryTypes memoryType, const size_t length) {
return std::nullopt;
}
}