readme update plus time functions and cleaner scoped_buffer WITH begin()/end()
scoped_buffer update will break most usesv1
parent
20f8238f70
commit
0d5abd143f
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
project(BLT VERSION 0.6.0)
|
||||
project(BLT VERSION 0.6.1)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
|
|
21
README.md
21
README.md
|
@ -1,4 +1,4 @@
|
|||
# **BLT v0.6.0a**
|
||||
# **BLT v0.6.1a**
|
||||
A common utilities library I find useful
|
||||
|
||||
![Icon](icon_large.png)
|
||||
|
@ -26,11 +26,10 @@ If you are using BLT as a CMake library (as you should!) this is done for you.
|
|||
- ## Data Structures
|
||||
- Queue / Stack
|
||||
- faster than std::queue / std::stack
|
||||
- Binary Tree
|
||||
- Hashmap (TODO)
|
||||
- backed by a contiguous array
|
||||
- ## Utility
|
||||
- Simple Random Interface
|
||||
- No more worrying about min/max bounds!
|
||||
- Simple Random Wrapper Interface
|
||||
- Simple random functions based on the PCG Hash
|
||||
- ### String Functions
|
||||
- starts_with
|
||||
- ends_with
|
||||
|
@ -40,14 +39,12 @@ If you are using BLT as a CMake library (as you should!) this is done for you.
|
|||
- split
|
||||
- trim
|
||||
- Logging
|
||||
- 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.
|
||||
- See blt::logging section above
|
||||
- Time
|
||||
- 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
|
||||
- ## Profiling
|
||||
- Basic profiler
|
||||
- WIP
|
||||
- Basic profiler with history and formatted output
|
|
@ -65,11 +65,12 @@ namespace blt {
|
|||
*/
|
||||
template<typename T>
|
||||
struct scoped_buffer {
|
||||
T* buffer;
|
||||
unsigned long size;
|
||||
|
||||
explicit scoped_buffer(unsigned long size): size(size) {
|
||||
buffer = new T[size];
|
||||
private:
|
||||
T* _buffer;
|
||||
size_t _size;
|
||||
public:
|
||||
explicit scoped_buffer(size_t size): _size(size) {
|
||||
_buffer = new T[size];
|
||||
}
|
||||
|
||||
scoped_buffer(scoped_buffer& copy) = delete;
|
||||
|
@ -80,16 +81,36 @@ namespace blt {
|
|||
|
||||
scoped_buffer operator=(scoped_buffer&& moveAssignment) = delete;
|
||||
|
||||
inline T& operator[](unsigned long index) const {
|
||||
return buffer[index];
|
||||
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;
|
||||
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;
|
||||
delete[] _buffer;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -29,6 +29,14 @@ namespace blt::system {
|
|||
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:
|
||||
* Year-Month-Date Hour:Min:Second
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
#include <blt/std/filesystem.h>
|
||||
|
||||
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);
|
||||
blt::fs::fstream_block_reader byteLargeBlockInputLarge(largeBlockInputLarge, bufferSize);
|
||||
byteLargeBlockInputLarge.read(read_buffer.buffer, bufferToCompare.size);
|
||||
for (unsigned int i = 0; i < bufferToCompare.size; i++) {
|
||||
if (read_buffer[i] != bufferToCompare.buffer[i])
|
||||
byteLargeBlockInputLarge.read(*read_buffer, bufferToCompare.size());
|
||||
for (unsigned int i = 0; i < bufferToCompare.size(); i++) {
|
||||
if (read_buffer[i] != bufferToCompare[i])
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
std::fstream largeBlockInput(file, std::ios::in | std::ios::binary);
|
||||
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;
|
||||
byteLargeBlockInput.read(&byte, 1);
|
||||
if (byte != bufferToCompare[i]) {
|
||||
|
@ -52,11 +52,11 @@ inline void nbt_read_tests(){
|
|||
bool fstream_large_correct = true;
|
||||
|
||||
for (int i = 0; i < bufferSize; i++)
|
||||
buffer.buffer[i] = i+1;
|
||||
buffer[i] = i + 1;
|
||||
|
||||
BLT_START_INTERVAL("nbt read", "Raw Write");
|
||||
std::fstream largeOutput("HeyThere.txt", std::ios::out | std::ios::binary);
|
||||
largeOutput.write(buffer.buffer, bufferSize);
|
||||
largeOutput.write(*buffer, bufferSize);
|
||||
largeOutput.flush();
|
||||
largeOutput.close();
|
||||
BLT_END_INTERVAL("nbt read", "Raw Write");
|
||||
|
@ -129,7 +129,7 @@ inline void nbt_write_tests(){
|
|||
blt::scoped_buffer<char> read_buffer{bufferSize};
|
||||
|
||||
for (int i = 0; i < bufferSize; i++)
|
||||
buffer.buffer[i] = i+1;
|
||||
buffer[i] = i + 1;
|
||||
|
||||
std::fstream fileOutput("IAmAFile.txt", std::ios::binary | std::ios::out);
|
||||
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_START_INTERVAL("nbt write block", profiler_string);
|
||||
writer.write(buffer.buffer, buffer.size);
|
||||
writer.write(*buffer, buffer.size());
|
||||
BLT_END_INTERVAL("nbt write block", profiler_string);
|
||||
BLT_START_INTERVAL("nbt write individual", profiler_string);
|
||||
for (int j = 0; j < bufferSize; j++) {
|
||||
writer.write(&buffer.buffer[j], 1);
|
||||
writer.write(&buffer[j], 1);
|
||||
}
|
||||
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_str = std::to_string(size);
|
||||
bool results = true;
|
||||
fileInput.read(read_buffer.buffer, bufferSize);
|
||||
fileInput.read(*read_buffer, bufferSize);
|
||||
for (int j = 0; j < bufferSize; j++) {
|
||||
if (buffer[j] != read_buffer[j]) {
|
||||
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");
|
||||
|
||||
results = true;
|
||||
fileInput.read(read_buffer.buffer, bufferSize);
|
||||
fileInput.read(*read_buffer, bufferSize);
|
||||
for (int j = 0; j < bufferSize; j++) {
|
||||
if (buffer[j] != read_buffer[j]) {
|
||||
results = false;
|
||||
|
|
Loading…
Reference in New Issue