Core lib building
This commit is contained in:
parent
3ed195d7dd
commit
94fcc42aed
73 changed files with 625 additions and 661 deletions
|
@ -54,7 +54,7 @@ std::pair<MarkdownContentParser::FileMetadata, Ptr<MarkdownDocument>> MarkdownCo
|
|||
return {output_metadata, std::move(document)};
|
||||
}
|
||||
|
||||
std::optional<MarkdownContentParser::FileMetadataItem> MarkdownContentParser::checkForMetadataItem(const String& line) const
|
||||
Optional<MarkdownContentParser::FileMetadataItem> MarkdownContentParser::checkForMetadataItem(const String& line) const
|
||||
{
|
||||
unsigned char_count = 0;
|
||||
String prefix;
|
||||
|
|
|
@ -18,5 +18,5 @@ public:
|
|||
|
||||
std::pair<FileMetadata, Ptr<MarkdownDocument>> run(const Path& path);
|
||||
private:
|
||||
std::optional<FileMetadataItem> checkForMetadataItem(const String& line) const;
|
||||
Optional<FileMetadataItem> checkForMetadataItem(const String& line) const;
|
||||
};
|
||||
|
|
|
@ -7,10 +7,10 @@ CORE_SRC_DIR=$SOURCE_DIR/base/core
|
|||
g++ $SOURCE_DIR/main.cpp \
|
||||
$CORE_SRC_DIR/base_types/Error.cpp \
|
||||
$CORE_SRC_DIR/base_types/Index.cpp \
|
||||
$CORE_SRC_DIR/base_types/Char.cpp \
|
||||
$SOURCE_DIR/base/compiler/BuildLibrary.cpp \
|
||||
$SOURCE_DIR/base/compiler/BuildSession.cpp \
|
||||
$CORE_SRC_DIR/data_structures/String.cpp \
|
||||
$CORE_SRC_DIR/encoding/CharUtils.cpp \
|
||||
$CORE_SRC_DIR/filesystem/FileSystemPath.cpp \
|
||||
$CORE_SRC_DIR/filesystem/File.cpp \
|
||||
$CORE_SRC_DIR/filesystem/Directory.cpp \
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "MidiChannelEventAdapter.h"
|
||||
|
||||
#include "BinaryStream.h"
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <bitset>
|
||||
|
@ -19,7 +19,7 @@ int MidiChannelEventAdapter::readEvent(std::ifstream* file, char firstByte, Midi
|
|||
unsigned byteCount = 0;
|
||||
//std::cout << "Channel: " << midi_channel << std::endl;
|
||||
|
||||
const bool isStatusByte = ByteUtils::MostSignificantBitIsOne(firstByte);
|
||||
const bool isStatusByte = Bits::MostSignificantBitIsOne(firstByte);
|
||||
if(isStatusByte)
|
||||
{
|
||||
event->SetTypeAndChannel(firstByte);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "MidiMetaEventAdapter.h"
|
||||
|
||||
#include "BinaryStream.h"
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <bitset>
|
||||
|
@ -108,7 +108,7 @@ int MidiMetaEventAdapter::ReadIntEvent(std::ifstream* file, MetaMidiEvent* event
|
|||
BinaryStream::getNextNBytes(file, buffer.data(), length);
|
||||
byteCount += length;
|
||||
|
||||
const int value = ByteUtils::ToType<ByteUtils::DWord>(buffer.data(), length);
|
||||
const int value = Bits::ToType<Bits::DWord>(buffer.data(), length);
|
||||
event->SetValue(value);
|
||||
return byteCount;
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ int MidiMetaEventAdapter::ReadChannelPrefixEvent(std::ifstream* file, MetaMidiEv
|
|||
BinaryStream::getNextNBytes(file, buffer.data(), length);
|
||||
byteCount += length;
|
||||
|
||||
const int value = ByteUtils::ToType<ByteUtils::DWord>(buffer.data(), length);
|
||||
const int value = Bits::ToType<Bits::DWord>(buffer.data(), length);
|
||||
event->SetValue(value);
|
||||
lastMidiChannel = value;
|
||||
return byteCount;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "MidiReader.h"
|
||||
|
||||
#include "MidiDocument.h"
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "MidiTrack.h"
|
||||
#include "BinaryStream.h"
|
||||
#include "FileLogger.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "MidiTimeAdapter.h"
|
||||
|
||||
#include "BinaryStream.h"
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <bitset>
|
||||
|
@ -13,7 +13,7 @@ int MidiTimeAdapter::ReadEventTimeDelta(std::ifstream* file, int& delta)
|
|||
file->get(c);
|
||||
byteCount++;
|
||||
|
||||
if(!ByteUtils::MostSignificantBitIsOne(c))
|
||||
if(!Bits::MostSignificantBitIsOne(c))
|
||||
{
|
||||
delta = int(c);
|
||||
//std::cout << "Time delta final: " << delta << std::endl;
|
||||
|
@ -54,13 +54,13 @@ int MidiTimeAdapter::ReadTimeDivision(std::ifstream* file, MidiTimeDivision& div
|
|||
return -1;
|
||||
}
|
||||
|
||||
division.mUseFps = ByteUtils::GetWordFirstBit(*time_division);
|
||||
division.mUseFps = Bits::GetWordFirstBit(*time_division);
|
||||
if (division.mUseFps)
|
||||
{
|
||||
const int TOP_7_BITS = 0x7F00; // 0111 1111 - 0000 0000
|
||||
division.mFps = ((~(*time_division) & TOP_7_BITS) >> 8) - 1; // Reverse 2complement of next 7 bits
|
||||
}
|
||||
|
||||
division.mTicks = ByteUtils::GetWordLastByte(*time_division);
|
||||
division.mTicks = Bits::GetWordLastByte(*time_division);
|
||||
return 2; // Bytes advanced
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
add_subdirectory(compiler)
|
||||
add_subdirectory(compression)
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(database)
|
||||
add_subdirectory(geometry)
|
||||
add_subdirectory(network)
|
|
@ -16,6 +16,8 @@ BuildSession::BuildSession(const String& source_dir,
|
|||
{
|
||||
m_build_dir = build_dir;
|
||||
}
|
||||
const auto build_str = m_build_dir.str() + "/build";
|
||||
m_build_dir = FileSystemPath(build_str);
|
||||
m_compiler_flags.push_back("-g");
|
||||
m_compiler_flags.push_back("-fno-exceptions");
|
||||
m_compiler_flags.push_back("-fno-rtti");
|
||||
|
@ -24,23 +26,22 @@ BuildSession::BuildSession(const String& source_dir,
|
|||
Status BuildSession::scan()
|
||||
{
|
||||
LOG_INFO("Scanning sources at:" << m_source_dir);
|
||||
Vector<FileSystemPath> toml_files;
|
||||
Vector<FileSystemPath> ini_files;
|
||||
STATUS_CHECK(Directory::getFilesWithExtension(
|
||||
m_source_dir,
|
||||
".toml",
|
||||
toml_files,
|
||||
".ini",
|
||||
ini_files,
|
||||
true), "Error looking for build files");
|
||||
|
||||
for(const auto& toml_file : toml_files)
|
||||
for(const auto& ini_file : ini_files)
|
||||
{
|
||||
if (toml_file.file_name() == "build")
|
||||
if (ini_file.file_name() == "build")
|
||||
{
|
||||
STATUS_CHECK(add_library(toml_file),
|
||||
STATUS_CHECK(add_library(ini_file),
|
||||
"Error adding library");
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
||||
}
|
||||
|
||||
Status BuildSession::add_library(const FileSystemPath& config_path)
|
||||
|
@ -54,26 +55,52 @@ Status BuildSession::add_library(const FileSystemPath& config_path)
|
|||
|
||||
Status BuildSession::build()
|
||||
{
|
||||
for(const auto& library : m_libraries)
|
||||
Directory::create(m_build_dir, true);
|
||||
for(auto& library : m_libraries)
|
||||
{
|
||||
for(const auto& source : library.get_sources())
|
||||
{
|
||||
Vector<String> args = m_compiler_flags;
|
||||
args.push_back("-c");
|
||||
for(const auto& include_dir : library.get_include_dirs())
|
||||
{
|
||||
args.push_back(_s("-I") + include_dir.str());
|
||||
}
|
||||
args.push_back(source.str());
|
||||
LOG_INFO("Compiling " << source.file_name());
|
||||
const auto run_status = Process::launch(m_compiler_command, args);
|
||||
const auto run_status = compile_library(library);
|
||||
if (!run_status.ok())
|
||||
{
|
||||
return run_status;
|
||||
}
|
||||
//break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Status BuildSession::compile_library(BuildLibrary& lib)
|
||||
{
|
||||
for(const auto& source : lib.get_sources())
|
||||
{
|
||||
const auto run_status = compile_source_file(source, lib);
|
||||
if (!run_status.ok())
|
||||
{
|
||||
return run_status;
|
||||
}
|
||||
//break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Status BuildSession::compile_source_file(const FileSystemPath& source,
|
||||
const BuildLibrary& lib)
|
||||
{
|
||||
Vector<String> args = m_compiler_flags;
|
||||
args.push_back("-c");
|
||||
add_include_dirs(args, lib);
|
||||
args.push_back(source.str());
|
||||
|
||||
const auto output_path = m_build_dir / source.file_name();
|
||||
args.push_back("-o");
|
||||
args.push_back(output_path.str() + ".o");
|
||||
LOG_INFO("Compiling " << source.file_name());
|
||||
return Process::launch(m_compiler_command, args);
|
||||
}
|
||||
|
||||
void BuildSession::add_include_dirs(Vector<String>& args, const BuildLibrary& lib)
|
||||
{
|
||||
for(const auto& include_dir : lib.get_include_dirs())
|
||||
{
|
||||
args.push_back(_s("-I") + include_dir.str());
|
||||
}
|
||||
}
|
|
@ -16,6 +16,13 @@ public:
|
|||
Status add_library(const FileSystemPath& config_path);
|
||||
|
||||
private:
|
||||
Status compile_library(BuildLibrary& lib);
|
||||
|
||||
Status compile_source_file(const FileSystemPath& source,
|
||||
const BuildLibrary& lib);
|
||||
|
||||
void add_include_dirs(Vector<String>& args, const BuildLibrary& lib);
|
||||
|
||||
String m_compiler_command{"/usr/bin/g++"};
|
||||
Vector<String> m_compiler_flags;
|
||||
FileSystemPath m_source_dir;
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
set(MODULE_NAME compiler)
|
||||
|
||||
list(APPEND HEADERS
|
||||
Lexer.h
|
||||
template_engine/TemplatingEngine.h
|
||||
template_engine/TemplateFile.h
|
||||
template_engine/TemplateNode.h
|
||||
template_engine/TemplateElements.h
|
||||
)
|
||||
|
||||
list(APPEND SOURCES
|
||||
Lexer.cpp
|
||||
template_engine/TemplatingEngine.cpp
|
||||
template_engine/TemplateFile.cpp
|
||||
template_engine/TemplateNode.cpp
|
||||
template_engine/TemplateElements.cpp
|
||||
)
|
||||
|
||||
add_library(${MODULE_NAME} SHARED ${HEADERS} ${SOURCES})
|
||||
|
||||
target_include_directories(${MODULE_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/template_engine
|
||||
)
|
||||
target_link_libraries( ${MODULE_NAME} PUBLIC core)
|
||||
|
||||
set_target_properties( ${MODULE_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src/base)
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "StringUtils.h"
|
||||
#include "BitStream.h"
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "HuffmanEncoder.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -234,7 +234,7 @@ void Lz77Encoder::flushHitBuffer()
|
|||
if (length == 0)
|
||||
{
|
||||
code = *mCodeGenerator->getLiteralValue(next_char);
|
||||
std::cout << "Writing symbol " << static_cast<int>(next_char) << " with code " << ByteUtils::toString(code.getData(), code.getLength()) << "\n";
|
||||
std::cout << "Writing symbol " << static_cast<int>(next_char) << " with code " << Bits::toString(code.getData(), code.getLength()) << "\n";
|
||||
|
||||
mOutputStream->writeNBits(code.getData(), code.getLength());
|
||||
}
|
||||
|
@ -243,16 +243,16 @@ void Lz77Encoder::flushHitBuffer()
|
|||
code = *mCodeGenerator->getLengthValue(length);
|
||||
const auto distance_code = mCodeGenerator->getDistanceValue(distance);
|
||||
|
||||
std::cout << "Writing length " << length << " with code " << ByteUtils::toString(code.getData(), code.getLength()) << "\n";
|
||||
std::cout << "Writing length " << length << " with code " << Bits::toString(code.getData(), code.getLength()) << "\n";
|
||||
mOutputStream->writeNBits(code.getData(), code.getLength());
|
||||
|
||||
std::cout << "Writing distance " << distance << " with code " << ByteUtils::toString(distance_code.getData(), distance_code.getLength()) << "\n";
|
||||
std::cout << "Writing distance " << distance << " with code " << Bits::toString(distance_code.getData(), distance_code.getLength()) << "\n";
|
||||
mOutputStream->writeNBits(distance_code.getData(), distance_code.getLength());
|
||||
}
|
||||
}
|
||||
|
||||
auto eos_code = mCodeGenerator->getEndOfStreamValue();
|
||||
std::cout << "Writing EOS value with code " << ByteUtils::toString(eos_code->getData(), eos_code->getLength()) << "\n";
|
||||
std::cout << "Writing EOS value with code " << Bits::toString(eos_code->getData(), eos_code->getLength()) << "\n";
|
||||
|
||||
mOutputStream->writeNBits(eos_code->getData(), eos_code->getLength());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "ZlibEncoder.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "DeflateEncoder.h"
|
||||
#include "FileLogger.h"
|
||||
#include "BitStream.h"
|
||||
|
@ -52,8 +52,8 @@ String ZlibEncoder::toString(CompressionMethod method) const
|
|||
void ZlibEncoder::parseCompressionMethod(unsigned char method)
|
||||
{
|
||||
//std::cout << "Got compression input " << static_cast<int>(method) << std::endl;
|
||||
mCompressionMethod = static_cast<CompressionMethod>(ByteUtils::getLowerNBits(method, 4));
|
||||
auto compression_info = ByteUtils::getHigherNBits(method, 4);
|
||||
mCompressionMethod = static_cast<CompressionMethod>(Bits::getLowerNBits(method, 4));
|
||||
auto compression_info = Bits::getHigherNBits(method, 4);
|
||||
|
||||
if (mCompressionMethod == CompressionMethod::DEFLATE)
|
||||
{
|
||||
|
@ -71,9 +71,9 @@ void ZlibEncoder::parseExtraFlags(unsigned char extraFlags, unsigned char compre
|
|||
//std::cout << "Invalid header. Mod is " << mod << std::endl;
|
||||
}
|
||||
|
||||
mFlagCheck = ByteUtils::getLowerNBits(extraFlags, 5);
|
||||
mUseDictionary = bool(ByteUtils::getBitN(extraFlags, 5));
|
||||
mFlagLevel = static_cast<CompressionLevel>(ByteUtils::getHigherNBits(extraFlags, 2));
|
||||
mFlagCheck = Bits::getLowerNBits(extraFlags, 5);
|
||||
mUseDictionary = bool(Bits::getBitN(extraFlags, 5));
|
||||
mFlagLevel = static_cast<CompressionLevel>(Bits::getHigherNBits(extraFlags, 2));
|
||||
}
|
||||
|
||||
String ZlibEncoder::getData() const
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "DeflateBlock.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "AbstractChecksumCalculator.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -72,16 +72,16 @@ bool DeflateBlock::readUncompressedStream()
|
|||
auto byte1 = *mInputStream->readNextByte();
|
||||
mUncompressedBlockLength = (byte0 << 8) | byte1;
|
||||
|
||||
std::cout << "Check block 0: " << ByteUtils::toString(byte0) << std::endl;
|
||||
std::cout << "Check block 1: " << ByteUtils::toString(byte1) << std::endl;
|
||||
std::cout << "Check block 0: " << Bits::toString(byte0) << std::endl;
|
||||
std::cout << "Check block 1: " << Bits::toString(byte1) << std::endl;
|
||||
|
||||
auto byte2 = *mInputStream->readNextByte();
|
||||
auto byte3 = *mInputStream->readNextByte();
|
||||
uint16_t len_check = (byte2 << 8) | byte3;
|
||||
(void) len_check;
|
||||
|
||||
//std::cout << "Check block 2: " << ByteUtils::toString(byte2) << std::endl;
|
||||
//std::cout << "Check block 3: " << ByteUtils::toString(byte3) << std::endl;
|
||||
//std::cout << "Check block 2: " << Bits::toString(byte2) << std::endl;
|
||||
//std::cout << "Check block 3: " << Bits::toString(byte3) << std::endl;
|
||||
//if (!(byte0 ==(~byte2) && byte1 ==(~byte3)))
|
||||
//{
|
||||
//std::cout << "Uncompressed block length check failed - aborting." << std::endl;
|
||||
|
@ -141,13 +141,13 @@ void DeflateBlock::write(uint16_t datalength)
|
|||
|
||||
void DeflateBlock::writeUncompressedStream(unsigned char working_byte, uint16_t datalength)
|
||||
{
|
||||
//std::cout << "Writing compression block header " << ByteUtils::toString(working_byte) << std::endl;
|
||||
//std::cout << "Writing compression block header " << Bits::toString(working_byte) << std::endl;
|
||||
mOutputStream->writeByte(working_byte);
|
||||
|
||||
//std::cout << "Writing data length " << mUncompressedBlockLength << " " << ByteUtils::toString(mUncompressedBlockLength) << std::endl;
|
||||
//std::cout << "Writing data length " << mUncompressedBlockLength << " " << Bits::toString(mUncompressedBlockLength) << std::endl;
|
||||
mOutputStream->writeWord(datalength);
|
||||
|
||||
//std::cout << "Writing iverse data length " << ~mUncompressedBlockLength << " " << ByteUtils::toString(~mUncompressedBlockLength) << std::endl;
|
||||
//std::cout << "Writing iverse data length " << ~mUncompressedBlockLength << " " << Bits::toString(~mUncompressedBlockLength) << std::endl;
|
||||
mOutputStream->writeWord(static_cast<uint16_t>(~mUncompressedBlockLength));
|
||||
|
||||
for(unsigned idx=0; idx<mUncompressedBlockLength;idx++)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "DeflateEncoder.h"
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "DeflateBlock.h"
|
||||
#include "BufferBitStream.h"
|
||||
|
||||
|
@ -45,7 +45,7 @@ bool DeflateEncoder::encode()
|
|||
|
||||
if (auto byte = mInputStream->readNextByte())
|
||||
{
|
||||
//std::cout << "Adding byte " << ByteUtils::toString(*byte) << " to deflate block input" << std::endl;
|
||||
//std::cout << "Adding byte " << Bits::toString(*byte) << " to deflate block input" << std::endl;
|
||||
stream.writeByte(*byte);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "HuffmanCodeLengthTable.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "RunLengthEncoder.h"
|
||||
#include "BitStream.h"
|
||||
|
||||
|
@ -94,7 +94,7 @@ const Vector<size_t> HuffmanCodeLengthTable::getCompressedLengthCounts() const
|
|||
return mCompressedLengthCounts;
|
||||
}
|
||||
|
||||
std::optional<PrefixCode> HuffmanCodeLengthTable::getCodeForSymbol(unsigned symbol) const
|
||||
Optional<PrefixCode> HuffmanCodeLengthTable::getCodeForSymbol(unsigned symbol) const
|
||||
{
|
||||
return mTree.getCode(symbol);
|
||||
}
|
||||
|
@ -118,11 +118,11 @@ bool HuffmanCodeLengthTable::readNextSymbol(unsigned& result, BitStream* stream)
|
|||
while(!found)
|
||||
{
|
||||
stream->readNextNBits(delta, buffer);
|
||||
//std::cout << "Got buffer " << ByteUtils::toString(buffer) << std::endl;;
|
||||
//std::cout << "Got buffer " << Bits::toString(buffer) << std::endl;;
|
||||
|
||||
unsigned hold = buffer;
|
||||
working_bits = working_bits | (hold << (length - delta));
|
||||
//std::cout << "Read " << delta << " bits with length " << length << " and value " << ByteUtils::toString(working_bits) << std::endl;
|
||||
//std::cout << "Read " << delta << " bits with length " << length << " and value " << Bits::toString(working_bits) << std::endl;
|
||||
|
||||
if (const auto symbol = findMatch(working_index, working_bits))
|
||||
{
|
||||
|
@ -146,13 +146,13 @@ bool HuffmanCodeLengthTable::readNextSymbol(unsigned& result, BitStream* stream)
|
|||
if (found)
|
||||
{
|
||||
result = working_symbol;
|
||||
// std::cout << "Found symbol " << working_symbol << " with bits " << ByteUtils::toString(working_bits) << std::endl;
|
||||
// std::cout << "Found symbol " << working_symbol << " with bits " << Bits::toString(working_bits) << std::endl;
|
||||
// std::cout << "At Byte offset " << stream->getCurrentByteOffset() << " and bit offset " << stream->getCurrentBitOffset() << std::endl;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "SYMBOL NOT FOUND " << " with bits " << ByteUtils::toString(working_bits) << " and index " << working_index << std::endl;
|
||||
//std::cout << "SYMBOL NOT FOUND " << " with bits " << Bits::toString(working_bits) << " and index " << working_index << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ void HuffmanCodeLengthTable::buildPrefixCodes()
|
|||
for (unsigned bits = 1; bits <= max_length; bits++)
|
||||
{
|
||||
code = (code + counts[bits-1]) << 1;
|
||||
//std::cout << "Start code for bit " << bits << " is " << ByteUtils::toString(code) << " | dec " << code << " count " << counts[bits-1] << std::endl;
|
||||
//std::cout << "Start code for bit " << bits << " is " << Bits::toString(code) << " | dec " << code << " count " << counts[bits-1] << std::endl;
|
||||
next_code[bits] = code;
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ size_t HuffmanCodeLengthTable::getNumCodeLengths() const
|
|||
return mTree.getNumCodeLengths();
|
||||
}
|
||||
|
||||
std::optional<HuffmanTree::Symbol> HuffmanCodeLengthTable::findMatch(size_t treeIndex, uint32_t code) const
|
||||
Optional<HuffmanTree::Symbol> HuffmanCodeLengthTable::findMatch(size_t treeIndex, uint32_t code) const
|
||||
{
|
||||
return mTree.findMatch(treeIndex, code);
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@ public:
|
|||
|
||||
String dumpPrefixCodes() const;
|
||||
|
||||
std::optional<HuffmanTree::Symbol> findMatch(size_t treeIndex, uint32_t code) const;
|
||||
Optional<HuffmanTree::Symbol> findMatch(size_t treeIndex, uint32_t code) const;
|
||||
|
||||
const HuffmanTree& getTree() const;
|
||||
|
||||
const PrefixCode& getCode(size_t index) const;
|
||||
|
||||
std::optional<PrefixCode> getCodeForSymbol(unsigned symbol) const;
|
||||
Optional<PrefixCode> getCodeForSymbol(unsigned symbol) const;
|
||||
|
||||
using CompressedSequenceEntry = std::pair<unsigned, unsigned>;
|
||||
const Vector<CompressedSequenceEntry>& getCompressedLengthSequence() const;
|
||||
|
|
|
@ -112,22 +112,22 @@ uint32_t HuffmanEncoder::getLengthValue(unsigned)
|
|||
return 0;
|
||||
}
|
||||
|
||||
std::optional<PrefixCode> HuffmanEncoder::getLiteralValue(unsigned char value) const
|
||||
Optional<PrefixCode> HuffmanEncoder::getLiteralValue(unsigned char value) const
|
||||
{
|
||||
return mLiteralLengthTable.getCodeForSymbol(value);
|
||||
}
|
||||
|
||||
std::optional<PrefixCode> HuffmanEncoder::getLengthValue(unsigned length) const
|
||||
Optional<PrefixCode> HuffmanEncoder::getLengthValue(unsigned length) const
|
||||
{
|
||||
return mLiteralLengthTable.getCodeForSymbol(length);
|
||||
}
|
||||
|
||||
std::optional<PrefixCode> HuffmanEncoder::getDistanceValue(unsigned distance) const
|
||||
Optional<PrefixCode> HuffmanEncoder::getDistanceValue(unsigned distance) const
|
||||
{
|
||||
return mDistanceTable.getCodeForSymbol(distance);
|
||||
}
|
||||
|
||||
std::optional<PrefixCode> HuffmanEncoder::getEndOfStreamValue() const
|
||||
Optional<PrefixCode> HuffmanEncoder::getEndOfStreamValue() const
|
||||
{
|
||||
return mLiteralLengthTable.getCodeForSymbol(256);
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ class PrefixCodeGenerator
|
|||
{
|
||||
public:
|
||||
virtual ~PrefixCodeGenerator() = default;
|
||||
virtual std::optional<PrefixCode> getLiteralValue(unsigned char symbol) const = 0;
|
||||
virtual std::optional<PrefixCode> getLengthValue(unsigned length) const = 0;
|
||||
virtual std::optional<PrefixCode> getDistanceValue(unsigned distance) const = 0;
|
||||
virtual Optional<PrefixCode> getLiteralValue(unsigned char symbol) const = 0;
|
||||
virtual Optional<PrefixCode> getLengthValue(unsigned length) const = 0;
|
||||
virtual Optional<PrefixCode> getDistanceValue(unsigned distance) const = 0;
|
||||
|
||||
virtual std::optional<PrefixCode> getEndOfStreamValue() const = 0;
|
||||
virtual Optional<PrefixCode> getEndOfStreamValue() const = 0;
|
||||
};
|
||||
|
||||
class HuffmanEncoder : public PrefixCodeGenerator
|
||||
|
@ -31,13 +31,13 @@ public:
|
|||
|
||||
uint32_t getLengthValue(unsigned length);
|
||||
|
||||
std::optional<PrefixCode> getLiteralValue(unsigned char symbol) const override;
|
||||
Optional<PrefixCode> getLiteralValue(unsigned char symbol) const override;
|
||||
|
||||
std::optional<PrefixCode> getLengthValue(unsigned length) const override;
|
||||
Optional<PrefixCode> getLengthValue(unsigned length) const override;
|
||||
|
||||
std::optional<PrefixCode> getDistanceValue(unsigned distance) const override;
|
||||
Optional<PrefixCode> getDistanceValue(unsigned distance) const override;
|
||||
|
||||
std::optional<PrefixCode> getEndOfStreamValue() const override;
|
||||
Optional<PrefixCode> getEndOfStreamValue() const override;
|
||||
|
||||
void initializeTrees(const Vector<Hit>& hits);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "HuffmanStream.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "HuffmanFixedCodes.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -335,7 +335,7 @@ void HuffmanStream::readCodingsTable()
|
|||
for(unsigned idx = 0; idx< num_code_lengths; idx++)
|
||||
{
|
||||
mInputStream->readNextNBits(3, buffer);
|
||||
//std::cout << "Got coding table value " << idx << " | " << static_cast<int>(buffer) << " | " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Got coding table value " << idx << " | " << static_cast<int>(buffer) << " | " << Bits::toString(buffer) << std::endl;
|
||||
sequence[idx] = buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "HuffmanTree.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
@ -9,7 +9,7 @@
|
|||
PrefixCode::PrefixCode(uint32_t data, unsigned length)
|
||||
: mLength(length)
|
||||
{
|
||||
mData = ByteUtils::mirror(data, length);
|
||||
mData = Bits::mirror(data, length);
|
||||
}
|
||||
|
||||
bool PrefixCode::matches(unsigned length, uint32_t code) const
|
||||
|
@ -23,22 +23,22 @@ String PrefixCode::toString(bool bitsAsRightToLeft) const
|
|||
{
|
||||
if (mLength <=8 )
|
||||
{
|
||||
return ByteUtils::toString(mData).substr(8 - mLength, mLength);
|
||||
return Bits::toString(mData).substr(8 - mLength, mLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ByteUtils::toString(mData, mLength);
|
||||
return Bits::toString(mData, mLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mLength <=8 )
|
||||
{
|
||||
return ByteUtils::toString(ByteUtils::mirror(mData, mLength)).substr(0, mLength);
|
||||
return Bits::toString(Bits::mirror(mData, mLength)).substr(0, mLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ByteUtils::toString(mData, mLength);
|
||||
return Bits::toString(mData, mLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,12 +67,12 @@ void HuffmanTree::sortTable()
|
|||
std::sort(mTable.begin(), mTable.end(), [](CodeLengthData a, CodeLengthData b){return a.first < b.first;});
|
||||
}
|
||||
|
||||
std::optional<HuffmanTree::Symbol> HuffmanTree::findMatch(size_t treeIndex, uint32_t code) const
|
||||
Optional<HuffmanTree::Symbol> HuffmanTree::findMatch(size_t treeIndex, uint32_t code) const
|
||||
{
|
||||
const auto& legth_data = mTable[treeIndex];
|
||||
for(const auto& entry : legth_data.second)
|
||||
{
|
||||
//std::cout << "Checking if " << entry.second << " matches code " << ByteUtils::toString(code) << std::endl;;
|
||||
//std::cout << "Checking if " << entry.second << " matches code " << Bits::toString(code) << std::endl;;
|
||||
if (entry.first.matches(legth_data.first, code))
|
||||
{
|
||||
return entry.second;
|
||||
|
@ -81,7 +81,7 @@ std::optional<HuffmanTree::Symbol> HuffmanTree::findMatch(size_t treeIndex, uint
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<PrefixCode> HuffmanTree::getCode(Symbol symbol) const
|
||||
Optional<PrefixCode> HuffmanTree::getCode(Symbol symbol) const
|
||||
{
|
||||
for(const auto& entry : mTable)
|
||||
{
|
||||
|
|
|
@ -41,13 +41,13 @@ public:
|
|||
|
||||
String dump(bool bitsAsRightToLeft = true) const;
|
||||
|
||||
std::optional<HuffmanTree::Symbol> findMatch(size_t treeIndex, uint32_t code) const;
|
||||
Optional<HuffmanTree::Symbol> findMatch(size_t treeIndex, uint32_t code) const;
|
||||
|
||||
size_t getNumCodeLengths() const;
|
||||
|
||||
unsigned getCodeLength(size_t idx) const;
|
||||
|
||||
std::optional<PrefixCode> getCode(Symbol symbol) const;
|
||||
Optional<PrefixCode> getCode(Symbol symbol) const;
|
||||
|
||||
void sortTable();
|
||||
private:
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
set(MODULE_NAME core)
|
||||
|
||||
list(APPEND HEADERS
|
||||
AbstractApp.h
|
||||
AbstractNamedItem.h
|
||||
AbstractWebApp.h
|
||||
Dictionary.h
|
||||
Event.h
|
||||
Color.h
|
||||
CommandLineArgs.h
|
||||
data_structures/RawTree.h
|
||||
data_structures/List.h
|
||||
data_structures/Tree.h
|
||||
encoding/ByteUtils.h
|
||||
encoding/StringUtils.h
|
||||
encoding/UnicodeUtils.h
|
||||
loggers/FileLogger.h
|
||||
file_utilities/Directory.h
|
||||
file_utilities/File.h
|
||||
file_utilities/FileFormats.h
|
||||
file_utilities/PathUtils.h
|
||||
http/HttpResponse.h
|
||||
http/HttpHeader.h
|
||||
http/HttpRequest.h
|
||||
http/HttpParser.h
|
||||
http/HttpPreamble.h
|
||||
serializers/TomlReader.h
|
||||
Win32BaseIncludes.h
|
||||
ThreadCollection.h
|
||||
xml/XmlParser.h
|
||||
xml/XmlDocument.h
|
||||
xml/XmlWriter.h
|
||||
xml/xml-elements/XmlElement.h
|
||||
xml/xml-elements/XmlAttribute.h
|
||||
xml/xml-elements/XmlProlog.h
|
||||
)
|
||||
|
||||
list(APPEND SOURCES
|
||||
Event.cpp
|
||||
Dictionary.cpp
|
||||
Color.cpp
|
||||
CommandLineArgs.cpp
|
||||
memory/Allocator.cpp
|
||||
data_structures/RawTree.cpp
|
||||
data_structures/Tree.cpp
|
||||
data_structures/Vector.cpp
|
||||
data_structures/String.cpp
|
||||
loggers/FileLogger.cpp
|
||||
file_utilities/Directory.cpp
|
||||
file_utilities/File.cpp
|
||||
file_utilities/FileFormats.cpp
|
||||
file_utilities/PathUtils.cpp
|
||||
memory/SharedMemory.cpp
|
||||
RandomUtils.cpp
|
||||
encoding/StringUtils.cpp
|
||||
encoding/ByteUtils.cpp
|
||||
encoding/UnicodeUtils.cpp
|
||||
streams/BinaryStream.cpp
|
||||
streams/BitStream.cpp
|
||||
streams/InputBitStream.cpp
|
||||
streams/OutputBitStream.cpp
|
||||
streams/BufferBitStream.cpp
|
||||
http/HttpResponse.cpp
|
||||
http/HttpHeader.cpp
|
||||
http/HttpRequest.cpp
|
||||
http/HttpParser.cpp
|
||||
serializers/TomlReader.cpp
|
||||
ThreadCollection.cpp
|
||||
xml/XmlParser.cpp
|
||||
xml/XmlDocument.cpp
|
||||
xml/XmlWriter.cpp
|
||||
xml/xml-elements/XmlElement.cpp
|
||||
xml/xml-elements/XmlAttribute.cpp
|
||||
xml/xml-elements/XmlProlog.cpp
|
||||
)
|
||||
|
||||
add_library(${MODULE_NAME} SHARED ${SOURCES} ${HEADERS})
|
||||
|
||||
target_include_directories(${MODULE_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/encoding
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_utilities
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/loggers
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/streams
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/http
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/base_types
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data_structures
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/serializers
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xml
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xml/xml-elements
|
||||
)
|
||||
set_target_properties( ${MODULE_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src/base)
|
|
@ -1,35 +1,47 @@
|
|||
#include "CharUtils.h"
|
||||
#include "Char.h"
|
||||
|
||||
bool CharUtils::is_alpha_upper(char c)
|
||||
bool Char::is_alpha_upper(char c)
|
||||
{
|
||||
const auto unsigned_c = static_cast<unsigned char>(c);
|
||||
return unsigned_c >= 65 && unsigned_c <= 90;
|
||||
}
|
||||
|
||||
bool CharUtils::is_alpha_lower(char c)
|
||||
bool Char::is_alpha_lower(char c)
|
||||
{
|
||||
const auto unsigned_c = static_cast<unsigned char>(c);
|
||||
return unsigned_c >= 97 && unsigned_c <= 122;
|
||||
}
|
||||
|
||||
bool CharUtils::is_alpha(char c)
|
||||
bool Char::is_alpha(char c)
|
||||
{
|
||||
return is_alpha_upper(c) || is_alpha_lower(c);
|
||||
}
|
||||
|
||||
bool CharUtils::is_alnum(char c)
|
||||
bool Char::is_alnum(char c)
|
||||
{
|
||||
return is_alpha(c) || is_digit(c);
|
||||
}
|
||||
|
||||
bool CharUtils::is_digit(char c)
|
||||
bool Char::is_digit(char c)
|
||||
{
|
||||
const auto unsigned_c = static_cast<unsigned char>(c);
|
||||
return unsigned_c >= 48 && unsigned_c <= 57;
|
||||
}
|
||||
|
||||
bool CharUtils::is_space(char c)
|
||||
bool Char::is_space(char c)
|
||||
{
|
||||
return c == ' ' || c == '\f' || c == '\n'
|
||||
|| c == '\r' || c == '\t' || c == '\v';
|
||||
}
|
||||
|
||||
char Char::to_lower(char c)
|
||||
{
|
||||
if (is_alpha_upper(c))
|
||||
{
|
||||
return c + 32;
|
||||
}
|
||||
else
|
||||
{
|
||||
return c;
|
||||
}
|
||||
}
|
29
src/base/core/base_types/Char.h
Normal file
29
src/base/core/base_types/Char.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
class Char
|
||||
{
|
||||
public:
|
||||
static constexpr char LEFT_BRACKET = '<';
|
||||
static constexpr char RIGHT_BRACKET = '>';
|
||||
static constexpr char FORWARD_SLASH = '/';
|
||||
static constexpr char BACK_SLASH = '\\';
|
||||
static constexpr char QUESTION_MARK = '?';
|
||||
static constexpr char EQUALS = '=';
|
||||
static constexpr char DOUBLE_QUOTE = '"';
|
||||
static constexpr char SINGLE_QUOTE = '\'';
|
||||
static constexpr char COLON = ':';
|
||||
|
||||
static bool is_alpha_upper(char c);
|
||||
|
||||
static bool is_alpha_lower(char c);
|
||||
|
||||
static bool is_alpha(char c);
|
||||
|
||||
static bool is_alnum(char c);
|
||||
|
||||
static bool is_digit(char c);
|
||||
|
||||
static bool is_space(char c);
|
||||
|
||||
static char to_lower(char c);
|
||||
};
|
|
@ -19,19 +19,23 @@ Color::Color(const String& hexString)
|
|||
{
|
||||
return;
|
||||
}
|
||||
/*
|
||||
mR = toDecimal(hexString.substr(1, 2));
|
||||
mG = toDecimal(hexString.substr(3, 2));
|
||||
mB = toDecimal(hexString.substr(5, 2));
|
||||
*/
|
||||
}
|
||||
|
||||
unsigned char Color::toDecimal(const String& hex) const
|
||||
{
|
||||
return static_cast<unsigned char>(std::stoul("0x" + hex, nullptr, 16));
|
||||
//return static_cast<unsigned char>(std::stoul("0x" + hex, nullptr, 16));
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ptr<Color> Color::Create(unsigned char r, unsigned char g, unsigned char b, double a )
|
||||
{
|
||||
return std::make_unique<Color>(r, g, b, a);
|
||||
//return Ptr<Color>::create(r, g, b, a);
|
||||
return {};
|
||||
}
|
||||
|
||||
size_t Color::getSize() const
|
||||
|
@ -60,10 +64,6 @@ uint8_t Color::getByte(size_t index) const
|
|||
{
|
||||
if (mFormat == Format::GRAYSCALE || mFormat == Format::LUT)
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
throw std::range_error("Color index out of range in getByte()");
|
||||
}
|
||||
return mValue;
|
||||
}
|
||||
else if (mFormat == Format::ARGB)
|
||||
|
@ -79,7 +79,7 @@ uint8_t Color::getByte(size_t index) const
|
|||
case 3:
|
||||
return mB;
|
||||
default:
|
||||
throw std::range_error("Color index out of range in getByte()");
|
||||
return mR;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -95,7 +95,7 @@ uint8_t Color::getByte(size_t index) const
|
|||
case 3:
|
||||
return mAlpha * 255;
|
||||
default:
|
||||
throw std::range_error("Color index out of range in getByte()");
|
||||
return mR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ void Color::setAlpha(float alpha)
|
|||
|
||||
Ptr<Color> Color::Create(const Color& color)
|
||||
{
|
||||
return std::make_unique<Color>(color);
|
||||
return Ptr<Color>::create(color);
|
||||
}
|
||||
|
||||
unsigned char Color::getR() const
|
||||
|
@ -132,7 +132,8 @@ double Color::getAlpha() const
|
|||
|
||||
Vector<double> Color::getAsVectorDouble() const
|
||||
{
|
||||
return { mR / 255.0, mG / 255.0, mB / 255.0, mAlpha };
|
||||
//return { mR / 255.0, mG / 255.0, mB / 255.0, mAlpha };
|
||||
return {};
|
||||
}
|
||||
|
||||
uint32_t Color::getAsUInt32() const
|
||||
|
@ -142,5 +143,5 @@ uint32_t Color::getAsUInt32() const
|
|||
|
||||
String Color::toString() const
|
||||
{
|
||||
return std::to_string(static_cast<int>(mR)) + "," + std::to_string(static_cast<int>(mG)) + "," + std::to_string(static_cast<int>(mB));
|
||||
return String::to_string(static_cast<int>(mR)) + "," + String::to_string(static_cast<int>(mG)) + "," + String::to_string(static_cast<int>(mB));
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
#include "Pointer.h"
|
||||
#include "Vector.h"
|
||||
#include "String.h"
|
||||
#include <stdexcept>
|
||||
|
||||
class Color
|
||||
{
|
||||
|
@ -69,6 +68,3 @@ private:
|
|||
unsigned mBitDepth{8};
|
||||
Format mFormat{Format::RGBA};
|
||||
};
|
||||
|
||||
using ColorPtr = std::shared_ptr<Color>;
|
||||
using ColorUPtr = Ptr<Color>;
|
||||
|
|
|
@ -23,6 +23,11 @@ public:
|
|||
return m_is_set;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return m_is_set;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_is_set{false};
|
||||
T m_value;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "String.h"
|
||||
|
||||
#include "Char.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
@ -107,6 +108,22 @@ void String::eraseIf(erasePredicate func)
|
|||
m_data[count] = '\0';
|
||||
}
|
||||
|
||||
bool String::is_whitespace() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
for(size_t idx=0;idx<size();idx++)
|
||||
{
|
||||
if (!Char::is_space(m_data[idx]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const Vector<char>& String::data() const
|
||||
{
|
||||
return m_data;
|
||||
|
@ -117,6 +134,18 @@ bool String::empty() const
|
|||
return m_data.empty() || m_data[0] == '\0';
|
||||
}
|
||||
|
||||
void String::to_bytes(Vector<Byte>& bytes) const
|
||||
{
|
||||
if (m_data.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(size_t idx=0; idx<m_data.size() - 1; idx++)
|
||||
{
|
||||
bytes.push_back(m_data[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
void String::append(const Vector<Byte>& data)
|
||||
{
|
||||
if (data.empty())
|
||||
|
@ -229,6 +258,34 @@ void String::reverse()
|
|||
}
|
||||
}
|
||||
|
||||
void String::split(Vector<String>& output, char delimiter) const
|
||||
{
|
||||
String working_string;
|
||||
bool last_was_non_delimiter{ false };
|
||||
for (size_t idx = 0; idx<size(); idx++)
|
||||
{
|
||||
const auto c = m_data[idx];
|
||||
if (c == delimiter)
|
||||
{
|
||||
if (last_was_non_delimiter)
|
||||
{
|
||||
output.push_back(working_string);
|
||||
working_string = "";
|
||||
last_was_non_delimiter = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
last_was_non_delimiter = true;
|
||||
working_string += c;
|
||||
}
|
||||
}
|
||||
if (!working_string.empty())
|
||||
{
|
||||
output.push_back(working_string);
|
||||
}
|
||||
}
|
||||
|
||||
String String::to_string(size_t input)
|
||||
{
|
||||
String conv;
|
||||
|
@ -276,6 +333,12 @@ String& String::operator<<(size_t idx)
|
|||
return *this;
|
||||
}
|
||||
|
||||
String& String::operator<<(const int idx)
|
||||
{
|
||||
*this += to_string(idx);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void String::push_back(char c)
|
||||
{
|
||||
if (m_data.empty())
|
||||
|
@ -286,6 +349,25 @@ void String::push_back(char c)
|
|||
m_data[m_data.size()-2] = c;
|
||||
}
|
||||
|
||||
void String::to_lower()
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(size_t idx=0; idx<size(); idx++)
|
||||
{
|
||||
m_data[idx] = Char::to_lower(m_data[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
String String::to_lower(const String& input)
|
||||
{
|
||||
String ret = input;
|
||||
ret.to_lower();
|
||||
return ret;
|
||||
}
|
||||
|
||||
String& String::operator+=(const String& str)
|
||||
{
|
||||
if (m_data.empty())
|
||||
|
|
|
@ -29,6 +29,8 @@ public:
|
|||
using erasePredicate = std::function<bool(char)>;
|
||||
void eraseIf(erasePredicate func);
|
||||
|
||||
bool is_whitespace() const;
|
||||
|
||||
void push_back(char c);
|
||||
|
||||
const char* raw() const;
|
||||
|
@ -45,8 +47,16 @@ public:
|
|||
|
||||
bool slice(size_t start, size_t end, String& out) const;
|
||||
|
||||
void split(Vector<String>& output, char delimiter = ' ') const;
|
||||
|
||||
static String to_string(size_t input);
|
||||
|
||||
void to_bytes(Vector<Byte>& bytes) const;
|
||||
|
||||
void to_lower();
|
||||
|
||||
static String to_lower(const String& input);
|
||||
|
||||
char operator[](size_t idx) const;
|
||||
|
||||
String& operator<<(const String& body);
|
||||
|
@ -55,6 +65,8 @@ public:
|
|||
|
||||
String& operator<<(size_t idx);
|
||||
|
||||
String& operator<<(const int idx);
|
||||
|
||||
template<typename T>
|
||||
String& operator<<(const T& stringable)
|
||||
{
|
||||
|
|
|
@ -1,32 +1,31 @@
|
|||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
|
||||
|
||||
bool ByteUtils::MostSignificantBitIsOne(Byte c)
|
||||
bool Bits::MostSignificantBitIsOne(Byte c)
|
||||
{
|
||||
return c & (1 << 7);
|
||||
}
|
||||
|
||||
Word ByteUtils::GetWordFirstBit(const Word word)
|
||||
Word Bits::GetWordFirstBit(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_FIRST_BIT;
|
||||
return word & Bits::WORD_FIRST_BIT;
|
||||
};
|
||||
|
||||
Word ByteUtils::GetWordLastByte(const Word word)
|
||||
Word Bits::GetWordLastByte(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_LAST_BYTE;
|
||||
return word & Bits::WORD_LAST_BYTE;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getHigherNBits(Byte input, size_t num)
|
||||
unsigned char Bits::getHigherNBits(Byte input, size_t num)
|
||||
{
|
||||
return input >> (8 - num);
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getByteN(DWord input, size_t n)
|
||||
unsigned char Bits::getByteN(DWord input, size_t n)
|
||||
{
|
||||
return (input << 8*n) >> 24;
|
||||
}
|
||||
|
||||
uint32_t ByteUtils::mirror(DWord byte, size_t length)
|
||||
uint32_t Bits::mirror(DWord byte, size_t length)
|
||||
{
|
||||
uint32_t ret{0};
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
|
@ -39,7 +38,7 @@ uint32_t ByteUtils::mirror(DWord byte, size_t length)
|
|||
return ret;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getLowerNBits(DWord input, size_t num)
|
||||
unsigned char Bits::getLowerNBits(DWord input, size_t num)
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
|
@ -64,12 +63,12 @@ unsigned char ByteUtils::getLowerNBits(DWord input, size_t num)
|
|||
}
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getTwoBitsAtN(Byte input, size_t n)
|
||||
unsigned char Bits::getTwoBitsAtN(Byte input, size_t n)
|
||||
{
|
||||
return (input & (0x03 << n)) >> n;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getMBitsAtN(Byte input, size_t m, size_t n)
|
||||
unsigned char Bits::getMBitsAtN(Byte input, size_t m, size_t n)
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
|
@ -94,12 +93,12 @@ unsigned char ByteUtils::getMBitsAtN(Byte input, size_t m, size_t n)
|
|||
}
|
||||
}
|
||||
|
||||
bool ByteUtils::getBitN(DWord input, size_t n)
|
||||
bool Bits::getBitN(DWord input, size_t n)
|
||||
{
|
||||
return input & (1 << n);
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getFromString(const String& string)
|
||||
unsigned char Bits::getFromString(const String& string)
|
||||
{
|
||||
unsigned char ret{0};
|
||||
|
||||
|
@ -118,7 +117,7 @@ unsigned char ByteUtils::getFromString(const String& string)
|
|||
return ret;
|
||||
}
|
||||
|
||||
String ByteUtils::toString(DWord input, size_t length)
|
||||
String Bits::toString(DWord input, size_t length)
|
||||
{
|
||||
String ret;
|
||||
if (length > 8)
|
||||
|
@ -144,7 +143,7 @@ String ByteUtils::toString(DWord input, size_t length)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void ByteUtils::ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t targetSize)
|
||||
void Bits::ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t targetSize)
|
||||
{
|
||||
for(unsigned idx=0; idx<targetSize; idx++)
|
||||
{
|
||||
|
@ -159,22 +158,22 @@ void ByteUtils::ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t t
|
|||
}
|
||||
}
|
||||
|
||||
Word ByteUtils::ToWord(Byte* buffer, bool reverse)
|
||||
Word Bits::ToWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<Word>(buffer, reverse);
|
||||
}
|
||||
|
||||
DWord ByteUtils::ToDWord(Byte* buffer, bool reverse)
|
||||
DWord Bits::ToDWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<DWord>(buffer, reverse);
|
||||
}
|
||||
|
||||
QWord ByteUtils::ToQWord(Byte* buffer, bool reverse)
|
||||
QWord Bits::ToQWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<QWord>(buffer, reverse);
|
||||
}
|
||||
|
||||
bool ByteUtils::Compare(Byte* buffer, const char* tag, size_t size)
|
||||
bool Bits::Compare(Byte* buffer, const char* tag, size_t size)
|
||||
{
|
||||
for(unsigned idx=0; idx<size; idx++)
|
||||
{
|
||||
|
@ -186,12 +185,24 @@ bool ByteUtils::Compare(Byte* buffer, const char* tag, size_t size)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ByteUtils::CompareDWords(Byte* buffer, const char* tag)
|
||||
bool Bits::CompareDWords(Byte* buffer, DWord target)
|
||||
{
|
||||
return Compare(buffer, tag, sizeof(DWord));
|
||||
for(size_t idx=0; idx<4;idx++)
|
||||
{
|
||||
if (buffer[idx] != getByteN(target, idx))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ByteUtils::CompareWords(Byte* buffer, const char* tag)
|
||||
bool Bits::CompareWords(Byte* buffer, Word target)
|
||||
{
|
||||
return Compare(buffer, tag, sizeof(Word));
|
||||
bool first_byte_matches = (buffer[0] == GetWordFirstBit(target));
|
||||
if (!first_byte_matches)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return buffer[1] == GetWordLastByte(target);
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
#include "ByteTypes.h"
|
||||
#include "String.h"
|
||||
|
||||
class ByteUtils
|
||||
class Bits
|
||||
{
|
||||
public:
|
||||
static bool MostSignificantBitIsOne(Byte c);
|
||||
|
@ -57,9 +57,9 @@ public:
|
|||
|
||||
static bool Compare(Byte* buffer, const char* tag, size_t size);
|
||||
|
||||
static bool CompareDWords(Byte* buffer, const char* tag);
|
||||
static bool CompareDWords(Byte* buffer, DWord target);
|
||||
|
||||
static bool CompareWords(Byte* buffer, const char* tag);
|
||||
static bool CompareWords(Byte* buffer, Word target);
|
||||
|
||||
static const int BYTE_FIRST_BIT = 0x40; // 1000 0000
|
||||
static const Word WORD_FIRST_BIT = static_cast<Word>(0x8000); // 1000 0000 - 0000 0000
|
|
@ -1,17 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class CharUtils
|
||||
{
|
||||
public:
|
||||
static bool is_alpha_upper(char c);
|
||||
|
||||
static bool is_alpha_lower(char c);
|
||||
|
||||
static bool is_alpha(char c);
|
||||
|
||||
static bool is_alnum(char c);
|
||||
|
||||
static bool is_digit(char c);
|
||||
|
||||
static bool is_space(char c);
|
||||
};
|
|
@ -1,60 +1,15 @@
|
|||
#include "StringUtils.h"
|
||||
|
||||
#include "Char.h"
|
||||
|
||||
#include <locale>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
bool StringUtils::isAlphaNumeric(char c)
|
||||
{
|
||||
return std::isalnum(c);
|
||||
}
|
||||
|
||||
bool StringUtils::isSpace(char c)
|
||||
{
|
||||
return std::isspace(c);
|
||||
}
|
||||
|
||||
bool StringUtils::isAlphabetical(char c)
|
||||
{
|
||||
return std::isalpha(c);
|
||||
}
|
||||
|
||||
Vector<unsigned char> StringUtils::toBytes(const String& input)
|
||||
{
|
||||
return {input.begin(), input.end()};
|
||||
}
|
||||
|
||||
String StringUtils::toString(const Vector<unsigned char>& bytes)
|
||||
{
|
||||
return {bytes.begin(), bytes.end()};
|
||||
}
|
||||
|
||||
Vector<String> StringUtils::toLines(const String& input)
|
||||
{
|
||||
auto result = Vector<String>{};
|
||||
auto ss = Stringstream{input};
|
||||
for (String line; std::getline(ss, line, '\n');)
|
||||
{
|
||||
result.push_back(line);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool StringUtils::isWhitespaceOnly(const String& input)
|
||||
{
|
||||
if (input.empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::all_of(input.cbegin(), input.cend(), [](char c){ return std::isspace(c); });
|
||||
}
|
||||
}
|
||||
|
||||
size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
||||
{
|
||||
/*
|
||||
auto found_id = input.find(c);
|
||||
if(found_id == String::npos)
|
||||
{
|
||||
|
@ -76,10 +31,13 @@ size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
|||
}
|
||||
return count;
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
String StringUtils::stripSurroundingWhitepsace(const String& input)
|
||||
{
|
||||
/*
|
||||
if (input.empty())
|
||||
{
|
||||
return {};
|
||||
|
@ -110,54 +68,24 @@ String StringUtils::stripSurroundingWhitepsace(const String& input)
|
|||
}
|
||||
}
|
||||
return input.substr(first_nonspace, last_nonspace-first_nonspace + 1);
|
||||
}
|
||||
|
||||
Vector<String> StringUtils::split(const String& input)
|
||||
{
|
||||
Vector<String> substrings;
|
||||
String working_string;
|
||||
std::locale loc;
|
||||
bool last_was_nonspace{ false };
|
||||
for (auto c : input)
|
||||
{
|
||||
if (std::isspace(c, loc))
|
||||
{
|
||||
if (last_was_nonspace)
|
||||
{
|
||||
substrings.push_back(working_string);
|
||||
working_string = "";
|
||||
last_was_nonspace = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
last_was_nonspace = true;
|
||||
working_string += c;
|
||||
}
|
||||
}
|
||||
if (!working_string.empty())
|
||||
{
|
||||
substrings.push_back(working_string);
|
||||
}
|
||||
return substrings;
|
||||
}
|
||||
|
||||
String StringUtils::toLower(const String& s)
|
||||
{
|
||||
String ret;
|
||||
std::transform(s.begin(), s.end(), ret.begin(), [](unsigned char c){ return std::tolower(c); });
|
||||
return ret;
|
||||
*/
|
||||
return {};
|
||||
}
|
||||
|
||||
String StringUtils::toPaddedString(unsigned numBytes, unsigned entry)
|
||||
{
|
||||
/*
|
||||
Stringstream sstr;
|
||||
sstr << std::setfill('0') << std::setw(numBytes) << entry;
|
||||
return sstr.str();
|
||||
*/
|
||||
return {};
|
||||
}
|
||||
|
||||
String StringUtils::stripQuotes(const String& input)
|
||||
{
|
||||
/*
|
||||
if (input.size() < 3)
|
||||
{
|
||||
return input;
|
||||
|
@ -173,10 +101,13 @@ String StringUtils::stripQuotes(const String& input)
|
|||
end_index = end_index - 1;
|
||||
}
|
||||
return input.substr(start_index, end_index - start_index + 1);
|
||||
*/
|
||||
return {};
|
||||
}
|
||||
|
||||
String StringUtils::removeUpTo(const String& input, const String& prefix)
|
||||
{
|
||||
/*
|
||||
size_t found = input.find(prefix);
|
||||
if (found != String::npos)
|
||||
{
|
||||
|
@ -186,10 +117,13 @@ String StringUtils::removeUpTo(const String& input, const String& prefix)
|
|||
{
|
||||
return input;
|
||||
}
|
||||
*/
|
||||
return {};
|
||||
}
|
||||
|
||||
bool StringUtils::startsWith(const String& input, const String& prefix, bool ignoreWhitespace)
|
||||
{
|
||||
/*
|
||||
if(ignoreWhitespace)
|
||||
{
|
||||
const auto loc = input.find(prefix);
|
||||
|
@ -206,4 +140,6 @@ bool StringUtils::startsWith(const String& input, const String& prefix, bool ign
|
|||
{
|
||||
return input.find(prefix) == 0;
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -8,43 +8,15 @@
|
|||
class StringUtils
|
||||
{
|
||||
public:
|
||||
static constexpr char LEFT_BRACKET = '<';
|
||||
static constexpr char RIGHT_BRACKET = '>';
|
||||
static constexpr char FORWARD_SLASH = '/';
|
||||
static constexpr char BACK_SLASH = '\\';
|
||||
static constexpr char QUESTION_MARK = '?';
|
||||
static constexpr char EQUALS = '=';
|
||||
static constexpr char DOUBLE_QUOTE = '"';
|
||||
static constexpr char SINGLE_QUOTE = '\'';
|
||||
static constexpr char COLON = ':';
|
||||
|
||||
static size_t countFirstConsecutiveHits(const String& input, char c);
|
||||
|
||||
static bool isAlphaNumeric(char c);
|
||||
|
||||
static bool isAlphabetical(char c);
|
||||
|
||||
static bool isSpace(char c);
|
||||
|
||||
static bool isWhitespaceOnly(const String& input);
|
||||
|
||||
static String removeUpTo(const String& input, const String& prefix);
|
||||
|
||||
static Vector<String> split(const String& input);
|
||||
|
||||
static bool startsWith(const String& input, const String& prefix, bool ignoreWhitespace = false);
|
||||
|
||||
static String stripSurroundingWhitepsace(const String& input);
|
||||
|
||||
static String stripQuotes(const String& input);
|
||||
|
||||
static Vector<unsigned char> toBytes(const String& input);
|
||||
|
||||
static String toLower(const String& s);
|
||||
|
||||
static Vector<String> toLines(const String& input);
|
||||
|
||||
static String toPaddedString(unsigned numBytes, unsigned entry);
|
||||
|
||||
static String toString(const Vector<unsigned char>& bytes);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "UnicodeUtils.h"
|
||||
#include "Unicode.h"
|
||||
|
||||
#include "Win32BaseIncludes.h"
|
||||
|
||||
|
@ -45,7 +45,7 @@ std::wstring UnicodeUtils::utf8ToUtf16WString(const String& input)
|
|||
}
|
||||
*/
|
||||
|
||||
Vector<uint32_t> UnicodeUtils::utf8ToUtf32(const String& input)
|
||||
Vector<uint32_t> Unicode::utf8ToUtf32(const String& input)
|
||||
{
|
||||
//const auto utf_16 = utf8ToUtf16WString(input);
|
||||
|
||||
|
@ -77,22 +77,22 @@ Vector<uint32_t> UnicodeUtils::utf8ToUtf32(const String& input)
|
|||
return output;
|
||||
}
|
||||
|
||||
bool UnicodeUtils::isSurrogate(wchar_t c)
|
||||
bool Unicode::isSurrogate(wchar_t c)
|
||||
{
|
||||
return (c - 0xd800u) < 2048u;
|
||||
}
|
||||
|
||||
bool UnicodeUtils::isHighSurrogate(wchar_t c)
|
||||
bool Unicode::isHighSurrogate(wchar_t c)
|
||||
{
|
||||
return (c & 0xfffffc00) == 0xd800;
|
||||
}
|
||||
|
||||
bool UnicodeUtils::isLowSurrogate(wchar_t c)
|
||||
bool Unicode::isLowSurrogate(wchar_t c)
|
||||
{
|
||||
return (c & 0xfffffc00) == 0xdc00;
|
||||
}
|
||||
|
||||
uint32_t UnicodeUtils::surrogateToUtf32(wchar_t high, wchar_t low)
|
||||
uint32_t Unicode::surrogateToUtf32(wchar_t high, wchar_t low)
|
||||
{
|
||||
return (high << 10) + low - 0x35fdc00;
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
#include "Vector.h"
|
||||
#include <cstdint>
|
||||
|
||||
class UnicodeUtils
|
||||
class Unicode
|
||||
{
|
||||
public:
|
||||
//static String utf16ToUtf8String(const std::wstring& input);
|
|
@ -1,7 +1,6 @@
|
|||
#include "File.h"
|
||||
|
||||
//#include "FileLogger.h"
|
||||
#include "ByteUtils.h"
|
||||
#include "Char.h"
|
||||
#include "Directory.h"
|
||||
#include "Result.h"
|
||||
|
||||
|
@ -251,7 +250,7 @@ String File::dumpBinary()
|
|||
String hex_sstr;
|
||||
hex_sstr << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(byte);
|
||||
|
||||
sstr << count << " | " << ByteUtils::toString(byte) << " | " << static_cast<int>(byte) << " | " << hex_sstr.str() << " | " << ascii_val << '\n';
|
||||
sstr << count << " | " << Bits::toString(byte) << " | " << static_cast<int>(byte) << " | " << hex_sstr.str() << " | " << ascii_val << '\n';
|
||||
if (count % 10 == 0)
|
||||
{
|
||||
sstr << "\n";
|
||||
|
|
|
@ -13,7 +13,7 @@ FileFormat::ExtensionMap FileFormat::mExtensions = []
|
|||
|
||||
bool FileFormat::isFormat(const String& extension, Format format)
|
||||
{
|
||||
return StringUtils::toLower(extension) == (*mExtensions.find(format)).value();
|
||||
return String::to_lower(extension) == (*mExtensions.find(format)).value();
|
||||
}
|
||||
|
||||
FileFormat::Format FileFormat::inferFormat(const String& query)
|
||||
|
|
|
@ -36,6 +36,20 @@ public:
|
|||
|
||||
FileSystemPath parent_path() const;
|
||||
|
||||
FileSystemPath operator/ (const char* body) const
|
||||
{
|
||||
String ret = m_path;
|
||||
ret += m_delimiter + String(body);
|
||||
return ret;
|
||||
}
|
||||
|
||||
FileSystemPath operator/ (const String& body) const
|
||||
{
|
||||
String ret = m_path;
|
||||
ret += m_delimiter + body;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
String m_delimiter{"/"};
|
||||
String m_path;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "FileLogger.h"
|
||||
|
||||
#include <time.h>
|
||||
#include "FileSystemPath.h"
|
||||
|
||||
FileLogger::FileLogger()
|
||||
:mWorkDirectory(),
|
||||
|
@ -9,13 +9,6 @@ FileLogger::FileLogger()
|
|||
|
||||
}
|
||||
|
||||
|
||||
FileLogger& FileLogger::GetInstance()
|
||||
{
|
||||
static FileLogger instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
FileLogger::~FileLogger()
|
||||
{
|
||||
|
||||
|
@ -35,28 +28,14 @@ void FileLogger::Open()
|
|||
{
|
||||
if (mWorkDirectory.empty())
|
||||
{
|
||||
mWorkDirectory = std::filesystem::current_path().string();
|
||||
mWorkDirectory = FileSystemPath::current_dir().value().str();
|
||||
}
|
||||
mFileStream.open(mWorkDirectory + "/" + mFileName);
|
||||
//mFileStream.open(mWorkDirectory + "/" + mFileName);
|
||||
}
|
||||
|
||||
void FileLogger::Close()
|
||||
{
|
||||
mFileStream.close();
|
||||
}
|
||||
|
||||
void FileLogger::LogLine(const std::ostringstream& line)
|
||||
{
|
||||
if (mDisabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mFileStream.is_open())
|
||||
{
|
||||
Open();
|
||||
}
|
||||
mFileStream << line.str() << std::endl;
|
||||
//mFileStream.close();
|
||||
}
|
||||
|
||||
void FileLogger::disable()
|
||||
|
@ -64,21 +43,28 @@ void FileLogger::disable()
|
|||
mDisabled = true;
|
||||
}
|
||||
|
||||
void FileLogger::LogLine(const String& logType, const std::ostringstream& line, const String& fileName, const String& functionName, int lineNumber)
|
||||
void FileLogger::log_line(Level level,
|
||||
const String& line,
|
||||
const String& fileName,
|
||||
const String& functionName,
|
||||
int lineNumber)
|
||||
{
|
||||
if (mDisabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::time_t t = std::time(nullptr);
|
||||
const String cleanedFileName = fileName.substr(fileName.find_last_of("/\\") + 1);
|
||||
std::tm time_buf{ };
|
||||
#ifdef WIN32
|
||||
gmtime_s(&time_buf, &t);
|
||||
#else
|
||||
gmtime_r(&t, &time_buf);
|
||||
#endif
|
||||
std::cout << logType << "|" << std::put_time(&time_buf, "%T") << "|" << cleanedFileName << "::" << functionName << "::" << lineNumber << "|" << line.str() << std::endl;
|
||||
mFileStream << logType << "|" << std::put_time(&time_buf, "%T") << "|" << cleanedFileName << "::" << functionName << "::" << lineNumber << "|" << line.str() << std::endl;
|
||||
const auto log_msg = build_log_message(level,
|
||||
line,
|
||||
fileName,
|
||||
functionName,
|
||||
lineNumber);
|
||||
if (level == Level::INFO)
|
||||
{
|
||||
//printf("%s\n", log_msg.raw());
|
||||
}
|
||||
else
|
||||
{
|
||||
//fprintf(stderr, "%s\n", log_msg.raw());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "Pointer.h"
|
||||
#include "String.h"
|
||||
#include "Logger.h"
|
||||
|
||||
class FileLogger
|
||||
class FileLogger : public Logger
|
||||
{
|
||||
FileLogger();
|
||||
|
||||
public:
|
||||
static FileLogger& GetInstance();
|
||||
|
||||
FileLogger(FileLogger const&) = delete;
|
||||
void operator=(FileLogger const&) = delete;
|
||||
|
||||
~FileLogger();
|
||||
|
||||
void disable();
|
||||
|
@ -25,9 +18,11 @@ public:
|
|||
|
||||
void Close();
|
||||
|
||||
void LogLine(const String& line);
|
||||
|
||||
void LogLine(const String& logType, const String& line, const String& fileName = "", const String& functionName = "", int lineNumber=-1);
|
||||
void log_line(Level level,
|
||||
const String& line,
|
||||
const String& fileName,
|
||||
const String& functionName,
|
||||
int lineNumber) override;
|
||||
private:
|
||||
bool mDisabled{false};
|
||||
String mWorkDirectory;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "SharedPointer.h"
|
||||
#include "SharedMemory.h"
|
||||
|
||||
#include "RandomUtils.h"
|
||||
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -53,10 +55,10 @@ void SharedMemory::createFile(const String& namePrefix)
|
|||
const auto name = getRandomName(namePrefix);
|
||||
--retries;
|
||||
|
||||
const int fd = shm_open(name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
const int fd = shm_open(name.raw(), O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
if (fd >= 0)
|
||||
{
|
||||
shm_unlink(name.c_str());
|
||||
shm_unlink(name.raw());
|
||||
mFileDescriptor = fd;
|
||||
mIsValid = true;
|
||||
break;
|
||||
|
@ -72,7 +74,7 @@ String SharedMemory::getRandomName(const String& namePrefix) const
|
|||
String randomSuffix;
|
||||
for (const auto entry : RandomUtils::getRandomVecUnsigned(6))
|
||||
{
|
||||
randomSuffix += std::to_string(entry);
|
||||
randomSuffix += String::to_string(entry);
|
||||
}
|
||||
return namePrefix + randomSuffix;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "HttpHeader.h"
|
||||
#include "StringUtils.h"
|
||||
#include "Char.h"
|
||||
|
||||
|
||||
HttpHeader::HttpHeader()
|
||||
|
@ -29,7 +29,7 @@ void HttpHeader::parse(const Vector<String >& message)
|
|||
for(size_t idx = 0; idx< line.size(); idx++)
|
||||
{
|
||||
const auto c = line[idx];
|
||||
if (c == StringUtils::COLON)
|
||||
if (c == Char::COLON)
|
||||
{
|
||||
foundDelimiter = true;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ void HttpHeader::parse(const Vector<String >& message)
|
|||
}
|
||||
else
|
||||
{
|
||||
mOtherFields[tag] = value;
|
||||
mOtherFields.insert(tag, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "String.h"
|
||||
#include "Vector.h"
|
||||
#include <map>
|
||||
#include "Map.h"
|
||||
|
||||
class HttpHeader
|
||||
{
|
||||
|
@ -28,5 +28,5 @@ private:
|
|||
String mSecFetchMode;
|
||||
String mSecFetchSite;
|
||||
|
||||
std::map<String, String> mOtherFields;
|
||||
Map<String, String> mOtherFields;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include "HttpParser.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
#include "Char.h"
|
||||
|
||||
bool HttpParser::parsePreamble(const String& line, HttpPreamble& preamble)
|
||||
bool HttpParser::parsePreamble(const String& line,
|
||||
HttpPreamble& preamble)
|
||||
{
|
||||
bool inPath{ false };
|
||||
bool inMethod{ true };
|
||||
|
@ -12,7 +13,7 @@ bool HttpParser::parsePreamble(const String& line, HttpPreamble& preamble)
|
|||
{
|
||||
if (inPath)
|
||||
{
|
||||
if (StringUtils::isSpace(c))
|
||||
if (Char::is_space(c))
|
||||
{
|
||||
inPath = false;
|
||||
inMethod = true;
|
||||
|
@ -24,7 +25,7 @@ bool HttpParser::parsePreamble(const String& line, HttpPreamble& preamble)
|
|||
}
|
||||
else if (inMethod)
|
||||
{
|
||||
if (StringUtils::isSpace(c))
|
||||
if (Char::is_space(c))
|
||||
{
|
||||
inMethod = false;
|
||||
inProtocol = true;
|
||||
|
|
|
@ -5,5 +5,6 @@
|
|||
class HttpParser
|
||||
{
|
||||
public:
|
||||
static bool parsePreamble(const String& line, HttpPreamble& preamble);
|
||||
static bool parsePreamble(const String& line,
|
||||
HttpPreamble& preamble);
|
||||
};
|
|
@ -3,8 +3,6 @@
|
|||
#include "StringUtils.h"
|
||||
#include "HttpParser.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
HttpRequest::HttpRequest(Verb verb, const String& path)
|
||||
: mVerb(verb)
|
||||
{
|
||||
|
@ -31,30 +29,30 @@ String HttpRequest::toString(const String& host) const
|
|||
}
|
||||
|
||||
auto path = mPreamble.mPath;
|
||||
out += " /" + path + " HTTP/" + mHeader.getHttpVersion() + "\n";
|
||||
out += "Host: " + host + "\n";
|
||||
out += _s(" /") + path + _s(" HTTP/") + mHeader.getHttpVersion() + _s("\n");
|
||||
out += _s("Host: ") + host + _s("\n");
|
||||
out += "Accept - Encoding: \n";
|
||||
return out;
|
||||
}
|
||||
|
||||
void HttpRequest::fromString(const String& message)
|
||||
{
|
||||
Stringstream ss(message);
|
||||
|
||||
String buffer;
|
||||
bool firstLine{ true };
|
||||
|
||||
Vector<String> headers;
|
||||
while (std::getline(ss, buffer, '\n'))
|
||||
Vector<String> lines;
|
||||
message.split(lines, '\n');
|
||||
for(const auto& line : lines)
|
||||
{
|
||||
if (firstLine)
|
||||
{
|
||||
HttpParser::parsePreamble(buffer, mPreamble);
|
||||
HttpParser::parsePreamble(line, mPreamble);
|
||||
firstLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
headers.push_back(buffer);
|
||||
headers.push_back(line);
|
||||
}
|
||||
}
|
||||
if (mPreamble.mMethod == "GET")
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#include "StringUtils.h"
|
||||
#include "HttpParser.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
HttpResponse::HttpResponse()
|
||||
: mStatusCode(200),
|
||||
mResponseReason("OK"),
|
||||
|
@ -40,22 +38,22 @@ void HttpResponse::setBody(const String& body)
|
|||
|
||||
void HttpResponse::fromMessage(const String& message)
|
||||
{
|
||||
Stringstream ss(message);
|
||||
|
||||
String buffer;
|
||||
bool firstLine{ true };
|
||||
|
||||
Vector<String> headers;
|
||||
while (std::getline(ss, buffer, '\n'))
|
||||
Vector<String> lines;
|
||||
message.split(lines, '\n');
|
||||
for(const auto& line : lines)
|
||||
{
|
||||
if (firstLine)
|
||||
{
|
||||
HttpParser::parsePreamble(buffer, mPreamble);
|
||||
HttpParser::parsePreamble(line, mPreamble);
|
||||
firstLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
headers.push_back(buffer);
|
||||
headers.push_back(line);
|
||||
}
|
||||
}
|
||||
mHeader.parse(headers);
|
||||
|
@ -63,7 +61,7 @@ void HttpResponse::fromMessage(const String& message)
|
|||
|
||||
unsigned HttpResponse::getBodyLength() const
|
||||
{
|
||||
return unsigned(mBody.length());
|
||||
return unsigned(mBody.size());
|
||||
}
|
||||
|
||||
void HttpResponse::setClientError(const ClientError& error)
|
||||
|
@ -73,9 +71,9 @@ void HttpResponse::setClientError(const ClientError& error)
|
|||
|
||||
String HttpResponse::getHeaderString() const
|
||||
{
|
||||
String header = "HTTP/" + mHeader.getHttpVersion() + " " + std::to_string(mStatusCode) + " " + mResponseReason + "\n";
|
||||
header += "Content-Type: " + mHeader.getContentType() + "\n";
|
||||
header += "Content-Length: " + std::to_string(getBodyLength()) + "\n";
|
||||
String header = _s("HTTP/") + mHeader.getHttpVersion() + _s(" ") + String::to_string(mStatusCode) + _s(" ") + mResponseReason + _s("\n");
|
||||
header += _s("Content-Type: ") + mHeader.getContentType() + _s("\n");
|
||||
header += _s("Content-Length: ") + String::to_string(getBodyLength()) + _s("\n");
|
||||
return header;
|
||||
}
|
||||
|
||||
|
@ -86,7 +84,7 @@ const String& HttpResponse::getResponseReason() const
|
|||
|
||||
String HttpResponse::toString() const
|
||||
{
|
||||
return getHeaderString() + "\n\n" + mBody;
|
||||
return getHeaderString() + _s("\n\n") + mBody;
|
||||
}
|
||||
|
||||
void HttpResponse::setStatusCode(unsigned short code)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "TomlReader.h"
|
||||
|
||||
#include "CharUtils.h"
|
||||
#include "Char.h"
|
||||
|
||||
TomlTable::TomlTable(const String& header)
|
||||
: mHeader(header)
|
||||
|
@ -128,8 +128,8 @@ void TomlReader::processLine(const String& line)
|
|||
}
|
||||
else if (found_key)
|
||||
{
|
||||
key_string.eraseIf([](char c) {return CharUtils::is_space(c); });
|
||||
working_string.eraseIf([](char c) {return CharUtils::is_space(c); });
|
||||
key_string.eraseIf([](char c) {return Char::is_space(c); });
|
||||
working_string.eraseIf([](char c) {return Char::is_space(c); });
|
||||
if (working_string.size()>2 && working_string[0] == '"' && working_string[working_string.size() - 1] == '"')
|
||||
{
|
||||
working_string.slice(1, working_string.size() - 2, working_string);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "XmlParser.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
#include "Char.h"
|
||||
|
||||
#include "XmlDocument.h"
|
||||
#include "XmlElement.h"
|
||||
|
@ -24,22 +24,22 @@ void XmlParser::processLine(const String& input)
|
|||
{
|
||||
switch (input[idx])
|
||||
{
|
||||
case StringUtils::LEFT_BRACKET:
|
||||
case Char::LEFT_BRACKET:
|
||||
onLeftBracket();
|
||||
break;
|
||||
case StringUtils::RIGHT_BRACKET:
|
||||
case Char::RIGHT_BRACKET:
|
||||
onRightBracket();
|
||||
break;
|
||||
case StringUtils::QUESTION_MARK:
|
||||
case Char::QUESTION_MARK:
|
||||
onQuestionMark();
|
||||
break;
|
||||
case StringUtils::FORWARD_SLASH:
|
||||
case Char::FORWARD_SLASH:
|
||||
onForwardSlash();
|
||||
break;
|
||||
case StringUtils::EQUALS:
|
||||
case Char::EQUALS:
|
||||
onEquals();
|
||||
break;
|
||||
case StringUtils::DOUBLE_QUOTE:
|
||||
case Char::DOUBLE_QUOTE:
|
||||
onDoubleQuote();
|
||||
break;
|
||||
default:
|
||||
|
@ -51,11 +51,11 @@ void XmlParser::processLine(const String& input)
|
|||
|
||||
void XmlParser::onChar(char c)
|
||||
{
|
||||
if(StringUtils::isAlphaNumeric(c))
|
||||
if(Char::is_alnum(c))
|
||||
{
|
||||
onAlphaNumeric(c);
|
||||
}
|
||||
else if(StringUtils::isSpace(c))
|
||||
else if(Char::is_space(c))
|
||||
{
|
||||
onSpace(c);
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ void XmlParser::onLeftBracket()
|
|||
break;
|
||||
}
|
||||
default:
|
||||
onNonAlphaNumeric(StringUtils::LEFT_BRACKET);
|
||||
onNonAlphaNumeric(Char::LEFT_BRACKET);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ void XmlParser::onRightBracket()
|
|||
break;
|
||||
}
|
||||
default:
|
||||
onNonAlphaNumeric(StringUtils::RIGHT_BRACKET);
|
||||
onNonAlphaNumeric(Char::RIGHT_BRACKET);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ void XmlParser::onQuestionMark()
|
|||
}
|
||||
else if(mDocumentState != DS::Build_Prolog)
|
||||
{
|
||||
onNonAlphaNumeric(StringUtils::QUESTION_MARK);
|
||||
onNonAlphaNumeric(Char::QUESTION_MARK);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ void XmlParser::onForwardSlash()
|
|||
}
|
||||
else
|
||||
{
|
||||
onNonAlphaNumeric(StringUtils::FORWARD_SLASH);
|
||||
onNonAlphaNumeric(Char::FORWARD_SLASH);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ void XmlParser::onEquals()
|
|||
}
|
||||
else
|
||||
{
|
||||
onNonAlphaNumeric(StringUtils::EQUALS);
|
||||
onNonAlphaNumeric(Char::EQUALS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
#include "BinaryStream.h"
|
||||
|
||||
std::optional<int> BinaryStream::getNextByteAsInt(std::basic_istream<char>* stream)
|
||||
#include "Bits.h"
|
||||
|
||||
Optional<Byte> BinaryStream::getNextByte(InputStream<Byte>& stream)
|
||||
{
|
||||
return stream->get();
|
||||
return stream.get();
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextNBytes(std::basic_istream<char>* stream, char* buffer, unsigned number)
|
||||
bool BinaryStream::getNextNBytes(InputStream<Byte>& stream, Byte* buffer, size_t number)
|
||||
{
|
||||
char c;
|
||||
for(unsigned idx=0; idx<number; idx++)
|
||||
Byte c{0};
|
||||
for(size_t idx=0; idx<number; idx++)
|
||||
{
|
||||
if(stream->get(c))
|
||||
if(stream.get(c))
|
||||
{
|
||||
buffer[idx] = c;
|
||||
}
|
||||
|
@ -22,72 +24,72 @@ bool BinaryStream::getNextNBytes(std::basic_istream<char>* stream, char* buffer,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextWord(std::basic_istream<char>* stream, char* buffer)
|
||||
bool BinaryStream::getNextWord(InputStream<Byte>& stream, Byte* buffer)
|
||||
{
|
||||
return getNextNBytes(stream, buffer, sizeof(ByteUtils::Word));
|
||||
return getNextNBytes(stream, buffer, sizeof(Word));
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextDWord(std::basic_istream<char>* stream, char* buffer)
|
||||
bool BinaryStream::getNextDWord(InputStream<Byte>& stream, Byte* buffer)
|
||||
{
|
||||
return getNextNBytes(stream, buffer, sizeof(ByteUtils::DWord));
|
||||
return getNextNBytes(stream, buffer, sizeof(DWord));
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextQWord(std::basic_istream<char>* stream, char* buffer)
|
||||
bool BinaryStream::getNextQWord(InputStream<Byte>& stream, Byte* buffer)
|
||||
{
|
||||
return getNextNBytes(stream, buffer, sizeof(ByteUtils::QWord));
|
||||
return getNextNBytes(stream, buffer, sizeof(QWord));
|
||||
}
|
||||
|
||||
std::optional<ByteUtils::Word> BinaryStream::getNextWord(std::basic_istream<char>* stream, bool reverse)
|
||||
Optional<Word> BinaryStream::getNextWord(InputStream<Byte>& stream, bool reverse)
|
||||
{
|
||||
char buffer[sizeof(ByteUtils::Word)];
|
||||
if(!BinaryStream::getNextWord(stream, buffer))
|
||||
Byte buffer[sizeof(Word)];
|
||||
if(!getNextWord(stream, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ByteUtils::ToWord(buffer, reverse);
|
||||
return Bits::ToWord(buffer, reverse);
|
||||
}
|
||||
|
||||
std::optional<ByteUtils::DWord> BinaryStream::getNextDWord(std::basic_istream<char>* stream)
|
||||
Optional<DWord> BinaryStream::getNextDWord(InputStream<Byte>& stream)
|
||||
{
|
||||
char buffer[sizeof(ByteUtils::DWord)];
|
||||
Byte buffer[sizeof(DWord)];
|
||||
if(!BinaryStream::getNextDWord(stream, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ByteUtils::ToDWord(buffer);;
|
||||
return Bits::ToDWord(buffer);
|
||||
}
|
||||
|
||||
std::optional<ByteUtils::QWord> BinaryStream::getNextQWord(std::basic_istream<char>* stream)
|
||||
Optional<QWord> BinaryStream::getNextQWord(InputStream<Byte>& stream)
|
||||
{
|
||||
char buffer[sizeof(ByteUtils::QWord)];
|
||||
if(!BinaryStream::getNextQWord(stream, buffer))
|
||||
Byte buffer[sizeof(QWord)];
|
||||
if(!getNextQWord(stream, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ByteUtils::ToQWord(buffer);;
|
||||
return Bits::ToQWord(buffer);
|
||||
}
|
||||
|
||||
bool BinaryStream::checkNextDWord(std::basic_istream<char>* stream, const char* target)
|
||||
bool BinaryStream::checkNextDWord(InputStream<Byte>& stream, DWord target)
|
||||
{
|
||||
char buffer[sizeof(ByteUtils::DWord)];
|
||||
if(!BinaryStream::getNextDWord(stream, buffer))
|
||||
Byte buffer[sizeof(DWord)];
|
||||
if(!getNextDWord(stream, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!ByteUtils::CompareDWords(buffer, target))
|
||||
if(!Bits::CompareDWords(buffer, target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextString(std::basic_istream<char>* stream, String& target, unsigned numBytes)
|
||||
bool BinaryStream::getNextString(InputStream<Byte>& stream, String& target, size_t numBytes)
|
||||
{
|
||||
char c;
|
||||
for(unsigned idx=0; idx<numBytes; idx++)
|
||||
Byte c{0};
|
||||
for(size_t idx=0; idx<numBytes; idx++)
|
||||
{
|
||||
if(!stream->get(c))
|
||||
if(!stream.get(c))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,40 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include "Stream.h"
|
||||
#include "String.h"
|
||||
#include <optional>
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "Optional.h"
|
||||
#include "ByteTypes.h"
|
||||
|
||||
class BinaryStream
|
||||
{
|
||||
public:
|
||||
|
||||
template<typename T>
|
||||
static bool write(std::basic_ostream<char>* stream, T data)
|
||||
static bool write(OutputStream<Byte>* stream, T data)
|
||||
{
|
||||
stream->write(reinterpret_cast<char*>(&data), sizeof(data));
|
||||
stream->write(reinterpret_cast<Byte*>(&data), sizeof(data));
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::optional<int> getNextByteAsInt(std::basic_istream<char>* stream);
|
||||
static Optional<Byte> getNextByte(InputStream<Byte>& stream);
|
||||
|
||||
static bool getNextNBytes(std::basic_istream<char>* stream, char* buffer, unsigned numBytes);
|
||||
static bool getNextNBytes(InputStream<Byte>& stream, Byte* buffer, size_t numBytes);
|
||||
|
||||
static bool getNextWord(std::basic_istream<char>* stream, char* buffer);
|
||||
static bool getNextWord(InputStream<Byte>& stream, Byte* buffer);
|
||||
|
||||
static bool getNextDWord(std::basic_istream<char>* stream, char* buffer);
|
||||
static bool getNextDWord(InputStream<Byte>& stream, Byte* buffer);
|
||||
|
||||
static bool getNextQWord(std::basic_istream<char>* stream, char* buffer);
|
||||
static bool getNextQWord(InputStream<Byte>& stream, Byte* buffer);
|
||||
|
||||
static std::optional<ByteUtils::Word> getNextWord(std::basic_istream<char>* stream, bool reverse = true);
|
||||
static Optional<Word> getNextWord(InputStream<Byte>& stream, bool reverse = true);
|
||||
|
||||
static std::optional<ByteUtils::DWord> getNextDWord(std::basic_istream<char>* stream);
|
||||
static Optional<DWord> getNextDWord(InputStream<Byte>& stream);
|
||||
|
||||
static std::optional<ByteUtils::QWord> getNextQWord(std::basic_istream<char>* stream);
|
||||
static Optional<QWord> getNextQWord(InputStream<Byte>& stream);
|
||||
|
||||
static bool checkNextDWord(std::basic_istream<char>* stream, const char* target);
|
||||
static bool checkNextDWord(InputStream<Byte>& stream, DWord target);
|
||||
|
||||
static bool getNextString(std::basic_istream<char>* stream, String& target, unsigned numBytes);
|
||||
static bool getNextString(InputStream<Byte>& stream, String& target, size_t numBytes);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "BitStream.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
|
||||
BitStream::~BitStream()
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ void BitStream::write(DWord data)
|
|||
{
|
||||
for(size_t idx=0; idx<sizeof(DWord); idx++)
|
||||
{
|
||||
writeByte(ByteUtils::getByteN(data, idx));
|
||||
writeByte(Bits::getByteN(data, idx));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,23 +45,23 @@ size_t BitStream::getCurrentBitOffset() const
|
|||
String BitStream::logLocation()
|
||||
{
|
||||
String ret;
|
||||
ret << "Byte offset " << mByteOffset<< " | Bit offset " << mBitOffset;
|
||||
ret << " | Working byte " << ByteUtils::toString(getCurrentByte()) << '\n';
|
||||
ret << _s("Byte offset ") << mByteOffset<< _s(" | Bit offset ") << mBitOffset;
|
||||
ret << _s(" | Working byte ") << Bits::toString(getCurrentByte()) << _s('\n');
|
||||
return ret;
|
||||
}
|
||||
|
||||
String BitStream::logNextNBytes(size_t n) const
|
||||
{
|
||||
Stringstream sstr;
|
||||
String sstr;
|
||||
size_t count{0};
|
||||
VecBytes bytes;
|
||||
peekNextNBytes(n, bytes);
|
||||
for(auto byte : bytes)
|
||||
{
|
||||
sstr << mByteOffset + count << " | " << ByteUtils::toString(byte) + '\n';
|
||||
sstr << mByteOffset + count << _s(" | ") << Bits::toString(byte) + _s('\n');
|
||||
count++;
|
||||
}
|
||||
return sstr.str();
|
||||
return sstr;
|
||||
}
|
||||
|
||||
void BitStream::writeNBits(DWord data, size_t length)
|
||||
|
@ -71,7 +71,7 @@ void BitStream::writeNBits(DWord data, size_t length)
|
|||
|
||||
if (overshoot > 0)
|
||||
{
|
||||
Byte lower_bits = ByteUtils::getLowerNBits(data, num_left);
|
||||
Byte lower_bits = Bits::getLowerNBits(data, num_left);
|
||||
mCurrentByte |= lower_bits << mBitOffset;
|
||||
|
||||
writeByte(mCurrentByte, false);
|
||||
|
@ -79,13 +79,13 @@ void BitStream::writeNBits(DWord data, size_t length)
|
|||
size_t num_bytes = overshoot / 8;
|
||||
for (size_t idx=0; idx< num_bytes; idx++)
|
||||
{
|
||||
mCurrentByte = ByteUtils::getMBitsAtN(static_cast<Byte>(data), overshoot, idx*8 + num_left);
|
||||
mCurrentByte = Bits::getMBitsAtN(static_cast<Byte>(data), overshoot, idx*8 + num_left);
|
||||
writeByte(mCurrentByte, false);
|
||||
}
|
||||
|
||||
if (const auto remainder = overshoot % 8; remainder > 0)
|
||||
{
|
||||
mCurrentByte = ByteUtils::getMBitsAtN(static_cast<Byte>(data), remainder, num_bytes*8 + num_left);
|
||||
mCurrentByte = Bits::getMBitsAtN(static_cast<Byte>(data), remainder, num_bytes*8 + num_left);
|
||||
mBitOffset = remainder;
|
||||
}
|
||||
else
|
||||
|
@ -127,8 +127,8 @@ bool BitStream::readNextNBits(size_t n, Byte& buffer)
|
|||
}
|
||||
|
||||
auto num_lower = 8 - mBitOffset;
|
||||
const auto lower_bits = ByteUtils::getHigherNBits(last_byte, num_lower);
|
||||
const auto higher_bits = ByteUtils::getLowerNBits(mCurrentByte, overshoot);
|
||||
const auto lower_bits = Bits::getHigherNBits(last_byte, num_lower);
|
||||
const auto higher_bits = Bits::getLowerNBits(mCurrentByte, overshoot);
|
||||
|
||||
buffer = (higher_bits << num_lower) | lower_bits;
|
||||
|
||||
|
@ -137,7 +137,7 @@ bool BitStream::readNextNBits(size_t n, Byte& buffer)
|
|||
}
|
||||
else
|
||||
{
|
||||
buffer = ByteUtils::getMBitsAtN(mCurrentByte, n, mBitOffset);
|
||||
buffer = Bits::getMBitsAtN(mCurrentByte, n, mBitOffset);
|
||||
mBitOffset += n;
|
||||
return true;
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ void BitStream::flushRemainingBits()
|
|||
}
|
||||
}
|
||||
|
||||
std::pair<Byte, size_t> BitStream::getRemainingBits() const
|
||||
Pair<Byte, size_t> BitStream::getRemainingBits() const
|
||||
{
|
||||
return {mEndByte, mEndBitOffset};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "BufferBitStream.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "Bits.h"
|
||||
|
||||
bool BufferBitStream::isFinished() const
|
||||
{
|
||||
|
@ -32,11 +30,11 @@ void BufferBitStream::peekNextNBytes(size_t n, VecBytes& ret) const
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<uint8_t> BufferBitStream::readNextByte()
|
||||
Optional<uint8_t> BufferBitStream::readNextByte()
|
||||
{
|
||||
if (mByteOffset + 1 == static_cast<int>(mBuffer.size()))
|
||||
{
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -56,10 +54,10 @@ void BufferBitStream::writeByte(uint8_t data, bool checkOverflow)
|
|||
uint8_t out_byte{0};
|
||||
if (checkOverflow && mBitOffset > 0)
|
||||
{
|
||||
out_byte = ByteUtils::getLowerNBits(mCurrentByte, mBitOffset);
|
||||
out_byte = Bits::getLowerNBits(mCurrentByte, mBitOffset);
|
||||
out_byte |= data << mBitOffset;
|
||||
|
||||
mCurrentByte = ByteUtils::getHigherNBits(data, mBitOffset);
|
||||
mCurrentByte = Bits::getHigherNBits(data, mBitOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -70,14 +68,14 @@ void BufferBitStream::writeByte(uint8_t data, bool checkOverflow)
|
|||
{
|
||||
mChecksumCalculator->addValue(out_byte);
|
||||
}
|
||||
//std::cout << "Writing byte " << ByteUtils::toString(out_byte) << " had bitoffset of " << mBitOffset << std::endl;
|
||||
//std::cout << "Writing byte " << Bits::toString(out_byte) << " had bitoffset of " << mBitOffset << std::endl;
|
||||
mBuffer.push_back(out_byte);
|
||||
}
|
||||
|
||||
|
||||
void BufferBitStream::writeBytes(const VecBytes& data)
|
||||
{
|
||||
std::copy(data.begin(), data.end(), std::back_inserter(mBuffer));
|
||||
mBuffer = data;
|
||||
}
|
||||
|
||||
const VecBytes& BufferBitStream::getBuffer() const
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
|
||||
void peekNextNBytes(size_t n, VecBytes& bytes) const override;
|
||||
|
||||
std::optional<uint8_t> readNextByte() override;
|
||||
Optional<uint8_t> readNextByte() override;
|
||||
|
||||
void reset() override;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "InputBitStream.h"
|
||||
|
||||
InputBitStream::InputBitStream(std::basic_istream<unsigned char>* stream)
|
||||
InputBitStream::InputBitStream(InputStream<Byte>* stream)
|
||||
: BitStream(),
|
||||
mStream(stream)
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ void InputBitStream::peekNextNBytes(size_t, VecBytes&) const
|
|||
{
|
||||
}
|
||||
|
||||
std::optional<Byte> InputBitStream::readNextByte()
|
||||
Optional<Byte> InputBitStream::readNextByte()
|
||||
{
|
||||
if (mStream->good())
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ std::optional<Byte> InputBitStream::readNextByte()
|
|||
}
|
||||
else
|
||||
{
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "BitStream.h"
|
||||
|
||||
#include <istream>
|
||||
#include "Stream.h"
|
||||
#include "ByteTypes.h"
|
||||
|
||||
class InputBitStream : public BitStream
|
||||
{
|
||||
InputBitStream(std::basic_istream<unsigned char>* stream);
|
||||
InputBitStream(InputStream<Byte>* stream);
|
||||
|
||||
bool isFinished() const override;
|
||||
|
||||
void peekNextNBytes(size_t n, VecBytes& bytes) const override;
|
||||
|
||||
std::optional<Byte> readNextByte() override;
|
||||
Optional<Byte> readNextByte() override;
|
||||
|
||||
void writeByte(Byte data, bool checkOverflow = true) override;
|
||||
|
||||
|
@ -22,5 +22,5 @@ class InputBitStream : public BitStream
|
|||
}
|
||||
|
||||
private:
|
||||
std::basic_istream<unsigned char>* mStream{nullptr};
|
||||
InputStream<Byte>* mStream{nullptr};
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "OutputBitStream.h"
|
||||
|
||||
OutputBitStream::OutputBitStream(std::basic_ostream<char>* stream)
|
||||
OutputBitStream::OutputBitStream(OutputStream<Byte>* stream)
|
||||
: BitStream(),
|
||||
mStream(stream)
|
||||
{
|
||||
|
@ -17,14 +17,14 @@ void OutputBitStream::peekNextNBytes(size_t, VecBytes&) const
|
|||
|
||||
}
|
||||
|
||||
std::optional<uint8_t> OutputBitStream::readNextByte()
|
||||
Optional<uint8_t> OutputBitStream::readNextByte()
|
||||
{
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
void OutputBitStream::writeByte(uint8_t data, bool)
|
||||
{
|
||||
(*mStream) << data;
|
||||
//(*mStream) << data;
|
||||
}
|
||||
|
||||
void OutputBitStream::writeBytes(const VecBytes& data)
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "BitStream.h"
|
||||
|
||||
#include <ostream>
|
||||
#include "Stream.h"
|
||||
#include "ByteTypes.h"
|
||||
|
||||
class OutputBitStream : public BitStream
|
||||
{
|
||||
public:
|
||||
OutputBitStream(std::basic_ostream<char>* stream);
|
||||
OutputBitStream(OutputStream<Byte>* stream);
|
||||
|
||||
bool isFinished() const override;
|
||||
|
||||
void peekNextNBytes(size_t n, VecBytes& bytes) const override;
|
||||
|
||||
std::optional<Byte> readNextByte() override;
|
||||
Optional<Byte> readNextByte() override;
|
||||
|
||||
void writeByte(Byte data, bool checkOverflow = true) override;
|
||||
|
||||
void writeBytes(const VecBytes& data) override;
|
||||
|
||||
private:
|
||||
std::basic_ostream<char>* mStream{nullptr};
|
||||
OutputStream<Byte>* mStream{nullptr};
|
||||
};
|
||||
|
|
27
src/base/core/streams/Stream.h
Normal file
27
src/base/core/streams/Stream.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "Optional.h"
|
||||
#include <cstddef>
|
||||
|
||||
template<typename T>
|
||||
class Stream
|
||||
{
|
||||
public:
|
||||
virtual bool good() const = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class InputStream : public Stream<T>
|
||||
{
|
||||
public:
|
||||
virtual Optional<T> get() = 0;
|
||||
|
||||
virtual bool get(T& item) = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class OutputStream : public Stream<T>
|
||||
{
|
||||
public:
|
||||
virtual void write(T* data, size_t size) = 0;
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
#include "CommandLineArgs.h"
|
||||
|
||||
#include "UnicodeUtils.h"
|
||||
#include "Unicode.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Win32BaseIncludes.h"
|
||||
|
@ -26,7 +26,7 @@ void CommandLineArgs::initialize(CommandLineArgs* args)
|
|||
Vector<String> windowsArgs(nArgs);
|
||||
for (int idx = 0; idx < nArgs; idx++)
|
||||
{
|
||||
windowsArgs[idx] = UnicodeUtils::utf16ToUtf8String(szArglist[idx]);
|
||||
windowsArgs[idx] = Unicode::utf16ToUtf8String(szArglist[idx]);
|
||||
}
|
||||
::LocalFree(szArglist);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ Vector<uint8_t> ImageBitStream::peekNextNBytes(size_t) const
|
|||
return {};
|
||||
}
|
||||
|
||||
std::optional<uint8_t> ImageBitStream::readNextByte()
|
||||
Optional<uint8_t> ImageBitStream::readNextByte()
|
||||
{
|
||||
mByteOffset++;
|
||||
if (isFinished() )
|
||||
|
|
|
@ -15,7 +15,7 @@ public:
|
|||
|
||||
Vector<uint8_t> peekNextNBytes(size_t n) const override;
|
||||
|
||||
std::optional<uint8_t> readNextByte() override;
|
||||
Optional<uint8_t> readNextByte() override;
|
||||
|
||||
void writeByte(uint8_t data, bool checkOverflow = true) override;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "HuffmanEncoder.h"
|
||||
#include "CyclicRedundancyChecker.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "PngHeader.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "StringUtils.h"
|
||||
#include "CyclicRedundancyChecker.h"
|
||||
|
||||
|
@ -74,12 +74,12 @@ void PngHeader::updateData()
|
|||
|
||||
for(size_t idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mData.push_back(ByteUtils::getByteN(mWidth, idx));
|
||||
mData.push_back(Bits::getByteN(mWidth, idx));
|
||||
}
|
||||
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mData.push_back(ByteUtils::getByteN(mHeight, idx));
|
||||
mData.push_back(Bits::getByteN(mHeight, idx));
|
||||
}
|
||||
mData.push_back(mBitDepth);
|
||||
mData.push_back(static_cast<Byte>(mPngInfo.mColorType));
|
||||
|
|
|
@ -28,7 +28,7 @@ Map<String, LatexMathSymbol::Tag> LatexSymbolLookup::mTags = {
|
|||
{"ket", LatexMathSymbol::Tag::KET},
|
||||
};
|
||||
|
||||
std::optional<String> LatexSymbolLookup::getLeftSymbolUtf8(LatexMathSymbol::Tag tag)
|
||||
Optional<String> LatexSymbolLookup::getLeftSymbolUtf8(LatexMathSymbol::Tag tag)
|
||||
{
|
||||
if (auto entry = getLeftSymbolUtf16(tag); entry)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ std::optional<String> LatexSymbolLookup::getLeftSymbolUtf8(LatexMathSymbol::Tag
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<String> LatexSymbolLookup::getRightSymbolUtf8(LatexMathSymbol::Tag tag)
|
||||
Optional<String> LatexSymbolLookup::getRightSymbolUtf8(LatexMathSymbol::Tag tag)
|
||||
{
|
||||
if (auto entry = getRightSymbolUtf16(tag); entry)
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ std::optional<String> LatexSymbolLookup::getRightSymbolUtf8(LatexMathSymbol::Tag
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<String> LatexSymbolLookup::getSymbolUtf8(const String& tag)
|
||||
Optional<String> LatexSymbolLookup::getSymbolUtf8(const String& tag)
|
||||
{
|
||||
if (auto entry = getSymbolUtf16(tag); entry)
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ std::optional<String> LatexSymbolLookup::getSymbolUtf8(const String& tag)
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<std::wstring> LatexSymbolLookup::getLeftSymbolUtf16(LatexMathSymbol::Tag tag)
|
||||
Optional<std::wstring> LatexSymbolLookup::getLeftSymbolUtf16(LatexMathSymbol::Tag tag)
|
||||
{
|
||||
if (auto iter = mLeftSymbols.find(tag); iter != mLeftSymbols.end())
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ std::optional<std::wstring> LatexSymbolLookup::getLeftSymbolUtf16(LatexMathSymbo
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<std::wstring> LatexSymbolLookup::getRightSymbolUtf16(LatexMathSymbol::Tag tag)
|
||||
Optional<std::wstring> LatexSymbolLookup::getRightSymbolUtf16(LatexMathSymbol::Tag tag)
|
||||
{
|
||||
if (auto iter = mRightSymbols.find(tag); iter != mRightSymbols.end())
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ std::optional<std::wstring> LatexSymbolLookup::getRightSymbolUtf16(LatexMathSymb
|
|||
|
||||
}
|
||||
|
||||
std::optional<std::wstring> LatexSymbolLookup::getSymbolUtf16(const String& tag)
|
||||
Optional<std::wstring> LatexSymbolLookup::getSymbolUtf16(const String& tag)
|
||||
{
|
||||
if (auto iter = mSymbols.find(tag); iter != mSymbols.end())
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ std::optional<std::wstring> LatexSymbolLookup::getSymbolUtf16(const String& tag)
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<LatexMathSymbol::Tag> LatexSymbolLookup::getKnownTag(const String& tag)
|
||||
Optional<LatexMathSymbol::Tag> LatexSymbolLookup::getKnownTag(const String& tag)
|
||||
{
|
||||
if (auto iter = mTags.find(tag); iter != mTags.end())
|
||||
{
|
||||
|
|
|
@ -40,19 +40,19 @@ struct LatexMathSymbol
|
|||
class LatexSymbolLookup
|
||||
{
|
||||
public:
|
||||
static std::optional<String> getLeftSymbolUtf8(LatexMathSymbol::Tag tag);
|
||||
static Optional<String> getLeftSymbolUtf8(LatexMathSymbol::Tag tag);
|
||||
|
||||
static std::optional<String> getRightSymbolUtf8(LatexMathSymbol::Tag tag);
|
||||
static Optional<String> getRightSymbolUtf8(LatexMathSymbol::Tag tag);
|
||||
|
||||
static std::optional<String> getSymbolUtf8(const String& tag);
|
||||
static Optional<String> getSymbolUtf8(const String& tag);
|
||||
|
||||
static std::optional<std::wstring> getLeftSymbolUtf16(LatexMathSymbol::Tag tag);
|
||||
static Optional<std::wstring> getLeftSymbolUtf16(LatexMathSymbol::Tag tag);
|
||||
|
||||
static std::optional<std::wstring> getRightSymbolUtf16(LatexMathSymbol::Tag tag);
|
||||
static Optional<std::wstring> getRightSymbolUtf16(LatexMathSymbol::Tag tag);
|
||||
|
||||
static std::optional<std::wstring> getSymbolUtf16(const String& tag);
|
||||
static Optional<std::wstring> getSymbolUtf16(const String& tag);
|
||||
|
||||
static std::optional<LatexMathSymbol::Tag> getKnownTag(const String& tag);
|
||||
static Optional<LatexMathSymbol::Tag> getKnownTag(const String& tag);
|
||||
|
||||
static size_t getNumTagBodies(LatexMathSymbol::Tag tag)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ include(TestTargets)
|
|||
unit_tests(
|
||||
MODULE_NAME core
|
||||
FILES
|
||||
TestByteUtils.cpp
|
||||
TestBits.cpp
|
||||
TestBitStream.cpp
|
||||
TestDataStructures.cpp
|
||||
TestTomlReader.cpp
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "BufferBitStream.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
|
@ -16,27 +16,27 @@ TEST_CASE(TestReadBitStream, "core")
|
|||
BufferBitStream stream;
|
||||
for(const auto& byte : bytes)
|
||||
{
|
||||
stream.writeByte(ByteUtils::getFromString(byte));
|
||||
stream.writeByte(Bits::getFromString(byte));
|
||||
}
|
||||
|
||||
unsigned char buffer{0} ;
|
||||
auto valid = stream.readNextNBits(1, buffer);
|
||||
//std::cout << "Slice0 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Slice0 is " << Bits::toString(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(2, buffer);
|
||||
//std::cout << "Slice1 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Slice1 is " << Bits::toString(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(5, buffer);
|
||||
//std::cout << "Slice2 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Slice2 is " << Bits::toString(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(5, buffer);
|
||||
//std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Slice3 is " << Bits::toString(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(4, buffer);
|
||||
//std::cout << "Slice3 is " << ByteUtils::toString(buffer) << " and int " << static_cast<int>(buffer) << std::endl;
|
||||
//std::cout << "Slice3 is " << Bits::toString(buffer) << " and int " << static_cast<int>(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(3, buffer);
|
||||
//std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Slice3 is " << Bits::toString(buffer) << std::endl;
|
||||
REQUIRE(valid);
|
||||
}
|
||||
|
||||
|
@ -44,30 +44,30 @@ TEST_CASE(TestWritingBitStream, "core")
|
|||
{
|
||||
BufferBitStream stream;
|
||||
|
||||
stream.writeByte(ByteUtils::getFromString("01100000"));
|
||||
stream.writeByte(Bits::getFromString("01100000"));
|
||||
|
||||
auto bits0 = ByteUtils::getFromString("00000111");
|
||||
auto bits0 = Bits::getFromString("00000111");
|
||||
stream.writeNBits(bits0, 3);
|
||||
|
||||
stream.writeByte(ByteUtils::getFromString("11110000"));
|
||||
stream.writeByte(Bits::getFromString("11110000"));
|
||||
|
||||
auto bits1 = ByteUtils::getFromString("01001101");
|
||||
auto bits1 = Bits::getFromString("01001101");
|
||||
stream.writeNBits(bits1, 7);
|
||||
|
||||
stream.writeByte(ByteUtils::getFromString("11110000"));
|
||||
stream.writeByte(Bits::getFromString("11110000"));
|
||||
|
||||
auto bits2 = ByteUtils::getFromString("00000001");
|
||||
auto bits2 = Bits::getFromString("00000001");
|
||||
stream.writeNBits(bits2, 1);
|
||||
|
||||
stream.flushRemainingBits();
|
||||
|
||||
stream.resetOffsets();
|
||||
|
||||
auto byte0 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte1 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte2 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte3 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte4 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte0 = Bits::toString(*stream.readNextByte());
|
||||
auto byte1 = Bits::toString(*stream.readNextByte());
|
||||
auto byte2 = Bits::toString(*stream.readNextByte());
|
||||
auto byte3 = Bits::toString(*stream.readNextByte());
|
||||
auto byte4 = Bits::toString(*stream.readNextByte());
|
||||
|
||||
//std::cout << "Got bytes 0 " << byte0 << std::endl;
|
||||
//std::cout << "Got bytes 1 " << byte1 << std::endl;
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE(TestReadByteUtils, "core")
|
||||
TEST_CASE(TestReadBits, "core")
|
||||
{
|
||||
auto byte = ByteUtils::getFromString("00110101");
|
||||
auto byte = Bits::getFromString("00110101");
|
||||
//std::cout << "Value is " << static_cast<unsigned>(byte) << std::endl;
|
||||
|
||||
auto string_rep = ByteUtils::toString(byte);
|
||||
auto string_rep = Bits::toString(byte);
|
||||
//std::cout << "String rep is " << string_rep << std::endl;
|
||||
|
||||
auto slice = ByteUtils::getMBitsAtN(byte, 3, 3);
|
||||
//std::cout << "Slice is " << ByteUtils::toString(slice) << std::endl;
|
||||
auto slice = Bits::getMBitsAtN(byte, 3, 3);
|
||||
//std::cout << "Slice is " << Bits::toString(slice) << std::endl;
|
||||
(void) slice;
|
||||
|
||||
uint32_t input {12345678};
|
||||
auto byte0 = ByteUtils::getByteN(input, 0);
|
||||
auto byte1 = ByteUtils::getByteN(input, 1);
|
||||
auto byte2 = ByteUtils::getByteN(input, 2);
|
||||
auto byte3 = ByteUtils::getByteN(input, 3);
|
||||
auto byte0 = Bits::getByteN(input, 0);
|
||||
auto byte1 = Bits::getByteN(input, 1);
|
||||
auto byte2 = Bits::getByteN(input, 2);
|
||||
auto byte3 = Bits::getByteN(input, 3);
|
||||
|
||||
(void)byte0;
|
||||
(void)byte1;
|
||||
(void)byte2;
|
||||
(void)byte3;
|
||||
|
||||
//std::cout << "Byte0 is " << ByteUtils::toString(byte0) << std::endl;
|
||||
//std::cout << "Byte1 is " << ByteUtils::toString(byte1) << std::endl;
|
||||
//std::cout << "Byte2 is " << ByteUtils::toString(byte2) << std::endl;
|
||||
//std::cout << "Byte3 is " << ByteUtils::toString(byte3) << std::endl;
|
||||
//std::cout << "Byte0 is " << Bits::toString(byte0) << std::endl;
|
||||
//std::cout << "Byte1 is " << Bits::toString(byte1) << std::endl;
|
||||
//std::cout << "Byte2 is " << Bits::toString(byte2) << std::endl;
|
||||
//std::cout << "Byte3 is " << Bits::toString(byte3) << std::endl;
|
||||
|
||||
//std::cout << "Mirroring" << std::endl;
|
||||
|
||||
//auto out = ByteUtils::mirror(byte);
|
||||
//std::cout << "Mirror is " << ByteUtils::toString(out) << std::endl;
|
||||
//auto out = Bits::mirror(byte);
|
||||
//std::cout << "Mirror is " << Bits::toString(out) << std::endl;
|
||||
|
||||
unsigned hold = byte;
|
||||
hold = (hold << 5) + 3;
|
||||
(void)hold;
|
||||
//std::cout << "Big val is " << ByteUtils::toString(hold, 16) << std::endl;
|
||||
//std::cout << "Big val is " << Bits::toString(hold, 16) << std::endl;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "File.h"
|
||||
#include "BitStream.h"
|
||||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
#include "Grid.h"
|
||||
#include "ImagePrimitives.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue