Compare commits
No commits in common. "c3aab51030f3fc335780f334da6c8dcc9fda7d06" and "7fd3fbadb3b043ff21199ff66d13c9d8aaeddafd" have entirely different histories.
c3aab51030
...
7fd3fbadb3
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
project(BLT VERSION 0.6.1)
|
project(BLT VERSION 0.6.0)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
|
21
README.md
21
README.md
|
@ -1,4 +1,4 @@
|
||||||
# **BLT v0.6.1a**
|
# **BLT v0.6.0a**
|
||||||
A common utilities library I find useful
|
A common utilities library I find useful
|
||||||
|
|
||||||

|

|
||||||
|
@ -26,10 +26,11 @@ If you are using BLT as a CMake library (as you should!) this is done for you.
|
||||||
- ## Data Structures
|
- ## Data Structures
|
||||||
- Queue / Stack
|
- Queue / Stack
|
||||||
- faster than std::queue / std::stack
|
- faster than std::queue / std::stack
|
||||||
- backed by a contiguous array
|
- Binary Tree
|
||||||
|
- Hashmap (TODO)
|
||||||
- ## Utility
|
- ## Utility
|
||||||
- Simple Random Wrapper Interface
|
- Simple Random Interface
|
||||||
- Simple random functions based on the PCG Hash
|
- No more worrying about min/max bounds!
|
||||||
- ### String Functions
|
- ### String Functions
|
||||||
- starts_with
|
- starts_with
|
||||||
- ends_with
|
- ends_with
|
||||||
|
@ -39,12 +40,14 @@ If you are using BLT as a CMake library (as you should!) this is done for you.
|
||||||
- split
|
- split
|
||||||
- trim
|
- trim
|
||||||
- Logging
|
- Logging
|
||||||
- See blt::logging section above
|
- Trace / Debug / Info / Warn / Error / Fatal
|
||||||
|
- Log to file
|
||||||
|
- Log to console with color!
|
||||||
|
- Easy to disable for release
|
||||||
|
- define BLT_DISABLE_LOGGING before including the logging.h file.
|
||||||
- Time
|
- Time
|
||||||
- Current time in nanoseconds (without all the c++ gobbledygook)
|
- Current time in nanoseconds (without all the c++ gobbledygook)
|
||||||
- Java's currentTimeMilliseconds
|
|
||||||
- nanoTime as well
|
|
||||||
- `std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count()` becomes `blt::system::nanoTime()`
|
|
||||||
- Formatted time string with year/month/date + current time
|
- Formatted time string with year/month/date + current time
|
||||||
- ## Profiling
|
- ## Profiling
|
||||||
- Basic profiler with history and formatted output
|
- Basic profiler
|
||||||
|
- WIP
|
|
@ -36,26 +36,6 @@ namespace blt {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline constexpr double pow(int b, int p) {
|
|
||||||
int collection = 1;
|
|
||||||
for (int i = 0; i < p; i++)
|
|
||||||
collection *= b;
|
|
||||||
return collection;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a fast rounding function and is not guaranteed to be 100% correct
|
|
||||||
* @tparam decimal_places
|
|
||||||
* @param value
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
template<int decimal_places>
|
|
||||||
static inline double round_up(double value) {
|
|
||||||
constexpr double multiplier = pow(10, decimal_places);
|
|
||||||
return ((int)(value * multiplier) + 1) / multiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*inline std::ostream& operator<<(std::ostream& out, const mat4x4& v) {
|
/*inline std::ostream& operator<<(std::ostream& out, const mat4x4& v) {
|
||||||
return out << "\rMatrix4x4{" << v.m00() << ", " << v.m01() << ", " << v.m02() << ", " << v.m03() << "} \n"\
|
return out << "\rMatrix4x4{" << v.m00() << ", " << v.m01() << ", " << v.m02() << ", " << v.m03() << "} \n"\
|
||||||
<< " {" << v.m10() << ", " << v.m11() << ", " << v.m12() << ", " << v.m13() << "} \n"\
|
<< " {" << v.m10() << ", " << v.m11() << ", " << v.m12() << ", " << v.m13() << "} \n"\
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
#ifndef BLT_TESTS_NBT_H
|
#ifndef BLT_TESTS_NBT_H
|
||||||
#define BLT_TESTS_NBT_H
|
#define BLT_TESTS_NBT_H
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "blt/std/format.h"
|
#include "blt/std/format.h"
|
||||||
#include "blt/std/filesystem.h"
|
#include "blt/std/filesystem.h"
|
||||||
|
|
||||||
|
@ -17,43 +15,26 @@ namespace blt::nbt {
|
||||||
|
|
||||||
std::string readUTF8String(std::fstream& stream);
|
std::string readUTF8String(std::fstream& stream);
|
||||||
|
|
||||||
enum class nbt_tag : char {
|
enum nbt_type {
|
||||||
END = 0,
|
tag_end = 0,
|
||||||
BYTE = 1,
|
tag_byte = 1,
|
||||||
SHORT = 2,
|
tag_short = 2,
|
||||||
INT = 3,
|
tag_int = 3,
|
||||||
LONG = 4,
|
tag_long = 4,
|
||||||
FLOAT = 5,
|
tag_float = 5,
|
||||||
DOUBLE = 6,
|
tag_double = 6,
|
||||||
BYTE_ARRAY = 7,
|
tag_byte_array = 7,
|
||||||
STRING = 8,
|
tag_string = 8,
|
||||||
LIST = 9,
|
tag_list = 9,
|
||||||
COMPOUND = 10,
|
tag_compound = 10,
|
||||||
INT_ARRAY = 11,
|
tag_int_array = 11,
|
||||||
LONG_ARRAY = 12
|
tag_long_array = 12
|
||||||
};
|
};
|
||||||
|
|
||||||
class tag {
|
class nbt_tag {
|
||||||
public:
|
public:
|
||||||
virtual void writePayload(std::fstream& out) = 0;
|
virtual void readTag() = 0;
|
||||||
virtual void readPayload(std::fstream& in) = 0;
|
virtual void writeTag() = 0;
|
||||||
};
|
|
||||||
|
|
||||||
class named_tag : public tag {
|
|
||||||
private:
|
|
||||||
std::string name;
|
|
||||||
public:
|
|
||||||
explicit named_tag(std::string name): name(std::move(name)) {}
|
|
||||||
named_tag() = default;
|
|
||||||
void writeName(std::fstream& out);
|
|
||||||
void readName(std::fstream& in);
|
|
||||||
};
|
|
||||||
|
|
||||||
class tag_end : public tag {
|
|
||||||
public:
|
|
||||||
void writePayload(std::fstream& out) final;
|
|
||||||
// nothing to read
|
|
||||||
void readPayload(std::fstream& in) final {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class NBTDecoder {
|
class NBTDecoder {
|
||||||
|
@ -70,6 +51,7 @@ namespace blt::nbt {
|
||||||
class NBTReader {
|
class NBTReader {
|
||||||
private:
|
private:
|
||||||
std::string m_file;
|
std::string m_file;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NBTReader(std::string file): m_file(std::move(file)) {}
|
explicit NBTReader(std::string file): m_file(std::move(file)) {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,9 +10,27 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <blt/math/math.h>
|
|
||||||
|
|
||||||
namespace blt::string {
|
namespace blt::string {
|
||||||
|
static inline constexpr double _static_pow(int p) {
|
||||||
|
int collection = 1;
|
||||||
|
for (int i = 0; i < p; i++)
|
||||||
|
collection *= 10;
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a fast rounding function and is not guaranteed to be 100% correct
|
||||||
|
* @tparam decimal_places
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
template<int decimal_places>
|
||||||
|
static inline double round_up(double value) {
|
||||||
|
constexpr double multiplier = _static_pow(decimal_places);
|
||||||
|
return ((int)(value * multiplier) + 1) / multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline std::string fromBytes(unsigned long bytes){
|
static inline std::string fromBytes(unsigned long bytes){
|
||||||
if (bytes > 1073741824) {
|
if (bytes > 1073741824) {
|
||||||
|
@ -69,7 +87,8 @@ namespace blt::string {
|
||||||
|
|
||||||
// taken from java, adapted for c++.
|
// taken from java, adapted for c++.
|
||||||
static inline utf8_string createUTFString(const std::string& str) {
|
static inline utf8_string createUTFString(const std::string& str) {
|
||||||
const auto strlen = (unsigned int) str.size();
|
|
||||||
|
const unsigned int strlen = (unsigned int) str.size();
|
||||||
unsigned int utflen = strlen;
|
unsigned int utflen = strlen;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < strlen; i++) {
|
for (unsigned int i = 0; i < strlen; i++) {
|
||||||
|
|
|
@ -58,68 +58,39 @@ namespace blt {
|
||||||
* Creates an encapsulation of a T array which will be automatically deleted when this object goes out of scope.
|
* Creates an encapsulation of a T array which will be automatically deleted when this object goes out of scope.
|
||||||
* This is a simple buffer meant to be used only inside of a function and not moved around, with a few minor exceptions.
|
* This is a simple buffer meant to be used only inside of a function and not moved around, with a few minor exceptions.
|
||||||
* The internal buffer is allocated on the heap.
|
* The internal buffer is allocated on the heap.
|
||||||
* The operator * has been overloaded to return the internal buffer.
|
* The operator * has been overloaded to return the internal buffer. (or just use scoped_buffer.buffer if you wish to be explicit)
|
||||||
|
* The operator & was not used because I think it is stupid to do so.
|
||||||
|
* "*" on a reference is fine however since it isn't used to dereference in the case.
|
||||||
* @tparam T type that is stored in buffer eg char
|
* @tparam T type that is stored in buffer eg char
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct scoped_buffer {
|
struct scoped_buffer {
|
||||||
private:
|
T* buffer;
|
||||||
T* _buffer;
|
unsigned long size;
|
||||||
size_t _size;
|
|
||||||
public:
|
explicit scoped_buffer(unsigned long size): size(size) {
|
||||||
explicit scoped_buffer(size_t size): _size(size) {
|
buffer = new T[size];
|
||||||
_buffer = new T[size];
|
}
|
||||||
}
|
|
||||||
|
scoped_buffer(scoped_buffer& copy) = delete;
|
||||||
scoped_buffer(const scoped_buffer& copy) = delete;
|
|
||||||
|
scoped_buffer(scoped_buffer&& move) = delete;
|
||||||
scoped_buffer(scoped_buffer&& move) noexcept {
|
|
||||||
_buffer = move._buffer;
|
scoped_buffer operator=(scoped_buffer& copyAssignment) = delete;
|
||||||
_size = move.size();
|
|
||||||
move._buffer = nullptr;
|
scoped_buffer operator=(scoped_buffer&& moveAssignment) = delete;
|
||||||
}
|
|
||||||
|
inline T& operator[](unsigned long index) const {
|
||||||
scoped_buffer operator=(scoped_buffer& copyAssignment) = delete;
|
return buffer[index];
|
||||||
|
}
|
||||||
scoped_buffer& operator=(scoped_buffer&& moveAssignment) noexcept {
|
|
||||||
_buffer = moveAssignment._buffer;
|
inline T* operator*(){
|
||||||
_size = moveAssignment.size();
|
return buffer;
|
||||||
moveAssignment._buffer = nullptr;
|
}
|
||||||
|
|
||||||
return *this;
|
~scoped_buffer() {
|
||||||
}
|
delete[] buffer;
|
||||||
|
}
|
||||||
inline T& operator[](unsigned long index) {
|
|
||||||
return _buffer[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const T& operator[](unsigned long index) const {
|
|
||||||
return _buffer[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline T* operator*(){
|
|
||||||
return _buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] inline size_t size() const {
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline T* ptr(){
|
|
||||||
return _buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr_iterator<T> begin(){
|
|
||||||
return ptr_iterator{_buffer};
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr_iterator<T> end(){
|
|
||||||
return ptr_iterator{&_buffer[_size]};
|
|
||||||
}
|
|
||||||
|
|
||||||
~scoped_buffer() {
|
|
||||||
delete[] _buffer;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -197,7 +168,6 @@ namespace blt {
|
||||||
delete[] _values;
|
delete[] _values;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //BLT_TESTS_MEMORY_H
|
#endif //BLT_TESTS_MEMORY_H
|
||||||
|
|
|
@ -29,14 +29,6 @@ namespace blt::system {
|
||||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline auto nanoTime() {
|
|
||||||
return getCurrentTimeNanoseconds();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline auto getCurrentTimeMilliseconds(){
|
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard time string is formatted as follows:
|
* Standard time string is formatted as follows:
|
||||||
* Year-Month-Date Hour:Min:Second
|
* Year-Month-Date Hour:Min:Second
|
||||||
|
|
|
@ -23,20 +23,8 @@ namespace blt::nbt {
|
||||||
|
|
||||||
stream.read(str.characters, str.size);
|
stream.read(str.characters, str.size);
|
||||||
|
|
||||||
auto strOut = blt::string::getStringFromUTF8(str);
|
auto strOut = std::move(blt::string::getStringFromUTF8(str));
|
||||||
delete[] str.characters;
|
delete[] str.characters;
|
||||||
return strOut;
|
return strOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
void named_tag::writeName(std::fstream& out) {
|
|
||||||
writeUTF8String(out, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void named_tag::readName(std::fstream& in) {
|
|
||||||
name = readUTF8String(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tag_end::writePayload(std::fstream& out) {
|
|
||||||
out.put('\0');
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -9,88 +9,8 @@
|
||||||
#include "blt/math/matrix.h"
|
#include "blt/math/matrix.h"
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include "hashmap_tests.h"
|
#include "hashmap_tests.h"
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
std::function<int(int i)> test{
|
int main() {
|
||||||
[](int i) -> int {
|
|
||||||
int acc = 1;
|
|
||||||
for (int j = 0; j < i; j++){
|
|
||||||
acc += j * i;
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int test_as_func(int i){
|
|
||||||
int acc = 1;
|
|
||||||
for (int j = 0; j < i; j++){
|
|
||||||
acc += j * i;
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
|
|
||||||
class super_func {
|
|
||||||
public:
|
|
||||||
virtual int test(int i) = 0;
|
|
||||||
virtual ~super_func() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
class class_func : public super_func {
|
|
||||||
public:
|
|
||||||
int test(int i) override {
|
|
||||||
int acc = 1;
|
|
||||||
for (int j = 0; j < i; j++){
|
|
||||||
acc += j * i;
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
|
|
||||||
if (argc > 1 && std::string(argv[1]) == "--no_color") {
|
|
||||||
for (int i = (int)blt::logging::log_level::NONE; i < (int)blt::logging::log_level::FATAL; i++) {
|
|
||||||
blt::logging::setLogColor((blt::logging::log_level)i, "");
|
|
||||||
}
|
|
||||||
blt::logging::setLogOutputFormat("[${{TIME}}] [${{LOG_LEVEL}}] (${{FILE}}:${{LINE}}) ${{STR}}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
class_func* funy = new class_func;
|
|
||||||
super_func* virtual_funy = new class_func;
|
|
||||||
|
|
||||||
int num_of_tests = 100000;
|
|
||||||
int acc = 1;
|
|
||||||
BLT_START_INTERVAL("Functions Test", "std::function");
|
|
||||||
acc = 1;
|
|
||||||
for (int i = 0; i < num_of_tests; i++){
|
|
||||||
acc = test(acc);
|
|
||||||
}
|
|
||||||
BLT_END_INTERVAL("Functions Test", "std::function");
|
|
||||||
|
|
||||||
BLT_START_INTERVAL("Functions Test", "normal function");
|
|
||||||
acc = 1;
|
|
||||||
for (int i = 0; i < num_of_tests; i++){
|
|
||||||
acc = test_as_func(acc);
|
|
||||||
}
|
|
||||||
BLT_END_INTERVAL("Functions Test", "normal function");
|
|
||||||
|
|
||||||
BLT_START_INTERVAL("Functions Test", "virtual class direct");
|
|
||||||
acc = 1;
|
|
||||||
for (int i = 0; i < num_of_tests; i++){
|
|
||||||
acc = funy->test(acc);
|
|
||||||
}
|
|
||||||
BLT_END_INTERVAL("Functions Test", "virtual class direct");
|
|
||||||
|
|
||||||
BLT_START_INTERVAL("Functions Test", "virtual class");
|
|
||||||
acc = 1;
|
|
||||||
for (int i = 0; i < num_of_tests; i++){
|
|
||||||
acc = virtual_funy->test(acc);
|
|
||||||
}
|
|
||||||
BLT_END_INTERVAL("Functions Test", "virtual class");
|
|
||||||
|
|
||||||
BLT_PRINT_PROFILE("Functions Test");
|
|
||||||
delete virtual_funy;
|
|
||||||
|
|
||||||
binaryTreeTest();
|
binaryTreeTest();
|
||||||
|
|
||||||
run_logging();
|
run_logging();
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
#include <blt/std/filesystem.h>
|
#include <blt/std/filesystem.h>
|
||||||
|
|
||||||
inline bool readLargeBlockUsingNBTBufferedReader(const std::string& file, const blt::scoped_buffer<char>& bufferToCompare, size_t bufferSize) {
|
inline bool readLargeBlockUsingNBTBufferedReader(const std::string& file, const blt::scoped_buffer<char>& bufferToCompare, size_t bufferSize) {
|
||||||
blt::scoped_buffer<char> read_buffer{bufferToCompare.size()};
|
blt::scoped_buffer<char> read_buffer{bufferToCompare.size};
|
||||||
std::fstream largeBlockInputLarge(file, std::ios::in | std::ios::binary);
|
std::fstream largeBlockInputLarge(file, std::ios::in | std::ios::binary);
|
||||||
blt::fs::fstream_block_reader byteLargeBlockInputLarge(largeBlockInputLarge, bufferSize);
|
blt::fs::fstream_block_reader byteLargeBlockInputLarge(largeBlockInputLarge, bufferSize);
|
||||||
byteLargeBlockInputLarge.read(*read_buffer, bufferToCompare.size());
|
byteLargeBlockInputLarge.read(read_buffer.buffer, bufferToCompare.size);
|
||||||
for (unsigned int i = 0; i < bufferToCompare.size(); i++) {
|
for (unsigned int i = 0; i < bufferToCompare.size; i++) {
|
||||||
if (read_buffer[i] != bufferToCompare[i])
|
if (read_buffer[i] != bufferToCompare.buffer[i])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
largeBlockInputLarge.close();
|
largeBlockInputLarge.close();
|
||||||
|
@ -29,7 +29,7 @@ inline bool readLargeBlockUsingNBTBufferedReader(const std::string& file, const
|
||||||
inline bool readIndividualUsingNBTBufferedReader(const std::string& file, const blt::scoped_buffer<char>& bufferToCompare, size_t bufferSize) {
|
inline bool readIndividualUsingNBTBufferedReader(const std::string& file, const blt::scoped_buffer<char>& bufferToCompare, size_t bufferSize) {
|
||||||
std::fstream largeBlockInput(file, std::ios::in | std::ios::binary);
|
std::fstream largeBlockInput(file, std::ios::in | std::ios::binary);
|
||||||
blt::fs::fstream_block_reader byteLargeBlockInput(largeBlockInput, bufferSize);
|
blt::fs::fstream_block_reader byteLargeBlockInput(largeBlockInput, bufferSize);
|
||||||
for (unsigned int i = 0; i < bufferToCompare.size(); i++) {
|
for (unsigned int i = 0; i < bufferToCompare.size; i++) {
|
||||||
char byte;
|
char byte;
|
||||||
byteLargeBlockInput.read(&byte, 1);
|
byteLargeBlockInput.read(&byte, 1);
|
||||||
if (byte != bufferToCompare[i]) {
|
if (byte != bufferToCompare[i]) {
|
||||||
|
@ -52,11 +52,11 @@ inline void nbt_read_tests(){
|
||||||
bool fstream_large_correct = true;
|
bool fstream_large_correct = true;
|
||||||
|
|
||||||
for (int i = 0; i < bufferSize; i++)
|
for (int i = 0; i < bufferSize; i++)
|
||||||
buffer[i] = i + 1;
|
buffer.buffer[i] = i+1;
|
||||||
|
|
||||||
BLT_START_INTERVAL("nbt read", "Raw Write");
|
BLT_START_INTERVAL("nbt read", "Raw Write");
|
||||||
std::fstream largeOutput("HeyThere.txt", std::ios::out | std::ios::binary);
|
std::fstream largeOutput("HeyThere.txt", std::ios::out | std::ios::binary);
|
||||||
largeOutput.write(*buffer, bufferSize);
|
largeOutput.write(buffer.buffer, bufferSize);
|
||||||
largeOutput.flush();
|
largeOutput.flush();
|
||||||
largeOutput.close();
|
largeOutput.close();
|
||||||
BLT_END_INTERVAL("nbt read", "Raw Write");
|
BLT_END_INTERVAL("nbt read", "Raw Write");
|
||||||
|
@ -129,7 +129,7 @@ inline void nbt_write_tests(){
|
||||||
blt::scoped_buffer<char> read_buffer{bufferSize};
|
blt::scoped_buffer<char> read_buffer{bufferSize};
|
||||||
|
|
||||||
for (int i = 0; i < bufferSize; i++)
|
for (int i = 0; i < bufferSize; i++)
|
||||||
buffer[i] = i + 1;
|
buffer.buffer[i] = i+1;
|
||||||
|
|
||||||
std::fstream fileOutput("IAmAFile.txt", std::ios::binary | std::ios::out);
|
std::fstream fileOutput("IAmAFile.txt", std::ios::binary | std::ios::out);
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
|
@ -139,11 +139,11 @@ inline void nbt_write_tests(){
|
||||||
blt::fs::fstream_block_writer writer(fileOutput, size);
|
blt::fs::fstream_block_writer writer(fileOutput, size);
|
||||||
|
|
||||||
BLT_START_INTERVAL("nbt write block", profiler_string);
|
BLT_START_INTERVAL("nbt write block", profiler_string);
|
||||||
writer.write(*buffer, buffer.size());
|
writer.write(buffer.buffer, buffer.size);
|
||||||
BLT_END_INTERVAL("nbt write block", profiler_string);
|
BLT_END_INTERVAL("nbt write block", profiler_string);
|
||||||
BLT_START_INTERVAL("nbt write individual", profiler_string);
|
BLT_START_INTERVAL("nbt write individual", profiler_string);
|
||||||
for (int j = 0; j < bufferSize; j++) {
|
for (int j = 0; j < bufferSize; j++) {
|
||||||
writer.write(&buffer[j], 1);
|
writer.write(&buffer.buffer[j], 1);
|
||||||
}
|
}
|
||||||
BLT_END_INTERVAL("nbt write individual", profiler_string);
|
BLT_END_INTERVAL("nbt write individual", profiler_string);
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ inline void nbt_write_tests(){
|
||||||
auto size = (size_t) std::pow(2, 11 + i);
|
auto size = (size_t) std::pow(2, 11 + i);
|
||||||
auto size_str = std::to_string(size);
|
auto size_str = std::to_string(size);
|
||||||
bool results = true;
|
bool results = true;
|
||||||
fileInput.read(*read_buffer, bufferSize);
|
fileInput.read(read_buffer.buffer, bufferSize);
|
||||||
for (int j = 0; j < bufferSize; j++) {
|
for (int j = 0; j < bufferSize; j++) {
|
||||||
if (buffer[j] != read_buffer[j]) {
|
if (buffer[j] != read_buffer[j]) {
|
||||||
results = false;
|
results = false;
|
||||||
|
@ -166,7 +166,7 @@ inline void nbt_write_tests(){
|
||||||
BLT_INFO("NBT %s Block Write Correctly? %s;\n", size_str.c_str(), results ? "True" : "False");
|
BLT_INFO("NBT %s Block Write Correctly? %s;\n", size_str.c_str(), results ? "True" : "False");
|
||||||
|
|
||||||
results = true;
|
results = true;
|
||||||
fileInput.read(*read_buffer, bufferSize);
|
fileInput.read(read_buffer.buffer, bufferSize);
|
||||||
for (int j = 0; j < bufferSize; j++) {
|
for (int j = 0; j < bufferSize; j++) {
|
||||||
if (buffer[j] != read_buffer[j]) {
|
if (buffer[j] != read_buffer[j]) {
|
||||||
results = false;
|
results = false;
|
||||||
|
|
Loading…
Reference in New Issue