Toward core module compiling.
This commit is contained in:
parent
c25a56ee19
commit
3ed195d7dd
305 changed files with 1774 additions and 1065 deletions
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class CanvasController
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
#include "NotesTk.h"
|
||||
#include "MainApplication.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "String.h"
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class PlainTextDocument
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include <filesystem>
|
||||
#include "TextEditorModel.h"
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "PlainTextDocument.h"
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class TextEditorModel
|
||||
{
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
|
||||
#include "String.h"
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include Map.h
|
||||
|
||||
class MarkdownDocument;
|
||||
|
||||
class ContentFile
|
||||
{
|
||||
public:
|
||||
using FileMetadata = std::unordered_map<String, String>;
|
||||
using FileMetadata = Map<String, String>;
|
||||
using FileContentBody = Vector<String>;
|
||||
|
||||
ContentFile(const Path& filename);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "String.h"
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include Map.h
|
||||
#include <filesystem>
|
||||
#include "Vector.h"
|
||||
|
||||
|
@ -14,7 +14,7 @@ class MarkdownContentParser
|
|||
{
|
||||
public:
|
||||
using FileMetadataItem = std::pair<String, String>;
|
||||
using FileMetadata = std::unordered_map<String, String>;
|
||||
using FileMetadata = Map<String, String>;
|
||||
|
||||
std::pair<FileMetadata, Ptr<MarkdownDocument>> run(const Path& path);
|
||||
private:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "String.h"
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <unordered_map>
|
||||
#include Map.h
|
||||
#include "Vector.h"
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "String.h"
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
|
||||
class CircuitElement
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include "Vector.h"
|
||||
|
||||
#include "CircuitElement.h"
|
||||
|
|
|
@ -8,7 +8,7 @@ class TruthTable
|
|||
public:
|
||||
using TableData = std::map<Vector<bool>, Vector<bool> >;
|
||||
|
||||
TruthTable(std::size_t, std::size_t)
|
||||
TruthTable(size_t, size_t)
|
||||
//: mNumInputColumns(numInputColumns),
|
||||
// mNumOutputColumns(numOutputColumns)
|
||||
{
|
||||
|
@ -25,8 +25,8 @@ public:
|
|||
static const TruthTable::TableData AND_TRUTH_TABLE;
|
||||
|
||||
private:
|
||||
//std::size_t mNumInputColumns{ 0 };
|
||||
//std::size_t mNumOutputColumns{ 0 };
|
||||
//size_t mNumInputColumns{ 0 };
|
||||
//size_t mNumOutputColumns{ 0 };
|
||||
|
||||
TableData mTable;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "LogicGate.h"
|
||||
|
||||
NInMOutLogicGate::NInMOutLogicGate(std::size_t numIn, std::size_t numOut, Vector<Wire*> inputs, Vector<Wire*> outputs)
|
||||
NInMOutLogicGate::NInMOutLogicGate(size_t numIn, size_t numOut, Vector<Wire*> inputs, Vector<Wire*> outputs)
|
||||
: LogicGate(),
|
||||
mNumIn(numIn),
|
||||
mNumOut(numOut)
|
||||
|
@ -24,17 +24,17 @@ NInMOutLogicGate::NInMOutLogicGate(std::size_t numIn, std::size_t numOut, Vector
|
|||
}
|
||||
}
|
||||
|
||||
std::size_t NInMOutLogicGate::getNumInputs() const
|
||||
size_t NInMOutLogicGate::getNumInputs() const
|
||||
{
|
||||
return mNumIn;
|
||||
}
|
||||
|
||||
std::size_t NInMOutLogicGate::getNumOutputs() const
|
||||
size_t NInMOutLogicGate::getNumOutputs() const
|
||||
{
|
||||
return mNumOut;
|
||||
}
|
||||
|
||||
Wire* NInMOutLogicGate::getInput(std::size_t idx) const
|
||||
Wire* NInMOutLogicGate::getInput(size_t idx) const
|
||||
{
|
||||
if (idx < mNumIn)
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ Wire* NInMOutLogicGate::getInput(std::size_t idx) const
|
|||
}
|
||||
}
|
||||
|
||||
Wire* NInMOutLogicGate::getOutput(std::size_t idx) const
|
||||
Wire* NInMOutLogicGate::getOutput(size_t idx) const
|
||||
{
|
||||
if (idx < mNumOut)
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ Wire* NInMOutLogicGate::getOutput(std::size_t idx) const
|
|||
}
|
||||
}
|
||||
|
||||
void NInMOutLogicGate::setAtInput(std::size_t idx, Wire* value)
|
||||
void NInMOutLogicGate::setAtInput(size_t idx, Wire* value)
|
||||
{
|
||||
if (idx < mInputs.size())
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ void NInMOutLogicGate::setAtInput(std::size_t idx, Wire* value)
|
|||
}
|
||||
}
|
||||
|
||||
void NInMOutLogicGate::setAtOutput(std::size_t idx, Wire* value)
|
||||
void NInMOutLogicGate::setAtOutput(size_t idx, Wire* value)
|
||||
{
|
||||
if (idx < mOutputs.size())
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "TruthTable.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include "Vector.h"
|
||||
|
||||
class LogicGate : public CircuitElement
|
||||
|
@ -20,13 +20,13 @@ public:
|
|||
};
|
||||
virtual ~LogicGate() = default;
|
||||
|
||||
virtual std::size_t getNumInputs() const = 0;
|
||||
virtual size_t getNumInputs() const = 0;
|
||||
|
||||
virtual std::size_t getNumOutputs() const = 0;
|
||||
virtual size_t getNumOutputs() const = 0;
|
||||
|
||||
virtual Wire* getInput(std::size_t idx) const = 0;
|
||||
virtual Wire* getInput(size_t idx) const = 0;
|
||||
|
||||
virtual Wire* getOutput(std::size_t idx) const = 0;
|
||||
virtual Wire* getOutput(size_t idx) const = 0;
|
||||
|
||||
virtual const TruthTable& getTruthTable() = 0;
|
||||
|
||||
|
@ -41,25 +41,25 @@ public:
|
|||
class NInMOutLogicGate : public LogicGate
|
||||
{
|
||||
public:
|
||||
NInMOutLogicGate(std::size_t numIn, std::size_t numOut, Vector<Wire*> inputs = {}, Vector<Wire*> outputs = {});
|
||||
NInMOutLogicGate(size_t numIn, size_t numOut, Vector<Wire*> inputs = {}, Vector<Wire*> outputs = {});
|
||||
|
||||
virtual ~NInMOutLogicGate() = default;
|
||||
|
||||
std::size_t getNumInputs() const override;
|
||||
size_t getNumInputs() const override;
|
||||
|
||||
std::size_t getNumOutputs() const override;
|
||||
size_t getNumOutputs() const override;
|
||||
|
||||
Wire* getInput(std::size_t idx) const override;
|
||||
Wire* getInput(size_t idx) const override;
|
||||
|
||||
Wire* getOutput(std::size_t idx) const override;
|
||||
Wire* getOutput(size_t idx) const override;
|
||||
|
||||
void setAtInput(std::size_t idx, Wire* value);
|
||||
void setAtInput(size_t idx, Wire* value);
|
||||
|
||||
void setAtOutput(std::size_t idx, Wire* value);
|
||||
void setAtOutput(size_t idx, Wire* value);
|
||||
|
||||
private:
|
||||
std::size_t mNumIn{ 1 };
|
||||
std::size_t mNumOut{ 1 };
|
||||
size_t mNumIn{ 1 };
|
||||
size_t mNumOut{ 1 };
|
||||
|
||||
Vector<Wire*> mInputs;
|
||||
Vector<Wire*> mOutputs;
|
||||
|
|
|
@ -37,12 +37,12 @@ void ElectronicCircuitNode::buildWireConnections()
|
|||
|
||||
for (auto gate : mContent->getLogicGates())
|
||||
{
|
||||
for (std::size_t idx = 0; idx < gate->getNumInputs(); idx++)
|
||||
for (size_t idx = 0; idx < gate->getNumInputs(); idx++)
|
||||
{
|
||||
mWireInputConnections[gate->getInput(idx)] = gate;
|
||||
}
|
||||
|
||||
for (std::size_t idx = 0; idx < gate->getNumOutputs(); idx++)
|
||||
for (size_t idx = 0; idx < gate->getNumOutputs(); idx++)
|
||||
{
|
||||
mWireOutputConnections[gate->getOutput(idx)] = gate;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "ElectronicCircuit.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include Map.h
|
||||
|
||||
class WireNode;
|
||||
class TerminalNode;
|
||||
|
@ -36,8 +36,8 @@ private:
|
|||
Vector<Ptr<WireNode> > mWireNodes;
|
||||
Vector<Ptr<LogicGateNode> > mLogicGateNodes;
|
||||
|
||||
std::unordered_map<Wire*, CircuitElement*> mWireInputConnections;
|
||||
std::unordered_map<Wire*, CircuitElement*> mWireOutputConnections;
|
||||
Map<Wire*, CircuitElement*> mWireInputConnections;
|
||||
Map<Wire*, CircuitElement*> mWireOutputConnections;
|
||||
|
||||
std::unordered_map<CircuitElement*, CircuitElementNode*> mNodesForContent;
|
||||
Map<CircuitElement*, CircuitElementNode*> mNodesForContent;
|
||||
};
|
||||
|
|
|
@ -21,9 +21,9 @@ LogicGateNode::~LogicGateNode()
|
|||
Point2 LogicGateNode::getConnectionLocation(Wire* wire) const
|
||||
{
|
||||
bool is_input{ false };
|
||||
std::size_t connection_id{ 0 };
|
||||
size_t connection_id{ 0 };
|
||||
|
||||
for (std::size_t idx = 0; idx < mContent->getNumInputs(); idx++)
|
||||
for (size_t idx = 0; idx < mContent->getNumInputs(); idx++)
|
||||
{
|
||||
if (mContent->getInput(idx) == wire)
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ Point2 LogicGateNode::getConnectionLocation(Wire* wire) const
|
|||
}
|
||||
}
|
||||
|
||||
for (std::size_t idx = 0; idx < mContent->getNumOutputs(); idx++)
|
||||
for (size_t idx = 0; idx < mContent->getNumOutputs(); idx++)
|
||||
{
|
||||
if (mContent->getOutput(idx) == wire)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@ String LogicGatePrimitiveShapes::getAndGateShape()
|
|||
return "M4 8 h24 a16 16 0 0 1 0 32 h-24Z";
|
||||
}
|
||||
|
||||
Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, std::size_t idx)
|
||||
Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, size_t idx)
|
||||
{
|
||||
if (isInput)
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ String LogicGatePrimitiveShapes::getOrGateShape()
|
|||
return "M4 8 h16 q16 2 24 16 q-12 16 -24 16 h-16 q12 -16 0 -32Z";
|
||||
}
|
||||
|
||||
Point2 LogicGatePrimitiveShapes::getOrGateConnectionLocation(bool isInput, std::size_t idx)
|
||||
Point2 LogicGatePrimitiveShapes::getOrGateConnectionLocation(bool isInput, size_t idx)
|
||||
{
|
||||
if (isInput)
|
||||
{
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
class LogicGatePrimitiveShapes
|
||||
{
|
||||
public:
|
||||
static Point2 getAndGateConnectionLocation(bool isInput, std::size_t idx);
|
||||
static Point2 getAndGateConnectionLocation(bool isInput, size_t idx);
|
||||
|
||||
static String getAndGateShape();
|
||||
|
||||
static Point2 getOrGateConnectionLocation(bool isInput, std::size_t idx);
|
||||
static Point2 getOrGateConnectionLocation(bool isInput, size_t idx);
|
||||
|
||||
static String getOrGateShape();
|
||||
};
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "MidiEvent.h"
|
||||
#include "MidiElements.h"
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include "String.h"
|
||||
|
||||
class MetaMidiEvent : public MidiEvent
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Vector.h"
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include "String.h"
|
||||
|
||||
#include "MidiElements.h"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class MidiEvent
|
||||
{
|
||||
|
|
|
@ -17,12 +17,12 @@ void MidiTrack::AddEvent(MidiEventPtr event)
|
|||
mEvents.push_back(std::move(event));
|
||||
}
|
||||
|
||||
MidiEvent* MidiTrack::GetEvent(std::size_t idx) const
|
||||
MidiEvent* MidiTrack::GetEvent(size_t idx) const
|
||||
{
|
||||
return mEvents[idx].get();
|
||||
}
|
||||
|
||||
std::size_t MidiTrack::GetNumEvents()
|
||||
size_t MidiTrack::GetNumEvents()
|
||||
{
|
||||
return mEvents.size();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Vector.h"
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include "String.h"
|
||||
#include "MidiEvent.h"
|
||||
|
||||
|
@ -18,9 +18,9 @@ public:
|
|||
|
||||
void AddEvent(MidiEventPtr event);
|
||||
|
||||
MidiEvent* GetEvent(std::size_t idx) const;
|
||||
MidiEvent* GetEvent(size_t idx) const;
|
||||
|
||||
std::size_t GetNumEvents();
|
||||
size_t GetNumEvents();
|
||||
|
||||
String Serialize() const;
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ void QuantumCircuit::buildWireConnections()
|
|||
{
|
||||
if (wire->getOutput() == gate)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < gate->getNumInputs(); idx++)
|
||||
for (size_t idx = 0; idx < gate->getNumInputs(); idx++)
|
||||
{
|
||||
if (gate->getInput(idx) == nullptr)
|
||||
{
|
||||
|
@ -107,7 +107,7 @@ void QuantumCircuit::buildWireConnections()
|
|||
|
||||
if (wire->getInput() == gate)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < gate->getNumOutputs(); idx++)
|
||||
for (size_t idx = 0; idx < gate->getNumOutputs(); idx++)
|
||||
{
|
||||
if (gate->getOutput(idx) == nullptr)
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@ Ptr<QuantumCircuit> QuantumCircuitReader::read(const String& content)
|
|||
auto circuit = std::make_unique<QuantumCircuit>();
|
||||
mWorkingCircuit = circuit.get();
|
||||
|
||||
std::size_t cursor = 0;
|
||||
size_t cursor = 0;
|
||||
for (const auto& line : StringUtils::toLines(content))
|
||||
{
|
||||
onLine(line, cursor);
|
||||
|
@ -31,10 +31,10 @@ Ptr<QuantumCircuit> QuantumCircuitReader::read(const String& content)
|
|||
return circuit;
|
||||
}
|
||||
|
||||
void QuantumCircuitReader::onLine(const String& line, std::size_t jdx)
|
||||
void QuantumCircuitReader::onLine(const String& line, size_t jdx)
|
||||
{
|
||||
mWorkingString.clear();
|
||||
std::size_t cursor = 0;
|
||||
size_t cursor = 0;
|
||||
|
||||
while (cursor < line.size())
|
||||
{
|
||||
|
@ -157,9 +157,9 @@ void QuantumCircuitReader::onKet(Location, const String value)
|
|||
mWorkingCircuit->addInputTerminal(std::move(input_terminal));
|
||||
}
|
||||
|
||||
std::size_t QuantumCircuitReader::getWireEnd(const String& segment)
|
||||
size_t QuantumCircuitReader::getWireEnd(const String& segment)
|
||||
{
|
||||
std::size_t idx = 0;
|
||||
size_t idx = 0;
|
||||
for (const auto c : segment)
|
||||
{
|
||||
if (c != '-')
|
||||
|
|
|
@ -16,15 +16,15 @@ public:
|
|||
Ptr<QuantumCircuit> read(const String& content);
|
||||
|
||||
private:
|
||||
using Location = std::pair<std::size_t, std::size_t>;
|
||||
using Location = std::pair<size_t, size_t>;
|
||||
|
||||
void onLine(const String& line, std::size_t jdx);
|
||||
void onLine(const String& line, size_t jdx);
|
||||
|
||||
String checkForKet(const String& segment);
|
||||
|
||||
String checkForGate(const String& segment);
|
||||
|
||||
std::size_t getWireEnd(const String& segment);
|
||||
size_t getWireEnd(const String& segment);
|
||||
|
||||
void onGate(Location loc, const String value);
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ bool Qubit::isIn1State() const
|
|||
return mBeta.getReal() == 1.0 && mAlpha.getMagnitude() == 0.0;
|
||||
}
|
||||
|
||||
String Qubit::toString(std::size_t precision) const
|
||||
String Qubit::toString(size_t precision) const
|
||||
{
|
||||
Stringstream sstr;
|
||||
sstr.precision(precision);
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
bool isIn1State() const;
|
||||
|
||||
String toString(std::size_t precision=3) const;
|
||||
String toString(size_t precision=3) const;
|
||||
private:
|
||||
ComplexNumber mAlpha;
|
||||
ComplexNumber mBeta;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class QuantumCircuitElement
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "QuantumGate.h"
|
||||
|
||||
NInMOutQuantumGate::NInMOutQuantumGate(std::size_t numIn, std::size_t numOut, Vector<AbstractQuantumWire*> inputs, Vector<AbstractQuantumWire*> outputs)
|
||||
NInMOutQuantumGate::NInMOutQuantumGate(size_t numIn, size_t numOut, Vector<AbstractQuantumWire*> inputs, Vector<AbstractQuantumWire*> outputs)
|
||||
: QuantumGate(),
|
||||
mNumIn(numIn),
|
||||
mNumOut(numOut)
|
||||
|
@ -24,17 +24,17 @@ NInMOutQuantumGate::NInMOutQuantumGate(std::size_t numIn, std::size_t numOut, Ve
|
|||
}
|
||||
}
|
||||
|
||||
std::size_t NInMOutQuantumGate::getNumInputs() const
|
||||
size_t NInMOutQuantumGate::getNumInputs() const
|
||||
{
|
||||
return mNumIn;
|
||||
}
|
||||
|
||||
std::size_t NInMOutQuantumGate::getNumOutputs() const
|
||||
size_t NInMOutQuantumGate::getNumOutputs() const
|
||||
{
|
||||
return mNumOut;
|
||||
}
|
||||
|
||||
AbstractQuantumWire* NInMOutQuantumGate::getInput(std::size_t idx) const
|
||||
AbstractQuantumWire* NInMOutQuantumGate::getInput(size_t idx) const
|
||||
{
|
||||
if (idx < mNumIn)
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ AbstractQuantumWire* NInMOutQuantumGate::getInput(std::size_t idx) const
|
|||
}
|
||||
}
|
||||
|
||||
AbstractQuantumWire* NInMOutQuantumGate::getOutput(std::size_t idx) const
|
||||
AbstractQuantumWire* NInMOutQuantumGate::getOutput(size_t idx) const
|
||||
{
|
||||
if (idx < mNumOut)
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ AbstractQuantumWire* NInMOutQuantumGate::getOutput(std::size_t idx) const
|
|||
}
|
||||
}
|
||||
|
||||
void NInMOutQuantumGate::setAtInput(std::size_t idx, AbstractQuantumWire* value)
|
||||
void NInMOutQuantumGate::setAtInput(size_t idx, AbstractQuantumWire* value)
|
||||
{
|
||||
if (idx < mInputs.size())
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ void NInMOutQuantumGate::setAtInput(std::size_t idx, AbstractQuantumWire* value)
|
|||
}
|
||||
}
|
||||
|
||||
void NInMOutQuantumGate::setAtOutput(std::size_t idx, AbstractQuantumWire* value)
|
||||
void NInMOutQuantumGate::setAtOutput(size_t idx, AbstractQuantumWire* value)
|
||||
{
|
||||
if (idx < mOutputs.size())
|
||||
{
|
||||
|
|
|
@ -20,17 +20,17 @@ public:
|
|||
};
|
||||
virtual ~QuantumGate() = default;
|
||||
|
||||
virtual std::size_t getNumInputs() const = 0;
|
||||
virtual size_t getNumInputs() const = 0;
|
||||
|
||||
virtual std::size_t getNumOutputs() const = 0;
|
||||
virtual size_t getNumOutputs() const = 0;
|
||||
|
||||
virtual AbstractQuantumWire* getInput(std::size_t idx) const = 0;
|
||||
virtual AbstractQuantumWire* getInput(size_t idx) const = 0;
|
||||
|
||||
virtual AbstractQuantumWire* getOutput(std::size_t idx) const = 0;
|
||||
virtual AbstractQuantumWire* getOutput(size_t idx) const = 0;
|
||||
|
||||
virtual void setAtInput(std::size_t idx, AbstractQuantumWire* value) = 0;
|
||||
virtual void setAtInput(size_t idx, AbstractQuantumWire* value) = 0;
|
||||
|
||||
virtual void setAtOutput(std::size_t idx, AbstractQuantumWire* value) = 0;
|
||||
virtual void setAtOutput(size_t idx, AbstractQuantumWire* value) = 0;
|
||||
|
||||
virtual GateType getGateType() const = 0;
|
||||
|
||||
|
@ -45,21 +45,21 @@ using QuantumGatePtr = Ptr<QuantumGate>;
|
|||
class NInMOutQuantumGate : public QuantumGate
|
||||
{
|
||||
public:
|
||||
NInMOutQuantumGate(std::size_t numIn, std::size_t numOut, Vector<AbstractQuantumWire*> inputs = {}, Vector<AbstractQuantumWire*> outputs = {});
|
||||
NInMOutQuantumGate(size_t numIn, size_t numOut, Vector<AbstractQuantumWire*> inputs = {}, Vector<AbstractQuantumWire*> outputs = {});
|
||||
|
||||
virtual ~NInMOutQuantumGate() = default;
|
||||
|
||||
std::size_t getNumInputs() const override;
|
||||
size_t getNumInputs() const override;
|
||||
|
||||
std::size_t getNumOutputs() const override;
|
||||
size_t getNumOutputs() const override;
|
||||
|
||||
AbstractQuantumWire* getInput(std::size_t idx) const override;
|
||||
AbstractQuantumWire* getInput(size_t idx) const override;
|
||||
|
||||
AbstractQuantumWire* getOutput(std::size_t idx) const override;
|
||||
AbstractQuantumWire* getOutput(size_t idx) const override;
|
||||
|
||||
void setAtInput(std::size_t idx, AbstractQuantumWire* value) override;
|
||||
void setAtInput(size_t idx, AbstractQuantumWire* value) override;
|
||||
|
||||
void setAtOutput(std::size_t idx, AbstractQuantumWire* value) override;
|
||||
void setAtOutput(size_t idx, AbstractQuantumWire* value) override;
|
||||
|
||||
bool isFullyConnected() const override
|
||||
{
|
||||
|
@ -82,8 +82,8 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
std::size_t mNumIn{ 1 };
|
||||
std::size_t mNumOut{ 1 };
|
||||
size_t mNumIn{ 1 };
|
||||
size_t mNumOut{ 1 };
|
||||
|
||||
Vector<AbstractQuantumWire*> mInputs;
|
||||
Vector<AbstractQuantumWire*> mOutputs;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "Qubit.h"
|
||||
|
||||
#include "String.h"
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class QuantumWire;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "AbstractVisualNode.h"
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class BlochSphere;
|
||||
class CircleNode;
|
||||
|
|
|
@ -45,12 +45,12 @@ void QuantumCircuitNode::buildWireConnections()
|
|||
|
||||
for (auto gate : mContent->getLogicGates())
|
||||
{
|
||||
for (std::size_t idx = 0; idx < gate->getNumInputs(); idx++)
|
||||
for (size_t idx = 0; idx < gate->getNumInputs(); idx++)
|
||||
{
|
||||
mWireInputConnections[gate->getInput(idx)] = gate;
|
||||
}
|
||||
|
||||
for (std::size_t idx = 0; idx < gate->getNumOutputs(); idx++)
|
||||
for (size_t idx = 0; idx < gate->getNumOutputs(); idx++)
|
||||
{
|
||||
mWireOutputConnections[gate->getOutput(idx)] = gate;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "AbstractVisualNode.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include Map.h
|
||||
|
||||
class QuantumCircuit;
|
||||
class QuantumCircuitElement;
|
||||
|
@ -34,8 +34,8 @@ private:
|
|||
Vector<Ptr<QuantumGateNode> > mGateNodes;
|
||||
Vector<Ptr<QuantumWireNode> > mWireNodes;
|
||||
|
||||
std::unordered_map<AbstractQuantumWire*, QuantumCircuitElement*> mWireInputConnections;
|
||||
std::unordered_map<AbstractQuantumWire*, QuantumCircuitElement*> mWireOutputConnections;
|
||||
Map<AbstractQuantumWire*, QuantumCircuitElement*> mWireInputConnections;
|
||||
Map<AbstractQuantumWire*, QuantumCircuitElement*> mWireOutputConnections;
|
||||
|
||||
std::unordered_map<QuantumCircuitElement*, QuantumCircuitElementNode*> mNodesForContent;
|
||||
Map<QuantumCircuitElement*, QuantumCircuitElementNode*> mNodesForContent;
|
||||
};
|
|
@ -75,9 +75,9 @@ void QuantumGateNode::createOrUpdateGeometry(SceneInfo*)
|
|||
Point2 QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
|
||||
{
|
||||
bool is_input{ false };
|
||||
//std::size_t connection_id{ 0 };
|
||||
//size_t connection_id{ 0 };
|
||||
|
||||
for (std::size_t idx = 0; idx < mContent->getNumInputs(); idx++)
|
||||
for (size_t idx = 0; idx < mContent->getNumInputs(); idx++)
|
||||
{
|
||||
if (mContent->getInput(idx) == wire)
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ Point2 QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
|
|||
}
|
||||
}
|
||||
|
||||
for (std::size_t idx = 0; idx < mContent->getNumOutputs(); idx++)
|
||||
for (size_t idx = 0; idx < mContent->getNumOutputs(); idx++)
|
||||
{
|
||||
if (mContent->getOutput(idx) == wire)
|
||||
{
|
||||
|
|
|
@ -73,7 +73,7 @@ void TemplateFile::onTextSpanFinished()
|
|||
mWorkingLineContent.clear();
|
||||
}
|
||||
|
||||
std::size_t TemplateFile::checkForStatement(const String& lineSection)
|
||||
size_t TemplateFile::checkForStatement(const String& lineSection)
|
||||
{
|
||||
if (lineSection.empty())
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ std::size_t TemplateFile::checkForStatement(const String& lineSection)
|
|||
}
|
||||
|
||||
Vector<String> hits;
|
||||
std::size_t hit_size{0};
|
||||
size_t hit_size{0};
|
||||
if (Lexer::matchPattern("{%@%}", lineSection, '@', hits))
|
||||
{
|
||||
if (hits.size() == 1)
|
||||
|
@ -97,7 +97,7 @@ std::size_t TemplateFile::checkForStatement(const String& lineSection)
|
|||
return hit_size;
|
||||
}
|
||||
|
||||
std::size_t TemplateFile::checkForExpression(const String& lineSection)
|
||||
size_t TemplateFile::checkForExpression(const String& lineSection)
|
||||
{
|
||||
if (lineSection.empty())
|
||||
{
|
||||
|
@ -105,7 +105,7 @@ std::size_t TemplateFile::checkForExpression(const String& lineSection)
|
|||
}
|
||||
|
||||
Vector<String> hits;
|
||||
std::size_t hit_size{0};
|
||||
size_t hit_size{0};
|
||||
if (Lexer::matchPattern("{{@}}", lineSection, '@', hits))
|
||||
{
|
||||
if (hits.size() == 1)
|
||||
|
@ -123,7 +123,7 @@ std::size_t TemplateFile::checkForExpression(const String& lineSection)
|
|||
|
||||
void TemplateFile::processLine(const String& line)
|
||||
{
|
||||
std::size_t line_position = 0;
|
||||
size_t line_position = 0;
|
||||
mWorkingLineContent.clear();
|
||||
while(line_position < line.size())
|
||||
{
|
||||
|
|
|
@ -27,9 +27,9 @@ public:
|
|||
void loadContent();
|
||||
|
||||
private:
|
||||
std::size_t checkForStatement(const String& lineSection);
|
||||
size_t checkForStatement(const String& lineSection);
|
||||
|
||||
std::size_t checkForExpression(const String& lineSection);
|
||||
size_t checkForExpression(const String& lineSection);
|
||||
|
||||
void onTextSpanFinished();
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ void TemplateNode::addChild(Ptr<TemplateNode> child)
|
|||
mChildren.push_back(std::move(child));
|
||||
}
|
||||
|
||||
std::size_t TemplateNode::getNumChildren() const
|
||||
size_t TemplateNode::getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ String TemplateNode::getIdentifier() const
|
|||
return {};
|
||||
}
|
||||
|
||||
TemplateNode* TemplateNode::getChild(std::size_t index) const
|
||||
TemplateNode* TemplateNode::getChild(size_t index) const
|
||||
{
|
||||
return mChildren[index].get();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include "String.h"
|
||||
#include "Vector.h"
|
||||
|
||||
|
@ -24,13 +24,13 @@ public:
|
|||
|
||||
virtual void addChild(Ptr<TemplateNode> child);
|
||||
|
||||
TemplateNode* getChild(std::size_t index) const;
|
||||
TemplateNode* getChild(size_t index) const;
|
||||
|
||||
TemplateNode* getFirstChildShallow(Type type, const String& identifier = {}) const;
|
||||
|
||||
virtual String getIdentifier() const;
|
||||
|
||||
std::size_t getNumChildren() const;
|
||||
size_t getNumChildren() const;
|
||||
|
||||
TemplateNode* getParent() const;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "String.h"
|
||||
#include <unordered_map>
|
||||
#include Map.h
|
||||
|
||||
class TemplateSubstitutionContext
|
||||
{
|
||||
|
@ -31,5 +31,5 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<String, String> mSubstitutions;
|
||||
Map<String, String> mSubstitutions;
|
||||
};
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
#include "Vector.h"
|
||||
#include "String.h"
|
||||
#include "Memory.h"
|
||||
#include <unordered_map>
|
||||
#include "Pointer.h"
|
||||
#include Map.h
|
||||
|
||||
class TemplateSubstitutionContext;
|
||||
|
||||
|
@ -24,7 +24,7 @@ private:
|
|||
void loadTemplateFiles();
|
||||
void processTemplate(TemplateFile* file, TemplateNode* parent = nullptr);
|
||||
|
||||
std::unordered_map<String, Ptr<TemplateFile> > mTemplateFiles;
|
||||
Map<String, Ptr<TemplateFile> > mTemplateFiles;
|
||||
Path mWorkingDirectory;
|
||||
String mTemplateExtension{ ".html" };
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ void CyclicRedundancyChecker::createTable()
|
|||
{
|
||||
mTable = Vector<unsigned long>(TABLE_SIZE, 0);
|
||||
unsigned long c{0};
|
||||
for (std::size_t n = 0; n < TABLE_SIZE; n++)
|
||||
for (size_t n = 0; n < TABLE_SIZE; n++)
|
||||
{
|
||||
c = (unsigned long) n;
|
||||
for (int k = 0; k < 8; k++)
|
||||
|
|
|
@ -19,6 +19,6 @@ private:
|
|||
|
||||
uint32_t mLastValue{0xffffffffL};
|
||||
|
||||
static const std::size_t TABLE_SIZE{ 256 };
|
||||
static const size_t TABLE_SIZE{ 256 };
|
||||
Vector<unsigned long> mTable;
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "String.h"
|
||||
#include "Vector.h"
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include <tuple>
|
||||
|
||||
class PrefixCodeGenerator;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "DeflateElements.h"
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include "Vector.h"
|
||||
|
||||
class AbstractChecksumCalculator;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include "BitStream.h"
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class AbstractChecksumCalculator;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "DeflateElements.h"
|
||||
|
||||
#include "Vector.h"
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class DeflateBlock;
|
||||
|
||||
|
|
|
@ -25,15 +25,15 @@ void HuffmanCodeLengthTable::buildCompressedLengthSequence()
|
|||
const auto count = entry.second;
|
||||
if (count < 3)
|
||||
{
|
||||
for(std::size_t idx=0; idx<count; idx++)
|
||||
for(size_t idx=0; idx<count; idx++)
|
||||
{
|
||||
mCompressedLengthSequence.push_back({length, 0});
|
||||
}
|
||||
}
|
||||
else if (length == 0)
|
||||
{
|
||||
std::size_t num_big = count / 138;
|
||||
for(std::size_t idx=0; idx<num_big; idx++)
|
||||
size_t num_big = count / 138;
|
||||
for(size_t idx=0; idx<num_big; idx++)
|
||||
{
|
||||
mCompressedLengthSequence.push_back({18, 127});
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ void HuffmanCodeLengthTable::buildCompressedLengthSequence()
|
|||
}
|
||||
else
|
||||
{
|
||||
for(std::size_t idx=0; idx<remainder_big; idx++)
|
||||
for(size_t idx=0; idx<remainder_big; idx++)
|
||||
{
|
||||
mCompressedLengthSequence.push_back({0, 0});
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ void HuffmanCodeLengthTable::buildCompressedLengthSequence()
|
|||
{
|
||||
mCompressedLengthSequence.push_back({length, 0});
|
||||
auto num_blocks_of_six = (count-1)/6;
|
||||
for(std::size_t idx=0; idx<num_blocks_of_six; idx++)
|
||||
for(size_t idx=0; idx<num_blocks_of_six; idx++)
|
||||
{
|
||||
mCompressedLengthSequence.push_back({16, 3});
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ void HuffmanCodeLengthTable::buildCompressedLengthSequence()
|
|||
}
|
||||
else
|
||||
{
|
||||
for(std::size_t idx=0; idx<remaining_counts; idx++)
|
||||
for(size_t idx=0; idx<remaining_counts; idx++)
|
||||
{
|
||||
mCompressedLengthSequence.push_back({length, 0});
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ void HuffmanCodeLengthTable::buildCompressedLengthSequence()
|
|||
}
|
||||
}
|
||||
|
||||
mCompressedLengthCounts = Vector<std::size_t>(19, 0);
|
||||
mCompressedLengthCounts = Vector<size_t>(19, 0);
|
||||
for (const auto& entry : mCompressedLengthSequence)
|
||||
{
|
||||
mCompressedLengthCounts[entry.first]++;
|
||||
|
@ -89,7 +89,7 @@ const Vector<HuffmanCodeLengthTable::CompressedSequenceEntry>& HuffmanCodeLength
|
|||
return mCompressedLengthSequence;
|
||||
}
|
||||
|
||||
const Vector<std::size_t> HuffmanCodeLengthTable::getCompressedLengthCounts() const
|
||||
const Vector<size_t> HuffmanCodeLengthTable::getCompressedLengthCounts() const
|
||||
{
|
||||
return mCompressedLengthCounts;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ bool HuffmanCodeLengthTable::readNextSymbol(unsigned& result, BitStream* stream)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::size_t working_index{0};
|
||||
size_t working_index{0};
|
||||
auto length = getCodeLength(working_index);
|
||||
auto delta = length;
|
||||
|
||||
|
@ -181,7 +181,7 @@ void HuffmanCodeLengthTable::buildPrefixCodes()
|
|||
next_code[bits] = code;
|
||||
}
|
||||
|
||||
for(std::size_t idx=0; idx<mInputLengthSequence.size(); idx++)
|
||||
for(size_t idx=0; idx<mInputLengthSequence.size(); idx++)
|
||||
{
|
||||
if (const auto length = mInputLengthSequence[idx]; length != 0)
|
||||
{
|
||||
|
@ -196,7 +196,7 @@ void HuffmanCodeLengthTable::buildPrefixCodes()
|
|||
//std::cout << dumpPrefixCodes();
|
||||
}
|
||||
|
||||
const PrefixCode& HuffmanCodeLengthTable::getCode(std::size_t index) const
|
||||
const PrefixCode& HuffmanCodeLengthTable::getCode(size_t index) const
|
||||
{
|
||||
return mCodes[index];
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ String HuffmanCodeLengthTable::dumpPrefixCodes() const
|
|||
return mTree.dump();
|
||||
}
|
||||
|
||||
std::size_t HuffmanCodeLengthTable::mapToDeflateIndex(std::size_t index) const
|
||||
size_t HuffmanCodeLengthTable::mapToDeflateIndex(size_t index) const
|
||||
{
|
||||
if (index>= DEFLATE_PERMUTATION_SIZE)
|
||||
{
|
||||
|
@ -218,17 +218,17 @@ std::size_t HuffmanCodeLengthTable::mapToDeflateIndex(std::size_t index) const
|
|||
}
|
||||
}
|
||||
|
||||
std::size_t HuffmanCodeLengthTable::getNumCodeLengths() const
|
||||
size_t HuffmanCodeLengthTable::getNumCodeLengths() const
|
||||
{
|
||||
return mTree.getNumCodeLengths();
|
||||
}
|
||||
|
||||
std::optional<HuffmanTree::Symbol> HuffmanCodeLengthTable::findMatch(std::size_t treeIndex, uint32_t code) const
|
||||
std::optional<HuffmanTree::Symbol> HuffmanCodeLengthTable::findMatch(size_t treeIndex, uint32_t code) const
|
||||
{
|
||||
return mTree.findMatch(treeIndex, code);
|
||||
}
|
||||
|
||||
unsigned HuffmanCodeLengthTable::getCodeLength(std::size_t index) const
|
||||
unsigned HuffmanCodeLengthTable::getCodeLength(size_t index) const
|
||||
{
|
||||
return mTree.getCodeLength(index);
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ void HuffmanCodeLengthTable::setInputLengthSequence(const Vector<unsigned char>&
|
|||
if (targetDeflate)
|
||||
{
|
||||
mInputLengthSequence = Vector<unsigned char>(DEFLATE_PERMUTATION_SIZE, 0);
|
||||
for(std::size_t idx=0; idx<sequence.size(); idx++)
|
||||
for(size_t idx=0; idx<sequence.size(); idx++)
|
||||
{
|
||||
mInputLengthSequence[mapToDeflateIndex(idx)] = sequence[idx];
|
||||
//std::cout << "Got code length for " << mapToDeflateIndex(idx) << " of " << static_cast<unsigned>(sequence[idx]) << std::endl;
|
||||
|
|
|
@ -17,24 +17,24 @@ public:
|
|||
|
||||
String dumpPrefixCodes() const;
|
||||
|
||||
std::optional<HuffmanTree::Symbol> findMatch(std::size_t treeIndex, uint32_t code) const;
|
||||
std::optional<HuffmanTree::Symbol> findMatch(size_t treeIndex, uint32_t code) const;
|
||||
|
||||
const HuffmanTree& getTree() const;
|
||||
|
||||
const PrefixCode& getCode(std::size_t index) const;
|
||||
const PrefixCode& getCode(size_t index) const;
|
||||
|
||||
std::optional<PrefixCode> getCodeForSymbol(unsigned symbol) const;
|
||||
|
||||
using CompressedSequenceEntry = std::pair<unsigned, unsigned>;
|
||||
const Vector<CompressedSequenceEntry>& getCompressedLengthSequence() const;
|
||||
|
||||
const Vector<std::size_t> getCompressedLengthCounts() const;
|
||||
const Vector<size_t> getCompressedLengthCounts() const;
|
||||
|
||||
std::size_t getNumCodeLengths() const;
|
||||
size_t getNumCodeLengths() const;
|
||||
|
||||
unsigned getCodeLength(std::size_t treeIndex) const;
|
||||
unsigned getCodeLength(size_t treeIndex) const;
|
||||
|
||||
std::size_t mapToDeflateIndex(std::size_t index) const;
|
||||
size_t mapToDeflateIndex(size_t index) const;
|
||||
|
||||
void setInputLengthSequence(const Vector<unsigned char>& sequence, bool targetDeflate = true);
|
||||
|
||||
|
@ -49,7 +49,7 @@ private:
|
|||
Vector<PrefixCode> mCodes;
|
||||
|
||||
Vector<CompressedSequenceEntry> mCompressedLengthSequence;
|
||||
Vector<std::size_t> mCompressedLengthCounts;
|
||||
Vector<size_t> mCompressedLengthCounts;
|
||||
|
||||
static constexpr unsigned DEFLATE_PERMUTATION_SIZE{19};
|
||||
static constexpr unsigned DEFLATE_PERMUTATION[DEFLATE_PERMUTATION_SIZE]{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "HuffmanFixedCodes.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include Map.h
|
||||
#include <queue>
|
||||
#include <tuple>
|
||||
#include <iostream>
|
||||
|
@ -90,7 +90,7 @@ void HuffmanEncoder::encode(const Vector<unsigned>& counts)
|
|||
//std::cout << "********" << std::endl;
|
||||
}
|
||||
|
||||
void HuffmanEncoder::encode(const std::unordered_map<unsigned char, unsigned>& counts)
|
||||
void HuffmanEncoder::encode(const Map<unsigned char, unsigned>& counts)
|
||||
{
|
||||
Vector<unsigned> just_counts;
|
||||
for (const auto& data: counts)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "Vector.h"
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include Map.h
|
||||
|
||||
class PrefixCodeGenerator
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ class HuffmanEncoder : public PrefixCodeGenerator
|
|||
|
||||
public:
|
||||
void encode(const Vector<unsigned>& counts);
|
||||
void encode(const std::unordered_map<unsigned char, unsigned>& counts);
|
||||
void encode(const Map<unsigned char, unsigned>& counts);
|
||||
|
||||
uint32_t getLengthValue(unsigned length);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
#include Map.h
|
||||
#include <sstream>
|
||||
|
||||
Vector<unsigned> DISTANCE_OFFSETS
|
||||
|
@ -172,7 +172,7 @@ void HuffmanStream::readCodeLengths()
|
|||
|
||||
void HuffmanStream::copyFromBuffer(unsigned length, unsigned distance)
|
||||
{
|
||||
std::size_t offset = mBuffer.size() - 1 - distance;
|
||||
size_t offset = mBuffer.size() - 1 - distance;
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
{
|
||||
auto symbol = mBuffer[offset + idx];
|
||||
|
|
|
@ -67,7 +67,7 @@ void HuffmanTree::sortTable()
|
|||
std::sort(mTable.begin(), mTable.end(), [](CodeLengthData a, CodeLengthData b){return a.first < b.first;});
|
||||
}
|
||||
|
||||
std::optional<HuffmanTree::Symbol> HuffmanTree::findMatch(std::size_t treeIndex, uint32_t code) const
|
||||
std::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)
|
||||
|
@ -96,12 +96,12 @@ std::optional<PrefixCode> HuffmanTree::getCode(Symbol symbol) const
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::size_t HuffmanTree::getNumCodeLengths() const
|
||||
size_t HuffmanTree::getNumCodeLengths() const
|
||||
{
|
||||
return mTable.size();
|
||||
}
|
||||
|
||||
unsigned HuffmanTree::getCodeLength(std::size_t idx) const
|
||||
unsigned HuffmanTree::getCodeLength(size_t idx) const
|
||||
{
|
||||
return mTable[idx].first;
|
||||
}
|
||||
|
|
|
@ -41,11 +41,11 @@ public:
|
|||
|
||||
String dump(bool bitsAsRightToLeft = true) const;
|
||||
|
||||
std::optional<HuffmanTree::Symbol> findMatch(std::size_t treeIndex, uint32_t code) const;
|
||||
std::optional<HuffmanTree::Symbol> findMatch(size_t treeIndex, uint32_t code) const;
|
||||
|
||||
std::size_t getNumCodeLengths() const;
|
||||
size_t getNumCodeLengths() const;
|
||||
|
||||
unsigned getCodeLength(std::size_t idx) const;
|
||||
unsigned getCodeLength(size_t idx) const;
|
||||
|
||||
std::optional<PrefixCode> getCode(Symbol symbol) const;
|
||||
|
||||
|
|
|
@ -34,17 +34,17 @@ Ptr<Color> Color::Create(unsigned char r, unsigned char g, unsigned char b, doub
|
|||
return std::make_unique<Color>(r, g, b, a);
|
||||
}
|
||||
|
||||
std::size_t Color::getSize() const
|
||||
size_t Color::getSize() const
|
||||
{
|
||||
return getSize(mFormat, mBitDepth);
|
||||
}
|
||||
|
||||
std::size_t Color::getSize(Format format, unsigned bitDepth)
|
||||
size_t Color::getSize(Format format, unsigned bitDepth)
|
||||
{
|
||||
return getNumChannels(format) * bitDepth / 8;
|
||||
}
|
||||
|
||||
std::size_t Color::getNumChannels(Format format)
|
||||
size_t Color::getNumChannels(Format format)
|
||||
{
|
||||
if (format == Format::GRAYSCALE || format == Format::LUT)
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ std::size_t Color::getNumChannels(Format format)
|
|||
}
|
||||
}
|
||||
|
||||
uint8_t Color::getByte(std::size_t index) const
|
||||
uint8_t Color::getByte(size_t index) const
|
||||
{
|
||||
if (mFormat == Format::GRAYSCALE || mFormat == Format::LUT)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include "Vector.h"
|
||||
#include "String.h"
|
||||
#include <stdexcept>
|
||||
|
@ -35,13 +35,13 @@ public:
|
|||
|
||||
String toString() const;
|
||||
|
||||
std::size_t getSize() const;
|
||||
size_t getSize() const;
|
||||
|
||||
static std::size_t getNumChannels(Format format);
|
||||
static size_t getNumChannels(Format format);
|
||||
|
||||
static std::size_t getSize(Format format, unsigned bitDepth);
|
||||
static size_t getSize(Format format, unsigned bitDepth);
|
||||
|
||||
uint8_t getByte(std::size_t index) const;
|
||||
uint8_t getByte(size_t index) const;
|
||||
|
||||
void setAlpha(float alpha);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "Index.h"
|
||||
|
||||
Index::Index(std::size_t value)
|
||||
Index::Index(size_t value)
|
||||
: m_value(value),
|
||||
m_valid(true)
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ bool Index::valid() const
|
|||
return m_valid;
|
||||
}
|
||||
|
||||
std::size_t Index::value() const
|
||||
size_t Index::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
|
@ -7,13 +7,13 @@ class Index
|
|||
public:
|
||||
Index() = default;
|
||||
|
||||
Index(std::size_t value);
|
||||
Index(size_t value);
|
||||
|
||||
bool valid() const;
|
||||
|
||||
std::size_t value() const;
|
||||
size_t value() const;
|
||||
|
||||
private:
|
||||
std::size_t m_value{0};
|
||||
size_t m_value{0};
|
||||
bool m_valid{false};
|
||||
};
|
|
@ -6,7 +6,7 @@ template<typename T>
|
|||
class CircleBuffer
|
||||
{
|
||||
public:
|
||||
CircleBuffer(std::size_t size)
|
||||
CircleBuffer(size_t size)
|
||||
: mData(size)
|
||||
{
|
||||
|
||||
|
@ -33,12 +33,12 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
std::size_t getNumItems() const
|
||||
size_t getNumItems() const
|
||||
{
|
||||
return mEndPointer;
|
||||
}
|
||||
|
||||
const T& getItem(std::size_t index) const
|
||||
const T& getItem(size_t index) const
|
||||
{
|
||||
if (mEndPointer < mData.size())
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
std::size_t mStartPointer{0};
|
||||
std::size_t mEndPointer{0};
|
||||
size_t mStartPointer{0};
|
||||
size_t mEndPointer{0};
|
||||
Vector<T> mData;
|
||||
};
|
||||
|
|
|
@ -7,12 +7,12 @@ bool Dictionary::hasKey(const String& key) const
|
|||
|
||||
bool Dictionary::hasStringKey(const String& key) const
|
||||
{
|
||||
return mStringData.count(key) > 0;
|
||||
return mStringData.has_key(key);
|
||||
}
|
||||
|
||||
bool Dictionary::hasDictKey(const String& key) const
|
||||
{
|
||||
return mDictData.count(key) > 0;
|
||||
return mDictData.has_key(key);
|
||||
}
|
||||
|
||||
Vector<String> Dictionary::getStringKeys() const
|
||||
|
@ -20,7 +20,7 @@ Vector<String> Dictionary::getStringKeys() const
|
|||
Vector<String> keys;
|
||||
for (const auto& item : mStringData)
|
||||
{
|
||||
keys.push_back(item.first);
|
||||
keys.push_back(item.key());
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
@ -30,27 +30,28 @@ Vector<String> Dictionary::getDictKeys() const
|
|||
Vector<String> keys;
|
||||
for (const auto& item : mDictData)
|
||||
{
|
||||
keys.push_back(item.first);
|
||||
keys.push_back(item.key());
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
Dictionary* Dictionary::getDict(const String& key) const
|
||||
{
|
||||
return mDictData.at(key).get();
|
||||
//return (*mDictData.find(key)).value().get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
String Dictionary::getItem(const String& key) const
|
||||
{
|
||||
return mStringData.at(key);
|
||||
return (*mStringData.find(key)).value();
|
||||
}
|
||||
|
||||
void Dictionary::addStringItem(const String& key, const String& item)
|
||||
{
|
||||
mStringData[key] = item;
|
||||
mStringData.insert(key, item);
|
||||
}
|
||||
|
||||
void Dictionary::addDictItem(const String& key, Ptr<Dictionary> dict)
|
||||
{
|
||||
mDictData[key] = std::move(dict);
|
||||
mDictData.insert(key, std::move(dict));
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
#include "String.h"
|
||||
#include "Vector.h"
|
||||
#include <map>
|
||||
#include "Memory.h"
|
||||
#include "Map.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class Dictionary
|
||||
{
|
||||
|
@ -27,8 +27,8 @@ public:
|
|||
bool hasStringKey(const String& key) const;
|
||||
|
||||
bool hasDictKey(const String& key) const;
|
||||
protected:
|
||||
|
||||
std::map<String, String> mStringData;
|
||||
std::map<String, Ptr<Dictionary> > mDictData;
|
||||
protected:
|
||||
Map<String, String> mStringData;
|
||||
Map<String, Ptr<Dictionary> > mDictData;
|
||||
};
|
||||
|
|
|
@ -1,68 +1,195 @@
|
|||
#pragma once
|
||||
|
||||
#include "Error.h"
|
||||
#include "Pointer.h"
|
||||
#include "Vector.h"
|
||||
#include "Optional.h"
|
||||
|
||||
class AbstractList
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractList() = default;
|
||||
|
||||
virtual std::size_t getLength() const = 0;
|
||||
};
|
||||
#include <functional>
|
||||
|
||||
template<typename T>
|
||||
class List : public AbstractList
|
||||
class List
|
||||
{
|
||||
public:
|
||||
List() = default;
|
||||
|
||||
void initializeTo(std::size_t size, T value)
|
||||
List(const T& item)
|
||||
: m_item(item)
|
||||
{
|
||||
mData = Vector<T>(size, value);
|
||||
}
|
||||
|
||||
const T* getDataPtr() const
|
||||
List(T&& item)
|
||||
: m_item(std::move(item))
|
||||
{
|
||||
return mData.data();
|
||||
}
|
||||
|
||||
const Vector<T>& getData() const
|
||||
List* next()
|
||||
{
|
||||
return mData;
|
||||
return m_next.get();
|
||||
}
|
||||
|
||||
T getItem(std::size_t index) const
|
||||
const List* next() const
|
||||
{
|
||||
if (index < mData.size())
|
||||
return m_next.get();
|
||||
}
|
||||
|
||||
const List* end() const
|
||||
{
|
||||
if (is_end())
|
||||
{
|
||||
return mData[index];
|
||||
return this;
|
||||
}
|
||||
else
|
||||
auto next_entry = next();
|
||||
while(next_entry)
|
||||
{
|
||||
const auto msg = "Tried to access out of range index: " + std::to_string(index) + " with size " + std::to_string(mData.size());
|
||||
throw std::out_of_range(msg);
|
||||
if(!next_entry->is_end())
|
||||
{
|
||||
next_entry = next_entry->next();
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return next_entry;
|
||||
}
|
||||
|
||||
using onItemFunc = std::function<bool(const T& item)>;
|
||||
void forEach(onItemFunc item_func) const
|
||||
{
|
||||
if (is_end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto next_entry = next();
|
||||
while(next_entry)
|
||||
{
|
||||
if (!item_func(next_entry->item()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
next_entry = next_entry->next();
|
||||
}
|
||||
}
|
||||
|
||||
void setData(const Vector<T>& data)
|
||||
List* end()
|
||||
{
|
||||
mData = data;
|
||||
}
|
||||
|
||||
void setItem(std::size_t index, T item)
|
||||
{
|
||||
if (index < mData.size())
|
||||
if (is_end())
|
||||
{
|
||||
mData[index] = item;
|
||||
return this;
|
||||
}
|
||||
auto next_entry = next();
|
||||
while(next_entry)
|
||||
{
|
||||
if(!next_entry->is_end())
|
||||
{
|
||||
next_entry = next_entry->next();
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return next_entry;
|
||||
}
|
||||
|
||||
std::size_t getLength() const override
|
||||
const List* find(const T& item) const
|
||||
{
|
||||
return mData.size();
|
||||
if (m_item == item)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
auto next_entry = next();
|
||||
while(next_entry)
|
||||
{
|
||||
if (next_entry->m_item == item)
|
||||
{
|
||||
return next_entry;
|
||||
}
|
||||
next_entry = next_entry->next();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Optional<size_t> find_index(const T& item) const
|
||||
{
|
||||
if (item == m_item)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
auto next_entry = next();
|
||||
size_t count = 1;
|
||||
while(next_entry)
|
||||
{
|
||||
if (next_entry->m_item == item)
|
||||
{
|
||||
return {count};
|
||||
}
|
||||
next_entry = next_entry->next();
|
||||
count++;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
auto next_entry = next();
|
||||
size_t count = 1;
|
||||
while(next_entry)
|
||||
{
|
||||
next_entry = next_entry->next();
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void insert(const T& item)
|
||||
{
|
||||
auto end_entry = end();
|
||||
end_entry->set_next(Ptr<List>::create(item));
|
||||
}
|
||||
|
||||
void insert(T&& item)
|
||||
{
|
||||
auto end_entry = end();
|
||||
end_entry->set_next(Ptr<List>::create(std::move(item)));
|
||||
}
|
||||
|
||||
const T& item() const
|
||||
{
|
||||
return m_item;
|
||||
}
|
||||
|
||||
T& item()
|
||||
{
|
||||
return m_item;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return is_end();
|
||||
}
|
||||
|
||||
bool is_end() const
|
||||
{
|
||||
return !bool(m_next);
|
||||
}
|
||||
|
||||
void flatten(Vector<T>& items) const
|
||||
{
|
||||
items.push_back(m_item);
|
||||
auto next_entry = next();
|
||||
while(next_entry)
|
||||
{
|
||||
items.push_back(next_entry->item());
|
||||
next_entry = next_entry->next();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Vector<T> mData;
|
||||
void set_next(Ptr<List> entry)
|
||||
{
|
||||
m_next = std::move(entry);
|
||||
}
|
||||
|
||||
T m_item;
|
||||
Ptr<List> m_next;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,363 @@
|
|||
#pragma once
|
||||
|
||||
template<typename T, typename U>
|
||||
#include "String.h"
|
||||
#include "List.h"
|
||||
#include "Pair.h"
|
||||
#include "Optional.h"
|
||||
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
|
||||
template<typename K, typename T>
|
||||
class Map{
|
||||
|
||||
public:
|
||||
struct KvPair
|
||||
{
|
||||
KvPair() = default;
|
||||
|
||||
KvPair(const K& key)
|
||||
:m_key(key)
|
||||
{
|
||||
}
|
||||
|
||||
KvPair(const K& key, const T& value)
|
||||
: m_key(key),
|
||||
m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
KvPair(const K& key, T&& value)
|
||||
: m_key(key),
|
||||
m_value(std::move(value))
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const KvPair& other) const
|
||||
{
|
||||
return m_key == other.m_key;
|
||||
}
|
||||
|
||||
const K& key() const
|
||||
{
|
||||
return m_key;
|
||||
}
|
||||
|
||||
const T& value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
T& value()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
K m_key;
|
||||
T m_value;
|
||||
};
|
||||
|
||||
Map() = default;
|
||||
|
||||
void insert(const K& key, const T& value)
|
||||
{
|
||||
auto& map_entry = m_buffer[(hash(key))];
|
||||
if (!map_entry.is_set())
|
||||
{
|
||||
map_entry.init(KvPair(key, value));
|
||||
}
|
||||
else
|
||||
{
|
||||
map_entry.m_list->insert(KvPair(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
void insert(const K& key, T&& value)
|
||||
{
|
||||
auto& map_entry = m_buffer[(hash(key))];
|
||||
if (!map_entry.is_set())
|
||||
{
|
||||
map_entry.init(std::move(KvPair(key, std::move(value))));
|
||||
}
|
||||
else
|
||||
{
|
||||
map_entry.m_list->insert(std::move(KvPair(key, std::move(value))));
|
||||
}
|
||||
}
|
||||
|
||||
using onItemFunc = std::function<bool(const T& key, const T& value)>;
|
||||
void forEach(onItemFunc item_func)
|
||||
{
|
||||
for(size_t idx=0; idx<BUFFER_SIZE;idx++)
|
||||
{
|
||||
const auto& map_entry = m_buffer[idx];
|
||||
auto list_func = [key=map_entry.key(), item_func](const T& item)
|
||||
{
|
||||
return item_func(key, item);
|
||||
};
|
||||
map_entry.forEach(list_func);
|
||||
}
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
for(size_t idx=0; idx<BUFFER_SIZE;idx++)
|
||||
{
|
||||
m_buffer[idx].clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
for(size_t idx=0; idx<BUFFER_SIZE; idx++)
|
||||
{
|
||||
if (m_buffer[idx].is_set())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const Optional<T>& value(const K& key) const
|
||||
{
|
||||
const auto& map_entry = m_buffer[(hash(key))];
|
||||
if (!map_entry.is_set())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
KvPair search_term(key);
|
||||
if (auto list_item = map_entry.find(search_term); list_item != nullptr)
|
||||
{
|
||||
return list_item->value();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool has_key(const K& key) const
|
||||
{
|
||||
const auto& map_entry = m_buffer[(hash(key))];
|
||||
if (!map_entry.is_set())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
KvPair search_term(key);
|
||||
if (auto list_item = map_entry.m_list->find(search_term); list_item != nullptr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector<KvPair> items() const
|
||||
{
|
||||
Vector<KvPair> ret;
|
||||
for(size_t idx=0; idx<BUFFER_SIZE;idx++)
|
||||
{
|
||||
const auto& map_entry = m_buffer[idx];
|
||||
if (map_entry.is_set())
|
||||
{
|
||||
map_entry.m_list->flatten(ret);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
class MapIter
|
||||
{
|
||||
public:
|
||||
MapIter(const Map* container, int index = -1)
|
||||
: m_index(index), m_container(container)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator!=(const MapIter& other) const
|
||||
{
|
||||
return m_index != other.m_index;
|
||||
}
|
||||
|
||||
const KvPair& operator*() const
|
||||
{
|
||||
bool found{false};
|
||||
return m_container->get_item(m_index, found);
|
||||
}
|
||||
|
||||
void operator++()
|
||||
{
|
||||
m_index++;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_index{-1};
|
||||
const Map* m_container{nullptr};
|
||||
};
|
||||
|
||||
MapIter begin() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
return MapIter(this, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return MapIter(this, 0);
|
||||
}
|
||||
}
|
||||
|
||||
MapIter end() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
return MapIter(this, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return MapIter(this, size());
|
||||
}
|
||||
}
|
||||
|
||||
MapIter find(const K& key) const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
return MapIter(this, -1);
|
||||
}
|
||||
size_t count{0};
|
||||
for(size_t idx=0; idx<BUFFER_SIZE; idx++)
|
||||
{
|
||||
const auto& map_entry = m_buffer[idx];
|
||||
if (map_entry.is_set())
|
||||
{
|
||||
const auto loc_index = map_entry.m_list->find_index(key);
|
||||
if (loc_index.is_set())
|
||||
{
|
||||
return MapIter(this, count + loc_index.value());
|
||||
}
|
||||
else
|
||||
{
|
||||
count += map_entry.m_list->size();
|
||||
}
|
||||
}
|
||||
}
|
||||
return MapIter(this, -1);
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
size_t count{0};
|
||||
for(size_t kdx=0; kdx<BUFFER_SIZE; kdx++)
|
||||
{
|
||||
const auto& map_entry = m_buffer[kdx];
|
||||
if (map_entry.is_set())
|
||||
{
|
||||
count++;
|
||||
auto next_item = map_entry.m_list->next();
|
||||
while(next_item)
|
||||
{
|
||||
next_item = next_item->next();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
struct MapEntry
|
||||
{
|
||||
bool is_set() const
|
||||
{
|
||||
return bool(m_list);
|
||||
}
|
||||
void init(const KvPair& kv)
|
||||
{
|
||||
m_list = Ptr<List<KvPair> >::create(kv);
|
||||
}
|
||||
void init(KvPair&& kv)
|
||||
{
|
||||
m_list = Ptr<List<KvPair> >::create(std::move(kv));
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
m_list.reset();
|
||||
}
|
||||
Ptr<List<KvPair> > m_list;
|
||||
};
|
||||
|
||||
size_t hash(const K& key) const
|
||||
{
|
||||
size_t result{0};
|
||||
for(const auto c : key.data())
|
||||
{
|
||||
result += static_cast<size_t>(c);
|
||||
}
|
||||
return result / BUFFER_SIZE;
|
||||
}
|
||||
|
||||
const KvPair& get_item(size_t idx, bool& found) const
|
||||
{
|
||||
static KvPair s_bad_item;
|
||||
|
||||
size_t count{0};
|
||||
for(size_t kdx=0; kdx<BUFFER_SIZE; kdx++)
|
||||
{
|
||||
const auto& map_entry = m_buffer[kdx];
|
||||
if (map_entry.is_set())
|
||||
{
|
||||
if (idx == count)
|
||||
{
|
||||
found = true;
|
||||
return map_entry.m_list->item();
|
||||
}
|
||||
count++;
|
||||
auto next_item = map_entry.m_list->next();
|
||||
while(next_item)
|
||||
{
|
||||
if (idx == count)
|
||||
{
|
||||
found = true;
|
||||
return next_item->item();
|
||||
}
|
||||
next_item = next_item->next();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return s_bad_item;
|
||||
}
|
||||
|
||||
KvPair& get_item(size_t idx, bool& found)
|
||||
{
|
||||
static KvPair s_bad_item;
|
||||
|
||||
size_t count{0};
|
||||
for(size_t kdx=0; kdx<BUFFER_SIZE; kdx++)
|
||||
{
|
||||
auto& map_entry = m_buffer[kdx];
|
||||
if (map_entry.is_set())
|
||||
{
|
||||
if (idx == count)
|
||||
{
|
||||
found = true;
|
||||
return map_entry.m_list->item();
|
||||
}
|
||||
count++;
|
||||
auto next_item = map_entry.m_list->next();
|
||||
while(next_item)
|
||||
{
|
||||
if (idx == count)
|
||||
{
|
||||
found = true;
|
||||
return next_item->item();
|
||||
}
|
||||
next_item = next_item->next();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return s_bad_item;
|
||||
}
|
||||
|
||||
static constexpr size_t BUFFER_SIZE{5000};
|
||||
MapEntry m_buffer[BUFFER_SIZE];
|
||||
};
|
71
src/base/core/data_structures/Stack.h
Normal file
71
src/base/core/data_structures/Stack.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
#pragma once
|
||||
|
||||
#include "Pointer.h"
|
||||
#include "Optional.h"
|
||||
|
||||
template<typename T>
|
||||
class Stack
|
||||
{
|
||||
struct StackItem
|
||||
{
|
||||
StackItem(const T& value, Ptr<StackItem> prev)
|
||||
: m_value(value),
|
||||
m_previous(std::move(prev))
|
||||
{
|
||||
}
|
||||
|
||||
T m_value;
|
||||
Ptr<StackItem> m_previous;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return !bool(m_end);
|
||||
}
|
||||
|
||||
Optional<T> pop()
|
||||
{
|
||||
if (!m_end)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
auto end_tmp = m_end->m_value;
|
||||
remove_end();
|
||||
return end_tmp;
|
||||
}
|
||||
|
||||
T* top()
|
||||
{
|
||||
if (!m_end)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return &(m_end->m_value);
|
||||
}
|
||||
|
||||
void push(const T& value)
|
||||
{
|
||||
//auto new_end = Ptr<StackItem>::create(value, std::move(m_end));
|
||||
//m_end = std::move(new_end);
|
||||
}
|
||||
|
||||
private:
|
||||
void remove_end()
|
||||
{
|
||||
if (m_end)
|
||||
{
|
||||
if (m_end->m_previous)
|
||||
{
|
||||
m_end = std::move(m_end->m_previous);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_end.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ptr<StackItem> m_end;
|
||||
};
|
|
@ -8,6 +8,12 @@ String::String()
|
|||
m_data.push_back('\0');
|
||||
}
|
||||
|
||||
String::String(size_t size, char c)
|
||||
{
|
||||
m_data.resize(size, c);
|
||||
m_data.push_back('\0');
|
||||
}
|
||||
|
||||
String::String(const Vector<Byte>& data)
|
||||
{
|
||||
append(data);
|
||||
|
@ -87,6 +93,20 @@ void String::append(const char* data)
|
|||
m_data.push_back('\0');
|
||||
}
|
||||
|
||||
void String::eraseIf(erasePredicate func)
|
||||
{
|
||||
size_t count{0};
|
||||
for(size_t idx=0; idx<size(); idx++)
|
||||
{
|
||||
if (!func(m_data[idx]))
|
||||
{
|
||||
m_data[count] = m_data[idx];
|
||||
count++;
|
||||
}
|
||||
}
|
||||
m_data[count] = '\0';
|
||||
}
|
||||
|
||||
const Vector<char>& String::data() const
|
||||
{
|
||||
return m_data;
|
||||
|
@ -138,7 +158,7 @@ Pair<String, String> String::rsplit(char c) const
|
|||
return {*this, {}};
|
||||
}
|
||||
|
||||
bool String::slice(std::size_t idx, String& out) const
|
||||
bool String::slice(size_t idx, String& out) const
|
||||
{
|
||||
if (idx >= m_data.size())
|
||||
{
|
||||
|
@ -153,7 +173,7 @@ bool String::slice(std::size_t idx, String& out) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool String::slice(std::size_t start, std::size_t end, String& out) const
|
||||
bool String::slice(size_t start, size_t end, String& out) const
|
||||
{
|
||||
if (end >= m_data.size())
|
||||
{
|
||||
|
@ -174,7 +194,7 @@ Index String::rindex(char c) const
|
|||
{
|
||||
return {};
|
||||
}
|
||||
for(std::size_t idx=m_data.size()-2; idx >= 0; idx--)
|
||||
for(size_t idx=m_data.size()-2; idx >= 0; idx--)
|
||||
{
|
||||
if (m_data[idx] == c)
|
||||
{
|
||||
|
@ -189,7 +209,7 @@ const char* String::raw() const
|
|||
return m_data.data();
|
||||
}
|
||||
|
||||
std::size_t String::size() const
|
||||
size_t String::size() const
|
||||
{
|
||||
return m_data.size() - 1;
|
||||
}
|
||||
|
@ -223,7 +243,7 @@ String String::to_string(size_t input)
|
|||
return conv;
|
||||
}
|
||||
|
||||
char String::operator[](std::size_t idx) const
|
||||
char String::operator[](size_t idx) const
|
||||
{
|
||||
return m_data[idx];
|
||||
}
|
||||
|
@ -256,6 +276,16 @@ String& String::operator<<(size_t idx)
|
|||
return *this;
|
||||
}
|
||||
|
||||
void String::push_back(char c)
|
||||
{
|
||||
if (m_data.empty())
|
||||
{
|
||||
m_data.push_back('\0');
|
||||
}
|
||||
m_data.push_back('\0');
|
||||
m_data[m_data.size()-2] = c;
|
||||
}
|
||||
|
||||
String& String::operator+=(const String& str)
|
||||
{
|
||||
if (m_data.empty())
|
||||
|
@ -279,12 +309,7 @@ String String::operator+(const String& str) const
|
|||
|
||||
String& String::operator+=(char c)
|
||||
{
|
||||
if (m_data.empty())
|
||||
{
|
||||
m_data.push_back('\0');
|
||||
}
|
||||
m_data.push_back('\0');
|
||||
m_data[m_data.size()-2] = c;
|
||||
push_back(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "Index.h"
|
||||
#include "ByteTypes.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
class String
|
||||
{
|
||||
public:
|
||||
|
@ -14,6 +16,8 @@ public:
|
|||
|
||||
String(const char* data);
|
||||
|
||||
String(size_t size, char c);
|
||||
|
||||
static String fmt(const char* fmt, ...);
|
||||
|
||||
void append(const Vector<Byte>& data);
|
||||
|
@ -22,6 +26,11 @@ public:
|
|||
|
||||
bool empty() const;
|
||||
|
||||
using erasePredicate = std::function<bool(char)>;
|
||||
void eraseIf(erasePredicate func);
|
||||
|
||||
void push_back(char c);
|
||||
|
||||
const char* raw() const;
|
||||
|
||||
Pair<String, String> rsplit(char c) const;
|
||||
|
@ -30,15 +39,15 @@ public:
|
|||
|
||||
void reverse();
|
||||
|
||||
std::size_t size() const;
|
||||
size_t size() const;
|
||||
|
||||
bool slice(std::size_t idx, String& out) const;
|
||||
bool slice(size_t idx, String& out) const;
|
||||
|
||||
bool slice(std::size_t start, std::size_t end, String& out) const;
|
||||
bool slice(size_t start, size_t end, String& out) const;
|
||||
|
||||
static String to_string(size_t input);
|
||||
|
||||
char operator[](std::size_t idx) const;
|
||||
char operator[](size_t idx) const;
|
||||
|
||||
String& operator<<(const String& body);
|
||||
|
||||
|
@ -63,6 +72,59 @@ public:
|
|||
|
||||
bool operator!=(const String& other) const;
|
||||
|
||||
|
||||
class StringIter
|
||||
{
|
||||
public:
|
||||
StringIter(const String* container, int index = -1)
|
||||
: m_index(index), m_container(container)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator!=(const StringIter& other) const
|
||||
{
|
||||
return m_index != other.m_index;
|
||||
}
|
||||
|
||||
char operator*() const
|
||||
{
|
||||
return (*m_container)[m_index];
|
||||
}
|
||||
|
||||
void operator++()
|
||||
{
|
||||
m_index++;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_index{-1};
|
||||
const String* m_container{nullptr};
|
||||
};
|
||||
|
||||
StringIter begin() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
return StringIter(this, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return StringIter(this, 0);
|
||||
}
|
||||
}
|
||||
|
||||
StringIter end() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
return StringIter(this, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return StringIter(this, size());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void append(const char* data);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class Vector
|
|||
public:
|
||||
Vector() = default;
|
||||
|
||||
Vector(std::size_t size)
|
||||
Vector(size_t size)
|
||||
{
|
||||
resize(size);
|
||||
}
|
||||
|
@ -44,40 +44,40 @@ public:
|
|||
return m_data;
|
||||
}
|
||||
|
||||
bool slice(std::size_t slice_idx, Vector& v) const
|
||||
bool slice(size_t slice_idx, Vector& v) const
|
||||
{
|
||||
if (slice_idx >= m_size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
v.resize(slice_idx);
|
||||
for(std::size_t idx=0; idx<slice_idx;idx++)
|
||||
for(size_t idx=0; idx<slice_idx;idx++)
|
||||
{
|
||||
v.m_data[idx] = m_data[idx];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool slice(std::size_t slice_start, std::size_t slice_end, Vector& v) const
|
||||
bool slice(size_t slice_start, size_t slice_end, Vector& v) const
|
||||
{
|
||||
if (slice_end > m_size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
v.resize(slice_end - slice_start);
|
||||
for(std::size_t idx=slice_start; idx<slice_end;idx++)
|
||||
for(size_t idx=slice_start; idx<slice_end;idx++)
|
||||
{
|
||||
v.m_data[idx - slice_start] = m_data[idx];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
size_t size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
std::size_t capacity() const
|
||||
size_t capacity() const
|
||||
{
|
||||
return m_capacity;
|
||||
}
|
||||
|
@ -101,13 +101,13 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void resize(std::size_t size)
|
||||
void resize(size_t size)
|
||||
{
|
||||
resize_capacity(size);
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
void resize(std::size_t size, const T& value)
|
||||
void resize(size_t size, const T& value)
|
||||
{
|
||||
resize_capacity(size);
|
||||
m_size = size;
|
||||
|
@ -145,19 +145,34 @@ public:
|
|||
}
|
||||
else if (m_size >= m_capacity)
|
||||
{
|
||||
const std::size_t new_size = 1.5*m_size;
|
||||
const size_t new_size = 1.5*m_size;
|
||||
resize_capacity(new_size);
|
||||
}
|
||||
m_data[m_size] = item;
|
||||
m_size++;
|
||||
}
|
||||
|
||||
const T& operator[] (const std::size_t idx) const
|
||||
void push_back(T&& item)
|
||||
{
|
||||
if (!has_allocated())
|
||||
{
|
||||
resize_capacity(10);
|
||||
}
|
||||
else if (m_size >= m_capacity)
|
||||
{
|
||||
const size_t new_size = 1.5*m_size;
|
||||
resize_capacity(new_size);
|
||||
}
|
||||
m_data[m_size] = std::move(item);
|
||||
m_size++;
|
||||
}
|
||||
|
||||
const T& operator[] (const size_t idx) const
|
||||
{
|
||||
return m_data[idx];
|
||||
}
|
||||
|
||||
T& operator[] (const std::size_t idx)
|
||||
T& operator[] (const size_t idx)
|
||||
{
|
||||
return m_data[idx];
|
||||
}
|
||||
|
@ -165,7 +180,7 @@ public:
|
|||
Vector<T>& operator=(const Vector<T>& v)
|
||||
{
|
||||
resize(v.size());
|
||||
for(std::size_t idx=0; idx<v.size(); idx++)
|
||||
for(size_t idx=0; idx<v.size(); idx++)
|
||||
{
|
||||
m_data[idx] = v.m_data[idx];
|
||||
}
|
||||
|
@ -178,7 +193,7 @@ public:
|
|||
{
|
||||
return false;
|
||||
}
|
||||
for(std::size_t idx=0; idx<m_size; idx++)
|
||||
for(size_t idx=0; idx<m_size; idx++)
|
||||
{
|
||||
if (m_data[idx] != other[idx])
|
||||
{
|
||||
|
@ -191,7 +206,7 @@ public:
|
|||
private:
|
||||
void fill_with(const T& value)
|
||||
{
|
||||
for(std::size_t idx = 0; idx<m_size; idx++)
|
||||
for(size_t idx = 0; idx<m_size; idx++)
|
||||
{
|
||||
m_data[idx] = value;
|
||||
}
|
||||
|
@ -207,7 +222,7 @@ private:
|
|||
return m_capacity - m_size;
|
||||
}
|
||||
|
||||
void resize_capacity(std::size_t new_capacity)
|
||||
void resize_capacity(size_t new_capacity)
|
||||
{
|
||||
if (!has_allocated())
|
||||
{
|
||||
|
@ -224,7 +239,7 @@ private:
|
|||
}
|
||||
for(size_t idx=0; idx<min_capacity; idx++)
|
||||
{
|
||||
temp[idx] = m_data[idx];
|
||||
temp[idx] = std::move(m_data[idx]);
|
||||
}
|
||||
clear(false);
|
||||
m_data = temp;
|
||||
|
@ -234,6 +249,6 @@ private:
|
|||
|
||||
T* m_data{nullptr};
|
||||
Allocator<T> m_allocator;
|
||||
std::size_t m_size{0};
|
||||
std::size_t m_capacity{0};
|
||||
size_t m_size{0};
|
||||
size_t m_capacity{0};
|
||||
};
|
|
@ -1,32 +1,32 @@
|
|||
#include "ByteUtils.h"
|
||||
|
||||
|
||||
bool ByteUtils::MostSignificantBitIsOne(char c)
|
||||
bool ByteUtils::MostSignificantBitIsOne(Byte c)
|
||||
{
|
||||
return c & (1 << 7);
|
||||
}
|
||||
|
||||
ByteUtils::Word ByteUtils::GetWordFirstBit(const Word word)
|
||||
Word ByteUtils::GetWordFirstBit(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_FIRST_BIT;
|
||||
};
|
||||
|
||||
ByteUtils::Word ByteUtils::GetWordLastByte(const Word word)
|
||||
Word ByteUtils::GetWordLastByte(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_LAST_BYTE;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getHigherNBits(unsigned char input, unsigned num)
|
||||
unsigned char ByteUtils::getHigherNBits(Byte input, size_t num)
|
||||
{
|
||||
return input >> (8 - num);
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getByteN(uint32_t input, unsigned n)
|
||||
unsigned char ByteUtils::getByteN(DWord input, size_t n)
|
||||
{
|
||||
return (input << 8*n) >> 24;
|
||||
}
|
||||
|
||||
uint32_t ByteUtils::mirror(uint32_t byte, unsigned length)
|
||||
uint32_t ByteUtils::mirror(DWord byte, size_t length)
|
||||
{
|
||||
uint32_t ret{0};
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
|
@ -39,7 +39,7 @@ uint32_t ByteUtils::mirror(uint32_t byte, unsigned length)
|
|||
return ret;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getLowerNBits(uint32_t input, unsigned num)
|
||||
unsigned char ByteUtils::getLowerNBits(DWord input, size_t num)
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
|
@ -64,12 +64,12 @@ unsigned char ByteUtils::getLowerNBits(uint32_t input, unsigned num)
|
|||
}
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getTwoBitsAtN(unsigned char input, unsigned n)
|
||||
unsigned char ByteUtils::getTwoBitsAtN(Byte input, size_t n)
|
||||
{
|
||||
return (input & (0x03 << n)) >> n;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getMBitsAtN(unsigned char input, unsigned m, unsigned n)
|
||||
unsigned char ByteUtils::getMBitsAtN(Byte input, size_t m, size_t n)
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ unsigned char ByteUtils::getMBitsAtN(unsigned char input, unsigned m, unsigned n
|
|||
}
|
||||
}
|
||||
|
||||
bool ByteUtils::getBitN(uint32_t input, unsigned n)
|
||||
bool ByteUtils::getBitN(DWord input, size_t n)
|
||||
{
|
||||
return input & (1 << n);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ unsigned char ByteUtils::getFromString(const String& string)
|
|||
{
|
||||
unsigned char ret{0};
|
||||
|
||||
if (string.length() < 8)
|
||||
if (string.size() < 8)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ unsigned char ByteUtils::getFromString(const String& string)
|
|||
return ret;
|
||||
}
|
||||
|
||||
String ByteUtils::toString(uint32_t input, unsigned length)
|
||||
String ByteUtils::toString(DWord input, size_t length)
|
||||
{
|
||||
String ret;
|
||||
if (length > 8)
|
||||
|
@ -144,7 +144,7 @@ String ByteUtils::toString(uint32_t input, unsigned length)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void ByteUtils::ReverseBuffer(char* buffer, char* reverse, unsigned size, unsigned targetSize)
|
||||
void ByteUtils::ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t targetSize)
|
||||
{
|
||||
for(unsigned idx=0; idx<targetSize; idx++)
|
||||
{
|
||||
|
@ -159,22 +159,22 @@ void ByteUtils::ReverseBuffer(char* buffer, char* reverse, unsigned size, unsign
|
|||
}
|
||||
}
|
||||
|
||||
ByteUtils::Word ByteUtils::ToWord(char* buffer, bool reverse)
|
||||
Word ByteUtils::ToWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<Word>(buffer, reverse);
|
||||
}
|
||||
|
||||
ByteUtils::DWord ByteUtils::ToDWord(char* buffer, bool reverse)
|
||||
DWord ByteUtils::ToDWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<DWord>(buffer, reverse);
|
||||
}
|
||||
|
||||
ByteUtils::QWord ByteUtils::ToQWord(char* buffer, bool reverse)
|
||||
QWord ByteUtils::ToQWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<QWord>(buffer, reverse);
|
||||
}
|
||||
|
||||
bool ByteUtils::Compare(char* buffer, const char* tag, unsigned size)
|
||||
bool ByteUtils::Compare(Byte* buffer, const char* tag, size_t size)
|
||||
{
|
||||
for(unsigned idx=0; idx<size; idx++)
|
||||
{
|
||||
|
@ -186,12 +186,12 @@ bool ByteUtils::Compare(char* buffer, const char* tag, unsigned size)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ByteUtils::CompareDWords(char* buffer, const char* tag)
|
||||
bool ByteUtils::CompareDWords(Byte* buffer, const char* tag)
|
||||
{
|
||||
return Compare(buffer, tag, sizeof(DWord));
|
||||
}
|
||||
|
||||
bool ByteUtils::CompareWords(char* buffer, const char* tag)
|
||||
bool ByteUtils::CompareWords(Byte* buffer, const char* tag)
|
||||
{
|
||||
return Compare(buffer, tag, sizeof(Word));
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "ByteTypes.h"
|
||||
#include "String.h"
|
||||
#include <cstring>
|
||||
|
||||
class ByteUtils
|
||||
{
|
||||
|
@ -13,25 +12,25 @@ public:
|
|||
|
||||
static Word GetWordLastByte(const Word word);
|
||||
|
||||
static Byte getByteN(DWord input, std::size_t n);
|
||||
static Byte getByteN(DWord input, size_t n);
|
||||
|
||||
static Byte getHigherNBits(Byte input, std::size_t num);
|
||||
static Byte getHigherNBits(Byte input, size_t num);
|
||||
|
||||
static Byte getLowerNBits(DWord input, std::size_t num);
|
||||
static Byte getLowerNBits(DWord input, size_t num);
|
||||
|
||||
static Byte getTwoBitsAtN(Byte input, std::size_t n);
|
||||
static Byte getTwoBitsAtN(Byte input, size_t n);
|
||||
|
||||
static Byte getMBitsAtN(Byte input, std::size_t m, std::size_t n);
|
||||
static Byte getMBitsAtN(Byte input, size_t m, size_t n);
|
||||
|
||||
static bool getBitN(DWord input, std::size_t n);
|
||||
static bool getBitN(DWord input, size_t n);
|
||||
|
||||
static Byte getFromString(const String& string);
|
||||
|
||||
static String toString(DWord input, std::size_t length = 8);
|
||||
static String toString(DWord input, size_t length = 8);
|
||||
|
||||
static DWord mirror(DWord input, std::size_t length=0);
|
||||
static DWord mirror(DWord input, size_t length=0);
|
||||
|
||||
static void ReverseBuffer(Byte* buffer, Byte* reverse, std::size_t size, std::size_t targetSize);
|
||||
static void ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t targetSize);
|
||||
|
||||
template<typename T>
|
||||
static T ToType(Byte* buffer, bool reverse = true)
|
||||
|
@ -41,11 +40,11 @@ public:
|
|||
{
|
||||
char reversed[sizeof(T)];
|
||||
ReverseBuffer(buffer, reversed, sizeof(T), sizeof(T));
|
||||
std::memcpy(&result, reversed, sizeof(T));
|
||||
//std::memcpy(&result, reversed, sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::memcpy(&result, buffer, sizeof(T));
|
||||
//std::memcpy(&result, buffer, sizeof(T));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -56,7 +55,7 @@ public:
|
|||
|
||||
static QWord ToQWord(Byte* buffer, bool reverse = true);
|
||||
|
||||
static bool Compare(Byte* buffer, const char* tag, std::size_t size);
|
||||
static bool Compare(Byte* buffer, const char* tag, size_t size);
|
||||
|
||||
static bool CompareDWords(Byte* buffer, const char* tag);
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ bool StringUtils::isWhitespaceOnly(const String& input)
|
|||
}
|
||||
}
|
||||
|
||||
std::size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
||||
size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
||||
{
|
||||
auto found_id = input.find(c);
|
||||
if(found_id == String::npos)
|
||||
|
@ -62,8 +62,8 @@ std::size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
|||
}
|
||||
else
|
||||
{
|
||||
std::size_t count = 1;
|
||||
for(std::size_t idx=found_id+1; idx<input.size(); idx++)
|
||||
size_t count = 1;
|
||||
for(size_t idx=found_id+1; idx<input.size(); idx++)
|
||||
{
|
||||
if(input[idx] == c)
|
||||
{
|
||||
|
@ -85,9 +85,9 @@ String StringUtils::stripSurroundingWhitepsace(const String& input)
|
|||
return {};
|
||||
}
|
||||
|
||||
std::size_t first_nonspace = 0;
|
||||
std::size_t last_nonspace = input.size() - 1;
|
||||
for (std::size_t idx = 0; idx < input.size(); idx++)
|
||||
size_t first_nonspace = 0;
|
||||
size_t last_nonspace = input.size() - 1;
|
||||
for (size_t idx = 0; idx < input.size(); idx++)
|
||||
{
|
||||
if (!std::isspace(input[idx]))
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ String StringUtils::stripSurroundingWhitepsace(const String& input)
|
|||
return {};
|
||||
}
|
||||
|
||||
for (std::size_t idx = last_nonspace; idx > 0; idx--)
|
||||
for (size_t idx = last_nonspace; idx > 0; idx--)
|
||||
{
|
||||
if (!std::isspace(input[idx]))
|
||||
{
|
||||
|
@ -162,8 +162,8 @@ String StringUtils::stripQuotes(const String& input)
|
|||
{
|
||||
return input;
|
||||
}
|
||||
std::size_t start_index = 0;
|
||||
std::size_t end_index = input.size()-1;
|
||||
size_t start_index = 0;
|
||||
size_t end_index = input.size()-1;
|
||||
if (input[start_index] == '"')
|
||||
{
|
||||
start_index = 1;
|
||||
|
@ -177,7 +177,7 @@ String StringUtils::stripQuotes(const String& input)
|
|||
|
||||
String StringUtils::removeUpTo(const String& input, const String& prefix)
|
||||
{
|
||||
std::size_t found = input.find(prefix);
|
||||
size_t found = input.find(prefix);
|
||||
if (found != String::npos)
|
||||
{
|
||||
return input.substr(found + prefix.size(), input.size()-found);
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
static constexpr char SINGLE_QUOTE = '\'';
|
||||
static constexpr char COLON = ':';
|
||||
|
||||
static std::size_t countFirstConsecutiveHits(const String& input, char c);
|
||||
static size_t countFirstConsecutiveHits(const String& input, char c);
|
||||
|
||||
static bool isAlphaNumeric(char c);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <stdexcept>
|
||||
#include <cstdint>
|
||||
|
||||
/*
|
||||
String UnicodeUtils::utf16ToUtf8String(const std::wstring& input)
|
||||
{
|
||||
if (input.empty())
|
||||
|
@ -23,7 +24,9 @@ String UnicodeUtils::utf16ToUtf8String(const std::wstring& input)
|
|||
throw std::logic_error("Not implemented");
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
std::wstring UnicodeUtils::utf8ToUtf16WString(const String& input)
|
||||
{
|
||||
if (input.empty())
|
||||
|
@ -40,13 +43,15 @@ std::wstring UnicodeUtils::utf8ToUtf16WString(const String& input)
|
|||
throw std::logic_error("Not implemented");
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
Vector<uint32_t> UnicodeUtils::utf8ToUtf32(const String& input)
|
||||
{
|
||||
const auto utf_16 = utf8ToUtf16WString(input);
|
||||
//const auto utf_16 = utf8ToUtf16WString(input);
|
||||
|
||||
Vector<uint32_t> output;
|
||||
std::size_t pos = 0;
|
||||
/*
|
||||
size_t pos = 0;
|
||||
while (pos < utf_16.size())
|
||||
{
|
||||
const auto c = utf_16[pos];
|
||||
|
@ -68,6 +73,7 @@ Vector<uint32_t> UnicodeUtils::utf8ToUtf32(const String& input)
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
class UnicodeUtils
|
||||
{
|
||||
public:
|
||||
static String utf16ToUtf8String(const std::wstring& input);
|
||||
//static String utf16ToUtf8String(const std::wstring& input);
|
||||
|
||||
static std::wstring utf8ToUtf16WString(const String& input);
|
||||
//static std::wstring utf8ToUtf16WString(const String& input);
|
||||
|
||||
static Vector<uint32_t> utf8ToUtf32(const String& input);
|
||||
|
||||
|
|
|
@ -78,31 +78,31 @@ public:
|
|||
return m_open_for_write;
|
||||
}
|
||||
|
||||
Result<std::size_t> do_read(VecBytes& bytes)
|
||||
Result<size_t> do_read(VecBytes& bytes)
|
||||
{
|
||||
errno = 0;
|
||||
const auto rc = ::read(m_fd, bytes.data(), bytes.capacity());
|
||||
if (rc < 0)
|
||||
{
|
||||
const auto msg = _s("Error in read impl | ") + Error::from_errno();
|
||||
return Result<std::size_t>(Error(msg));
|
||||
return Result<size_t>(Error(msg));
|
||||
}
|
||||
return Result<std::size_t>(rc);
|
||||
return Result<size_t>(rc);
|
||||
}
|
||||
|
||||
Result<std::size_t> do_write(const VecBytes& bytes)
|
||||
Result<size_t> do_write(const VecBytes& bytes)
|
||||
{
|
||||
errno = 0;
|
||||
const auto rc = ::write(m_fd, bytes.data(), bytes.size());
|
||||
if (rc < 0)
|
||||
{
|
||||
const auto msg = _s("Error in write impl | ") + Error::from_errno();
|
||||
return Result<std::size_t>(Error(msg));
|
||||
return Result<size_t>(Error(msg));
|
||||
}
|
||||
return Result<std::size_t>(rc);
|
||||
return Result<size_t>(rc);
|
||||
}
|
||||
|
||||
Result<std::size_t> do_write(const Vector<char>& bytes, int size = -1)
|
||||
Result<size_t> do_write(const Vector<char>& bytes, int size = -1)
|
||||
{
|
||||
errno = 0;
|
||||
int rc = 0;
|
||||
|
@ -117,9 +117,9 @@ public:
|
|||
if (rc < 0)
|
||||
{
|
||||
const auto msg = _s("Error in write impl | ") + Error::from_errno();
|
||||
return Result<std::size_t>(Error(msg));
|
||||
return Result<size_t>(Error(msg));
|
||||
}
|
||||
return Result<std::size_t>(rc);
|
||||
return Result<size_t>(rc);
|
||||
}
|
||||
|
||||
Status update_size()
|
||||
|
@ -139,7 +139,7 @@ public:
|
|||
bool m_open_for_write{false};
|
||||
bool m_open_for_read{false};
|
||||
bool m_valid{false};
|
||||
std::size_t m_size{0};
|
||||
size_t m_size{0};
|
||||
bool m_is_open{false};
|
||||
int m_fd{-1};
|
||||
};
|
||||
|
|
|
@ -5,24 +5,24 @@
|
|||
FileFormat::ExtensionMap FileFormat::mExtensions = []
|
||||
{
|
||||
ExtensionMap ret;
|
||||
ret[Format::Markdown] = ".md";
|
||||
ret[Format::Html] = ".html";
|
||||
ret[Format::Wav] = ".wav";
|
||||
//ret.insert(Format::Markdown, ".md");
|
||||
//ret.insert(Format::Html, ".html");
|
||||
//ret.insert(Format::Wav, ".wav");
|
||||
return ret;
|
||||
}();
|
||||
|
||||
bool FileFormat::isFormat(const String& extension, Format format)
|
||||
{
|
||||
return StringUtils::toLower(extension) == mExtensions[format];
|
||||
return StringUtils::toLower(extension) == (*mExtensions.find(format)).value();
|
||||
}
|
||||
|
||||
FileFormat::Format FileFormat::inferFormat(const String& query)
|
||||
{
|
||||
for(const auto& extension : mExtensions)
|
||||
{
|
||||
if(extension.second == query)
|
||||
if(extension.value() == query)
|
||||
{
|
||||
return extension.first;
|
||||
return extension.key();
|
||||
}
|
||||
}
|
||||
return Format::Unknown;
|
||||
|
@ -30,5 +30,5 @@ FileFormat::Format FileFormat::inferFormat(const String& query)
|
|||
|
||||
String FileFormat::getExtension(Format format)
|
||||
{
|
||||
return mExtensions[format];
|
||||
return (*mExtensions.find(format)).value();
|
||||
}
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
#include "PathUtils.h"
|
||||
|
||||
|
||||
String PathUtils::getBaseFilename(const Path& path)
|
||||
String PathUtils::getBaseFilename(const FileSystemPath& path)
|
||||
{
|
||||
return path.stem().string();
|
||||
//return path.stem().string();
|
||||
return {};
|
||||
}
|
||||
|
||||
Path PathUtils::getRelativePath(const Path& input, const Path& relativeTo)
|
||||
FileSystemPath PathUtils::getRelativePath(const FileSystemPath& input, const FileSystemPath& relativeTo)
|
||||
{
|
||||
return std::filesystem::relative(input, relativeTo);
|
||||
//return std::filesystem::relative(input, relativeTo);
|
||||
return input;
|
||||
}
|
||||
|
||||
String PathUtils::getPathDelimited(const Path& path, char delimiter)
|
||||
String PathUtils::getPathDelimited(const FileSystemPath& path, char delimiter)
|
||||
{
|
||||
String name;
|
||||
/*
|
||||
|
||||
unsigned count = 0;
|
||||
for(const auto& element : path)
|
||||
|
@ -28,6 +31,7 @@ String PathUtils::getPathDelimited(const Path& path, char delimiter)
|
|||
}
|
||||
count++;
|
||||
}
|
||||
*/
|
||||
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include "FileSystemPath.h"
|
||||
#include "String.h"
|
||||
#include "Vector.h"
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
||||
class PathUtils
|
||||
{
|
||||
public:
|
||||
static String getBaseFilename(const Path& path);
|
||||
static String getBaseFilename(const FileSystemPath& path);
|
||||
|
||||
static Path getRelativePath(const Path& path, const Path& relativeTo);
|
||||
static FileSystemPath getRelativePath(const FileSystemPath& path, const FileSystemPath& relativeTo);
|
||||
|
||||
static String getPathDelimited(const Path& path, char delimiter='-');
|
||||
static String getPathDelimited(const FileSystemPath& path, char delimiter='-');
|
||||
};
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
//#include <cstddef>
|
||||
#include <stdlib.h>
|
||||
#include <utility>
|
||||
|
||||
template<typename T>
|
||||
class Allocator
|
||||
{
|
||||
public:
|
||||
template<class U>
|
||||
T* allocate(U&& u)
|
||||
{
|
||||
return new T(std::forward<U>(u));
|
||||
}
|
||||
|
||||
T* allocate()
|
||||
{
|
||||
return new T;
|
||||
return new T();
|
||||
}
|
||||
|
||||
void do_delete(T* p)
|
||||
|
@ -17,7 +23,7 @@ public:
|
|||
delete p;
|
||||
}
|
||||
|
||||
T* alloc_array(std::size_t size)
|
||||
T* alloc_array(size_t size)
|
||||
{
|
||||
return new T[size];
|
||||
}
|
||||
|
|
|
@ -11,6 +11,14 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
template<class U>
|
||||
static Ptr create(U&& u)
|
||||
{
|
||||
Ptr p;
|
||||
p.allocate(std::forward<U>(u));
|
||||
return std::move(p);
|
||||
}
|
||||
|
||||
static Ptr create()
|
||||
{
|
||||
Ptr p;
|
||||
|
@ -18,12 +26,23 @@ public:
|
|||
return std::move(p);
|
||||
}
|
||||
|
||||
template<class U>
|
||||
void allocate(U&& u)
|
||||
{
|
||||
m_raw = m_allocator.allocate(std::forward<U>(u));
|
||||
}
|
||||
|
||||
void allocate()
|
||||
{
|
||||
m_raw = m_allocator.allocate();
|
||||
}
|
||||
|
||||
~Ptr()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
if (m_raw != nullptr)
|
||||
{
|
||||
|
@ -38,6 +57,21 @@ public:
|
|||
*this = std::move(other);
|
||||
}
|
||||
|
||||
void clear_raw()
|
||||
{
|
||||
m_raw = nullptr;
|
||||
}
|
||||
|
||||
T* get()
|
||||
{
|
||||
return m_raw;
|
||||
}
|
||||
|
||||
const T* get() const
|
||||
{
|
||||
return m_raw;
|
||||
}
|
||||
|
||||
Ptr<T>& operator=(const Ptr<T>& other) = delete;
|
||||
|
||||
template<typename U>
|
||||
|
@ -51,12 +85,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
T* get()
|
||||
{
|
||||
return m_raw;
|
||||
}
|
||||
|
||||
const T* get() const
|
||||
const T* operator->() const
|
||||
{
|
||||
return m_raw;
|
||||
}
|
||||
|
@ -66,9 +95,9 @@ public:
|
|||
return m_raw;
|
||||
}
|
||||
|
||||
void clear_raw()
|
||||
operator bool() const
|
||||
{
|
||||
m_raw = nullptr;
|
||||
return m_raw != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "SharedMemory.h"
|
||||
#include "SharedPointer.h"
|
||||
|
||||
#include "RandomUtils.h"
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
|||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
void SharedMemory::allocate(const String& namePrefix, std::size_t size)
|
||||
void SharedMemory::allocate(const String& namePrefix, size_t size)
|
||||
{
|
||||
createFile(namePrefix);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
class SharedMemory
|
||||
{
|
||||
public:
|
||||
void allocate(const String& namePrefix, std::size_t size);
|
||||
void allocate(const String& namePrefix, size_t size);
|
||||
|
||||
int getFileDescriptor() const;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ void HttpHeader::parse(const Vector<String >& message)
|
|||
bool foundDelimiter{false};
|
||||
for (const auto& line : message)
|
||||
{
|
||||
for(std::size_t idx = 0; idx< line.size(); idx++)
|
||||
for(size_t idx = 0; idx< line.size(); idx++)
|
||||
{
|
||||
const auto c = line[idx];
|
||||
if (c == StringUtils::COLON)
|
||||
|
|
|
@ -66,7 +66,7 @@ void HttpRequest::fromString(const String& message)
|
|||
mRequiredBytes = 0;
|
||||
}
|
||||
|
||||
std::size_t HttpRequest::requiredBytes() const
|
||||
size_t HttpRequest::requiredBytes() const
|
||||
{
|
||||
return mRequiredBytes;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
|
||||
String toString(const String& host) const;
|
||||
|
||||
std::size_t requiredBytes() const;
|
||||
size_t requiredBytes() const;
|
||||
|
||||
private:
|
||||
Verb mVerb = Verb::UNKNOWN;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
Vector<unsigned> RandomUtils::getRandomVecUnsigned(std::size_t size)
|
||||
Vector<unsigned> RandomUtils::getRandomVecUnsigned(size_t size)
|
||||
{
|
||||
std::random_device rnd_device;
|
||||
|
||||
|
|
|
@ -6,5 +6,5 @@ class RandomUtils
|
|||
{
|
||||
public:
|
||||
|
||||
static Vector<unsigned> getRandomVecUnsigned(std::size_t size);
|
||||
static Vector<unsigned> getRandomVecUnsigned(size_t size);
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
class Serializeable
|
||||
{
|
||||
public:
|
||||
virtual std::size_t getSize() const = 0;
|
||||
virtual size_t getSize() const = 0;
|
||||
|
||||
virtual uint8_t getByte(std::size_t index) const = 0;
|
||||
virtual uint8_t getByte(size_t index) const = 0;
|
||||
};
|
|
@ -1,8 +1,6 @@
|
|||
#include "TomlReader.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <algorithm>
|
||||
#include "CharUtils.h"
|
||||
|
||||
TomlTable::TomlTable(const String& header)
|
||||
: mHeader(header)
|
||||
|
@ -12,17 +10,17 @@ TomlTable::TomlTable(const String& header)
|
|||
|
||||
void TomlTable::addComment(const Comment& comment)
|
||||
{
|
||||
mComments.push_back(comment);
|
||||
//mComments.push_back(comment);
|
||||
}
|
||||
|
||||
void TomlTable::addTable(Ptr<TomlTable> table)
|
||||
{
|
||||
mTables[table->getHeader()] = std::move(table);
|
||||
mTables.insert(table->getHeader(), std::move(table));
|
||||
}
|
||||
|
||||
void TomlTable::addKeyValuePair(const String& key, const String& value)
|
||||
{
|
||||
mMap[key] = value;
|
||||
mMap.insert(key, value);
|
||||
}
|
||||
|
||||
String TomlTable::getHeader() const
|
||||
|
@ -30,49 +28,53 @@ String TomlTable::getHeader() const
|
|||
return mHeader;
|
||||
}
|
||||
|
||||
TomlTable* TomlTable::getTable(const String& path)
|
||||
const TomlTable* TomlTable::getTable(const String& path)
|
||||
{
|
||||
return mTables[path].get();
|
||||
return (*mTables.find(path)).value().get();
|
||||
}
|
||||
|
||||
TomlTable::KeyValuePairs TomlTable::getKeyValuePairs() const
|
||||
const TomlTable::KeyValuePairs& TomlTable::getKeyValuePairs() const
|
||||
{
|
||||
return mMap;
|
||||
}
|
||||
|
||||
|
||||
TomlContent::TomlContent()
|
||||
: mRootTable(std::make_unique<TomlTable>("root"))
|
||||
: mRootTable(Ptr<TomlTable>::create("root"))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TomlTable* TomlContent::getRootTable() const
|
||||
const TomlTable* TomlContent::getRootTable() const
|
||||
{
|
||||
return mRootTable.get();
|
||||
//return mRootTable.get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TomlTable* TomlContent::getTable(const String& path) const
|
||||
const TomlTable* TomlContent::getTable(const String& path) const
|
||||
{
|
||||
return mRootTable->getTable(path);
|
||||
//return mRootTable->getTable(path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TomlReader::TomlReader()
|
||||
: mContent(std::make_unique<TomlContent>())
|
||||
: mContent(Ptr<TomlContent>::create())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TomlContent* TomlReader::getContent() const
|
||||
const TomlContent* TomlReader::getContent() const
|
||||
{
|
||||
return mContent.get();
|
||||
//return mContent.get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TomlReader::read(const Path& input_path)
|
||||
void TomlReader::read(const FileSystemPath& input_path)
|
||||
{
|
||||
const auto lines = File(input_path).readLines();
|
||||
Vector<String> lines;
|
||||
File(input_path).readLines(lines);
|
||||
mLastSectionOffset = 0;
|
||||
mWorkingTable = mContent->getRootTable();
|
||||
//mWorkingTable = mContent->getRootTable();
|
||||
|
||||
for (const auto& line : lines)
|
||||
{
|
||||
|
@ -126,11 +128,11 @@ void TomlReader::processLine(const String& line)
|
|||
}
|
||||
else if (found_key)
|
||||
{
|
||||
key_string.erase(std::remove_if(key_string.begin(), key_string.end(), [](char c) {return std::isspace(c); }), key_string.end());
|
||||
working_string.erase(std::remove_if(working_string.begin(), working_string.end(), [](char c) {return std::isspace(c); }), working_string.end());
|
||||
key_string.eraseIf([](char c) {return CharUtils::is_space(c); });
|
||||
working_string.eraseIf([](char c) {return CharUtils::is_space(c); });
|
||||
if (working_string.size()>2 && working_string[0] == '"' && working_string[working_string.size() - 1] == '"')
|
||||
{
|
||||
working_string = working_string.substr(1, working_string.size() - 2);
|
||||
working_string.slice(1, working_string.size() - 2, working_string);
|
||||
}
|
||||
|
||||
onKeyValuePair(key_string, working_string);
|
||||
|
@ -139,7 +141,7 @@ void TomlReader::processLine(const String& line)
|
|||
|
||||
void TomlReader::onHeader(const String& header)
|
||||
{
|
||||
auto new_table = std::make_unique<TomlTable>(header);
|
||||
auto new_table = Ptr<TomlTable>::create(header);
|
||||
auto table_temp = new_table.get();
|
||||
mWorkingTable->addTable(std::move(new_table));
|
||||
mWorkingTable = table_temp;
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "File.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include "Memory.h"
|
||||
#include <unordered_map>
|
||||
#include "FileSystemPath.h"
|
||||
#include "Pointer.h"
|
||||
#include "Map.h"
|
||||
#include "String.h"
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
||||
class TomlTable
|
||||
{
|
||||
public:
|
||||
using Comment = std::pair<unsigned, String>;
|
||||
using KeyValuePairs = std::unordered_map<String, String>;
|
||||
using Comment = Pair<unsigned, String>;
|
||||
using KeyValuePairs = Map<String, String>;
|
||||
|
||||
TomlTable(const String& header);
|
||||
|
||||
|
@ -25,13 +22,13 @@ public:
|
|||
|
||||
String getHeader() const;
|
||||
|
||||
TomlTable* getTable(const String& path);
|
||||
const TomlTable* getTable(const String& path);
|
||||
|
||||
KeyValuePairs getKeyValuePairs() const;
|
||||
const KeyValuePairs& getKeyValuePairs() const;
|
||||
|
||||
private:
|
||||
String mHeader;
|
||||
std::unordered_map<String, Ptr<TomlTable> > mTables;
|
||||
Map<String, Ptr<TomlTable> > mTables;
|
||||
KeyValuePairs mMap;
|
||||
Vector<Comment> mComments;
|
||||
};
|
||||
|
@ -41,9 +38,9 @@ class TomlContent
|
|||
public:
|
||||
TomlContent();
|
||||
|
||||
TomlTable* getRootTable() const;
|
||||
const TomlTable* getRootTable() const;
|
||||
|
||||
TomlTable* getTable(const String& path) const;
|
||||
const TomlTable* getTable(const String& path) const;
|
||||
|
||||
private:
|
||||
Ptr<TomlTable> mRootTable;
|
||||
|
@ -54,9 +51,9 @@ class TomlReader
|
|||
public:
|
||||
TomlReader();
|
||||
|
||||
TomlContent* getContent() const;
|
||||
const TomlContent* getContent() const;
|
||||
|
||||
void read(const Path& input_path);
|
||||
void read(const FileSystemPath& input_path);
|
||||
|
||||
void processLine(const String& line);
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#include "XmlDocument.h"
|
||||
|
||||
#include "XmlProlog.h"
|
||||
#include "XmlElement.h"
|
||||
|
||||
XmlDocument::XmlDocument()
|
||||
: mProlog(XmlProlog::Create("xml"))
|
||||
{
|
||||
|
@ -19,7 +16,12 @@ void XmlDocument::setProlog(Ptr<XmlProlog> prolog)
|
|||
mProlog = std::move(prolog);
|
||||
}
|
||||
|
||||
XmlProlog* XmlDocument::getProlog() const
|
||||
const XmlProlog* XmlDocument::getProlog() const
|
||||
{
|
||||
return mProlog.get();
|
||||
}
|
||||
|
||||
XmlProlog* XmlDocument::getProlog()
|
||||
{
|
||||
return mProlog.get();
|
||||
}
|
||||
|
@ -29,7 +31,7 @@ void XmlDocument::setRoot(Ptr<XmlElement> root)
|
|||
mRoot = std::move(root);
|
||||
}
|
||||
|
||||
XmlElement* XmlDocument::getRoot() const
|
||||
const XmlElement* XmlDocument::getRoot() const
|
||||
{
|
||||
return mRoot.get();
|
||||
}
|
||||
|
|
|
@ -6,21 +6,19 @@
|
|||
#include "XmlElement.h"
|
||||
#include "XmlProlog.h"
|
||||
|
||||
class XmlElement;
|
||||
class XmlProlog;
|
||||
|
||||
class XmlDocument
|
||||
{
|
||||
public:
|
||||
XmlDocument();
|
||||
virtual ~XmlDocument();
|
||||
|
||||
XmlProlog* getProlog() const;
|
||||
XmlElement* getRoot() const;
|
||||
const XmlProlog* getProlog() const;
|
||||
XmlProlog* getProlog();
|
||||
const XmlElement* getRoot() const;
|
||||
|
||||
void setProlog(Ptr<XmlProlog> prolog);
|
||||
void setRoot(Ptr<XmlElement> root);
|
||||
private:
|
||||
XmlPrologPtr mProlog;
|
||||
XmlElementPtr mRoot;
|
||||
Ptr<XmlProlog> mProlog;
|
||||
Ptr<XmlElement> mRoot;
|
||||
};
|
||||
|
|
|
@ -6,15 +6,13 @@
|
|||
#include "XmlElement.h"
|
||||
#include "XmlAttribute.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using LS = XmlParser::LineState;
|
||||
using DS = XmlParser::DocumentState;
|
||||
|
||||
XmlParser::XmlParser()
|
||||
: mDocumentState(XmlParser::DocumentState::Await_Prolog),
|
||||
mLineState(XmlParser::LineState::Await_Tag_Open),
|
||||
mDocument(XmlDocument::Create()),
|
||||
mDocument(Ptr<XmlDocument>::create()),
|
||||
mWorkingElements()
|
||||
{
|
||||
|
||||
|
@ -22,7 +20,7 @@ XmlParser::XmlParser()
|
|||
|
||||
void XmlParser::processLine(const String& input)
|
||||
{
|
||||
for (std::size_t idx=0; idx<input.size(); idx++)
|
||||
for (size_t idx=0; idx<input.size(); idx++)
|
||||
{
|
||||
switch (input[idx])
|
||||
{
|
||||
|
@ -301,13 +299,13 @@ void XmlParser::onTagClose()
|
|||
|
||||
void XmlParser::onTextStart(char c)
|
||||
{
|
||||
mWorkingText = c;
|
||||
mWorkingText += c;
|
||||
mLineState = LS::Await_Text_End;
|
||||
}
|
||||
|
||||
void XmlParser::onTextEnd()
|
||||
{
|
||||
mWorkingElements.top()->setText(mWorkingText);
|
||||
(*mWorkingElements.top())->setText(mWorkingText);
|
||||
}
|
||||
|
||||
void XmlParser::onElementTagEnd()
|
||||
|
@ -318,7 +316,7 @@ void XmlParser::onElementTagEnd()
|
|||
|
||||
void XmlParser::onTagNameStart(char c)
|
||||
{
|
||||
mWorkingTagName = c;
|
||||
mWorkingTagName += c;
|
||||
mLineState = LS::Await_Tag_Name_End;
|
||||
if(mDocumentState != DS::Build_Prolog && mDocumentState != DS::Close_Element)
|
||||
{
|
||||
|
@ -344,7 +342,7 @@ void XmlParser::onTagNameEnd()
|
|||
}
|
||||
else
|
||||
{
|
||||
mWorkingElements.top()->addChild(std::move(new_element));
|
||||
(*mWorkingElements.top())->addChild(std::move(new_element));
|
||||
}
|
||||
mWorkingElements.push(working_element);
|
||||
mLineState = LS::Await_Attribute_Name;
|
||||
|
@ -353,7 +351,7 @@ void XmlParser::onTagNameEnd()
|
|||
|
||||
void XmlParser::onAttributeNameStart(char c)
|
||||
{
|
||||
mWorkingAttributeName = c;
|
||||
mWorkingAttributeName += c;
|
||||
mLineState = LS::Await_Attribute_Name_End;
|
||||
}
|
||||
|
||||
|
@ -366,7 +364,7 @@ void XmlParser::onAttributeNameEnd()
|
|||
}
|
||||
else if(mDocumentState == DS::Build_Element)
|
||||
{
|
||||
mWorkingElements.top()->addAttribute(std::move(attribute));
|
||||
(*mWorkingElements.top())->addAttribute(std::move(attribute));
|
||||
}
|
||||
mLineState = LS::Await_Attribute_Value;
|
||||
}
|
||||
|
@ -385,7 +383,7 @@ void XmlParser::onAttributeValueEnd()
|
|||
}
|
||||
else if(mDocumentState == DS::Build_Element)
|
||||
{
|
||||
mWorkingElements.top()->getAttribute(mWorkingAttributeName)->setValue(mWorkingAttributeValue);
|
||||
(*mWorkingElements.top())->getAttribute(mWorkingAttributeName)->setValue(mWorkingAttributeValue);
|
||||
}
|
||||
mLineState = LS::Await_Attribute_Name;
|
||||
}
|
||||
|
@ -403,7 +401,7 @@ void XmlParser::onFinishProlog()
|
|||
mLineState = LS::Await_Tag_Open;
|
||||
}
|
||||
|
||||
XmlDocumentPtr XmlParser::getDocument()
|
||||
Ptr<XmlDocument> XmlParser::getDocument()
|
||||
{
|
||||
return std::move(mDocument);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "String.h"
|
||||
#include <stack>
|
||||
#include "Memory.h"
|
||||
#include "Stack.h"
|
||||
#include "Pointer.h"
|
||||
|
||||
class XmlDocument;
|
||||
using XmlDocumentPtr = Ptr<XmlDocument>;
|
||||
|
||||
class XmlElement;
|
||||
|
||||
class XmlParser
|
||||
|
@ -38,9 +36,9 @@ public:
|
|||
public:
|
||||
XmlParser();
|
||||
|
||||
void processLine(const String& input);
|
||||
Ptr<XmlDocument> getDocument();
|
||||
|
||||
XmlDocumentPtr getDocument();
|
||||
void processLine(const String& input);
|
||||
|
||||
private:
|
||||
void onLeftBracket();
|
||||
|
@ -92,8 +90,8 @@ private:
|
|||
private:
|
||||
DocumentState mDocumentState;
|
||||
LineState mLineState;
|
||||
XmlDocumentPtr mDocument;
|
||||
std::stack<XmlElement*> mWorkingElements;
|
||||
Ptr<XmlDocument> mDocument;
|
||||
Stack<XmlElement*> mWorkingElements;
|
||||
|
||||
String mWorkingAttributeName;
|
||||
String mWorkingTagName;
|
||||
|
|
|
@ -10,7 +10,7 @@ Status XmlWriter::toString(XmlDocument* document, String& output)
|
|||
output += "<?xml";
|
||||
for (const auto& [key, attribute] : prolog->getAttributes())
|
||||
{
|
||||
output += " " + attribute->getName() + "=\"" + attribute->getValue() + "\"";
|
||||
output += _s(" ") + attribute->getName() + _s("=\"") + attribute->getValue() + _s("\"");
|
||||
}
|
||||
output += "?>\n";
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ XmlAttribute::XmlAttribute(const String& name)
|
|||
|
||||
}
|
||||
|
||||
XmlAttributePtr XmlAttribute::Create(const String& name)
|
||||
Ptr<XmlAttribute> XmlAttribute::Create(const String& name)
|
||||
{
|
||||
return std::make_unique<XmlAttribute>(name);
|
||||
return Ptr<XmlAttribute>::create(name);
|
||||
}
|
||||
|
||||
const String& XmlAttribute::getName() const
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Pointer.h"
|
||||
#include "String.h"
|
||||
|
||||
class XmlAttribute
|
||||
|
@ -19,5 +19,3 @@ private:
|
|||
String mName;
|
||||
String mValue;
|
||||
};
|
||||
|
||||
using XmlAttributePtr = Ptr<XmlAttribute>;
|
||||
|
|
|
@ -14,9 +14,9 @@ XmlElement::~XmlElement()
|
|||
|
||||
}
|
||||
|
||||
XmlElementPtr XmlElement::Create(const String& tagName)
|
||||
Ptr<XmlElement> XmlElement::Create(const String& tagName)
|
||||
{
|
||||
return std::make_unique<XmlElement>(tagName);
|
||||
return Ptr<XmlElement>::create(tagName);
|
||||
}
|
||||
|
||||
void XmlElement::setTagName(const String& tagName)
|
||||
|
@ -24,19 +24,19 @@ void XmlElement::setTagName(const String& tagName)
|
|||
mTagName = tagName;
|
||||
}
|
||||
|
||||
void XmlElement::addChild(XmlElementPtr child)
|
||||
void XmlElement::addChild(Ptr<XmlElement> child)
|
||||
{
|
||||
mChildren.push_back(std::move(child));
|
||||
}
|
||||
|
||||
void XmlElement::addAttribute(XmlAttributePtr attribute)
|
||||
void XmlElement::addAttribute(Ptr<XmlAttribute> attribute)
|
||||
{
|
||||
mAttributes[attribute->getName()] = std::move(attribute);
|
||||
mAttributes.insert(attribute->getName(), std::move(attribute));
|
||||
}
|
||||
|
||||
void XmlElement::addAttribute(const String& name, const String& value)
|
||||
{
|
||||
auto attr = std::make_unique<XmlAttribute>(name);
|
||||
auto attr = Ptr<XmlAttribute>::create(name);
|
||||
attr->setValue(value);
|
||||
addAttribute(std::move(attr));
|
||||
}
|
||||
|
@ -74,16 +74,30 @@ bool XmlElement::hasAttribute(const String& attribute) const
|
|||
return (bool)(getAttribute(attribute));
|
||||
}
|
||||
|
||||
XmlAttribute* XmlElement::getAttribute(const String& attributeName) const
|
||||
const XmlAttribute* XmlElement::getAttribute(const String& attributeName) const
|
||||
{
|
||||
if (auto iter = mAttributes.find(attributeName); iter != mAttributes.end())
|
||||
{
|
||||
return iter->second.get();
|
||||
return (*iter).value().get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const std::unordered_map<String, XmlAttributePtr>& XmlElement::getAttributes() const
|
||||
XmlAttribute* XmlElement::getAttribute(const String& attributeName)
|
||||
{
|
||||
if (auto iter = mAttributes.find(attributeName); iter != mAttributes.end())
|
||||
{
|
||||
//return (*iter).value().get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void XmlElement::forEachAttribute(eachAttrFunc func) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const Map<String, Ptr<XmlAttribute> >& XmlElement::getAttributes() const
|
||||
{
|
||||
return mAttributes;
|
||||
}
|
||||
|
@ -102,18 +116,18 @@ String XmlElement::toString(unsigned depth, bool keepInline) const
|
|||
auto content = prefix + "<" + getTagName();
|
||||
for (const auto& [key, attribute] : getAttributes())
|
||||
{
|
||||
content += " " + attribute->getName() + "=\"" + attribute->getValue() + "\"";
|
||||
content += _s(" ") + attribute->getName() + _s("=\"") + attribute->getValue() + _s("\"");
|
||||
}
|
||||
|
||||
const auto num_children = mChildren.size();
|
||||
if (num_children == 0 && getText().empty())
|
||||
{
|
||||
content += "/>" + line_ending;
|
||||
content += _s("/>") + line_ending;
|
||||
return content;
|
||||
}
|
||||
else
|
||||
{
|
||||
content += ">";
|
||||
content += _s(">");
|
||||
}
|
||||
|
||||
if (!getText().empty())
|
||||
|
@ -135,6 +149,6 @@ String XmlElement::toString(unsigned depth, bool keepInline) const
|
|||
content += prefix;
|
||||
}
|
||||
|
||||
content += "</" + getTagName() + ">" + line_ending;
|
||||
content += _s("</") + getTagName() + _s(">") + line_ending;
|
||||
return content;
|
||||
}
|
||||
|
|
|
@ -14,15 +14,20 @@ public:
|
|||
|
||||
static Ptr<XmlElement> Create(const String& tagName);
|
||||
|
||||
void addAttribute(XmlAttributePtr attribute);
|
||||
void addAttribute(Ptr<XmlAttribute> attribute);
|
||||
void addAttribute(const String& name, const String& value);
|
||||
void addChild(Ptr<XmlElement> child);
|
||||
|
||||
const String& getTagName() const;
|
||||
const String& getText() const;
|
||||
|
||||
XmlAttribute* getAttribute(const String& attribute) const;
|
||||
const Map<Ptr<XmlAttribute> >& getAttributes() const;
|
||||
using eachAttrFunc = std::function<bool(const String& key, const XmlAttribute& attr)>;
|
||||
void forEachAttribute(eachAttrFunc func) const;
|
||||
|
||||
const XmlAttribute* getAttribute(const String& attribute) const;
|
||||
XmlAttribute* getAttribute(const String& attribute);
|
||||
|
||||
const Map<String, Ptr<XmlAttribute> >& getAttributes() const;
|
||||
|
||||
const Vector<Ptr<XmlElement> >& getChildren() const;
|
||||
|
||||
|
@ -39,6 +44,6 @@ protected:
|
|||
String mTagName;
|
||||
String mText;
|
||||
|
||||
Map<Ptr<XmlAttributePtr> > mAttributes;
|
||||
Map<String, Ptr<XmlAttribute> > mAttributes;
|
||||
Vector<Ptr<XmlElement> > mChildren;
|
||||
};
|
||||
|
|
|
@ -10,9 +10,9 @@ XmlProlog::XmlProlog(const String& tagName)
|
|||
|
||||
}
|
||||
|
||||
XmlPrologPtr XmlProlog::Create(const String& tagName)
|
||||
Ptr<XmlProlog> XmlProlog::Create(const String& tagName)
|
||||
{
|
||||
return std::make_unique<XmlProlog>(tagName);
|
||||
return Ptr<XmlProlog>::create(tagName);
|
||||
}
|
||||
|
||||
XmlProlog::Encoding XmlProlog::getEncoding() const
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue