Small cleaning.
This commit is contained in:
parent
70220fc6e9
commit
d7fe11913f
26 changed files with 613 additions and 548 deletions
|
@ -18,9 +18,6 @@ public:
|
||||||
void openDevice(AudioDevice* device) override;
|
void openDevice(AudioDevice* device) override;
|
||||||
|
|
||||||
void play(AudioDevice* device, AudioSample* sample, unsigned duration) override;
|
void play(AudioDevice* device, AudioSample* sample, unsigned duration) override;
|
||||||
|
|
||||||
private:
|
|
||||||
void openDevice(const AudioDevicePtr& device) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using NullAudioInterfacePtr = std::shared_ptr<NullAudioInterface>;
|
using NullAudioInterfacePtr = std::shared_ptr<NullAudioInterface>;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "FileLogger.h"
|
#include "FileLogger.h"
|
||||||
|
|
||||||
#include "AudioSynth.h"
|
#include "AudioSynth.h"
|
||||||
|
#include "AudioDevice.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -26,37 +27,37 @@ std::unique_ptr<WasapiInterface> WasapiInterface::Create()
|
||||||
return std::make_unique<WasapiInterface>();
|
return std::make_unique<WasapiInterface>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WasapiInterface::OpenDevice(const AudioDevicePtr& device)
|
void WasapiInterface::openDevice(AudioDevice* device)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WasapiInterface::SetAccessType(const AudioDevicePtr& device)
|
void WasapiInterface::setAccessType(AudioDevice* device)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WasapiInterface::SetSampleFormat(const AudioDevicePtr& device)
|
void WasapiInterface::setSampleFormat(AudioDevice* device)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WasapiInterface::SetSampleRate(const AudioDevicePtr& device)
|
void WasapiInterface::setSampleRate(AudioDevice* device)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WasapiInterface::SetPeriod(const AudioDevicePtr& device)
|
void WasapiInterface::setPeriod(AudioDevice* device)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WasapiInterface::SetBufferSize(const AudioDevicePtr& device)
|
void WasapiInterface::setBufferSize(AudioDevice* device)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WasapiInterface::SetChannelNumber(const AudioDevicePtr& device)
|
void WasapiInterface::setChannelNumber(AudioDevice* device)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -76,7 +77,7 @@ const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
|
||||||
const IID IID_IAudioClient = __uuidof(IAudioClient);
|
const IID IID_IAudioClient = __uuidof(IAudioClient);
|
||||||
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
|
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
|
||||||
|
|
||||||
void WasapiInterface::Play(const AudioDevicePtr& device)
|
void WasapiInterface::play(AudioDevice* device, AudioSample* sample, unsigned duration)
|
||||||
{
|
{
|
||||||
std::cout << "Into wasapi play" << std::endl;
|
std::cout << "Into wasapi play" << std::endl;
|
||||||
IMMDeviceEnumerator* pEnumerator = nullptr;
|
IMMDeviceEnumerator* pEnumerator = nullptr;
|
||||||
|
|
|
@ -1,36 +1,35 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "IAudioInterface.h"
|
#include "IAudioInterface.h"
|
||||||
#include "AudioDevice.h"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
class AudioDevice;
|
||||||
|
|
||||||
class WasapiInterface : public IAudioInterface
|
class WasapiInterface : public IAudioInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
WasapiInterface();
|
WasapiInterface();
|
||||||
|
|
||||||
~WasapiInterface();
|
~WasapiInterface();
|
||||||
|
|
||||||
static std::unique_ptr<WasapiInterface> Create();
|
static std::unique_ptr<WasapiInterface> Create();
|
||||||
|
|
||||||
void OpenDevice(const AudioDevicePtr& device) override;
|
void play(AudioDevice* device, AudioSample* sample, unsigned duration) override;
|
||||||
|
private:
|
||||||
|
void openDevice(AudioDevice* device) override;
|
||||||
|
|
||||||
void SetAccessType(const AudioDevicePtr& device);
|
void setAccessType(AudioDevice* device);
|
||||||
|
|
||||||
void SetSampleFormat(const AudioDevicePtr& device);
|
void setSampleFormat(AudioDevice* device);
|
||||||
|
|
||||||
void SetSampleRate(const AudioDevicePtr& device);
|
void setSampleRate(AudioDevice* device);
|
||||||
|
|
||||||
void SetPeriod(const AudioDevicePtr& device);
|
void setPeriod(AudioDevice* device);
|
||||||
|
|
||||||
void SetBufferSize(const AudioDevicePtr& device);
|
void setBufferSize(AudioDevice* device);
|
||||||
|
|
||||||
void SetChannelNumber(const AudioDevicePtr& device);
|
void setChannelNumber(AudioDevice* device);
|
||||||
|
|
||||||
void Play(const AudioDevicePtr& device) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using AlsaInterfacePtr = std::shared_ptr<WasapiInterface>;
|
using WasapiInterfacePtr = std::unique_ptr<WasapiInterface>;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
|
||||||
int MidiChannelEventAdapter::ReadEvent(std::ifstream* file, char firstByte, MidiChannelEvent* event, MidiChannelEvent::Type& lastEventType)
|
int MidiChannelEventAdapter::readEvent(std::ifstream* file, char firstByte, MidiChannelEvent* event, MidiChannelEvent::Type& lastEventType)
|
||||||
{
|
{
|
||||||
int first_four_bits = 0xF0;
|
int first_four_bits = 0xF0;
|
||||||
int second_four_bits = 0xF;
|
int second_four_bits = 0xF;
|
||||||
|
@ -34,11 +34,11 @@ int MidiChannelEventAdapter::ReadEvent(std::ifstream* file, char firstByte, Midi
|
||||||
{
|
{
|
||||||
if (isStatusByte)
|
if (isStatusByte)
|
||||||
{
|
{
|
||||||
byteCount += ReadEventData(file, event);
|
byteCount += readEventData(file, event);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
byteCount += ReadEventData(file, event, firstByte);
|
byteCount += readEventData(file, event, firstByte);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ int MidiChannelEventAdapter::ReadEvent(std::ifstream* file, char firstByte, Midi
|
||||||
return byteCount;
|
return byteCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MidiChannelEventAdapter::ReadEventData(std::ifstream* file, MidiChannelEvent* event, char c)
|
int MidiChannelEventAdapter::readEventData(std::ifstream* file, MidiChannelEvent* event, char c)
|
||||||
{
|
{
|
||||||
int value0 = int(c);
|
int value0 = int(c);
|
||||||
int value1 = *BinaryStream::getNextByteAsInt(file);
|
int value1 = *BinaryStream::getNextByteAsInt(file);
|
||||||
|
@ -63,7 +63,7 @@ int MidiChannelEventAdapter::ReadEventData(std::ifstream* file, MidiChannelEvent
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MidiChannelEventAdapter::ReadEventData(std::ifstream* file, MidiChannelEvent* event)
|
int MidiChannelEventAdapter::readEventData(std::ifstream* file, MidiChannelEvent* event)
|
||||||
{
|
{
|
||||||
int value0 = *BinaryStream::getNextByteAsInt(file);
|
int value0 = *BinaryStream::getNextByteAsInt(file);
|
||||||
int value1 = *BinaryStream::getNextByteAsInt(file);
|
int value1 = *BinaryStream::getNextByteAsInt(file);
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
class MidiChannelEventAdapter
|
class MidiChannelEventAdapter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static int ReadEvent(std::ifstream* file, char firstByte, MidiChannelEvent* event, MidiChannelEvent::Type& lastEventType);
|
static int readEvent(std::ifstream* file, char firstByte, MidiChannelEvent* event, MidiChannelEvent::Type& lastEventType);
|
||||||
|
|
||||||
static int ReadEventData(std::ifstream* file, MidiChannelEvent* event, char c);
|
static int readEventData(std::ifstream* file, MidiChannelEvent* event, char c);
|
||||||
static int ReadEventData(std::ifstream* file, MidiChannelEvent* event);
|
static int readEventData(std::ifstream* file, MidiChannelEvent* event);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,11 +3,9 @@
|
||||||
#include "MetaMidiEvent.h"
|
#include "MetaMidiEvent.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
class MidiMetaEventAdapter
|
class MidiMetaEventAdapter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static int ReadEvent(std::ifstream* file, MetaMidiEvent* event, int& lastMidiChannel);
|
static int ReadEvent(std::ifstream* file, MetaMidiEvent* event, int& lastMidiChannel);
|
||||||
|
|
||||||
static int ReadIntEvent(std::ifstream* file, MetaMidiEvent* event, int length=-1);
|
static int ReadIntEvent(std::ifstream* file, MetaMidiEvent* event, int length=-1);
|
||||||
|
|
|
@ -87,7 +87,7 @@ int MidiReader::processEvent(MidiTrack* track)
|
||||||
auto event = std::make_unique<MidiChannelEvent>();
|
auto event = std::make_unique<MidiChannelEvent>();
|
||||||
event->SetTimeDelta(timeDelta);
|
event->SetTimeDelta(timeDelta);
|
||||||
//std::cout << "Midi event" << std::endl;
|
//std::cout << "Midi event" << std::endl;
|
||||||
byteCount += MidiChannelEventAdapter::ReadEvent(mFile->getInHandle(), c, event.get(), mLastChannelEventType);
|
byteCount += MidiChannelEventAdapter::readEvent(mFile->getInHandle(), c, event.get(), mLastChannelEventType);
|
||||||
track->AddEvent(std::move(event));
|
track->AddEvent(std::move(event));
|
||||||
}
|
}
|
||||||
return byteCount;
|
return byteCount;
|
||||||
|
|
|
@ -29,6 +29,11 @@ AbstractApp* GuiApplication::getMainApplication() const
|
||||||
return mMainApplication.get();
|
return mMainApplication.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractUIInterface* GuiApplication::getUiInterface() const
|
||||||
|
{
|
||||||
|
return mUiInterface.get();
|
||||||
|
}
|
||||||
|
|
||||||
void GuiApplication::initializeViews()
|
void GuiApplication::initializeViews()
|
||||||
{
|
{
|
||||||
mDesktopManager->getWindowManager()->getMainWindow()->setSize(800, 600);
|
mDesktopManager->getWindowManager()->getMainWindow()->setSize(800, 600);
|
||||||
|
|
|
@ -21,10 +21,7 @@ public:
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
AbstractUIInterface* getUiInterface() const override
|
AbstractUIInterface* getUiInterface() const override;
|
||||||
{
|
|
||||||
return mUiInterface.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setUiInterfaceBackend(UiInterfaceFactory::Backend backend);
|
void setUiInterfaceBackend(UiInterfaceFactory::Backend backend);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
class StatusBar : public Widget
|
class StatusBar : public Widget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
StatusBar();
|
StatusBar();
|
||||||
|
|
||||||
static std::unique_ptr<StatusBar> Create();
|
static std::unique_ptr<StatusBar> Create();
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
class TabbedPanelWidget : public Widget
|
class TabbedPanelWidget : public Widget
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TabbedPanelWidget();
|
TabbedPanelWidget();
|
||||||
|
|
||||||
|
|
|
@ -1,187 +1,189 @@
|
||||||
#include "TemplateFile.h"
|
#include "TemplateFile.h"
|
||||||
|
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
TemplateFile::TemplateFile(const Path& path)
|
TemplateFile::TemplateFile(const Path& path)
|
||||||
: mPath(path),
|
: mPath(path),
|
||||||
mRootNode(std::make_unique<TemplateNode>(nullptr))
|
mRootNode(std::make_unique<TemplateNode>(nullptr))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> TemplateFile::getProcessedContent() const
|
std::vector<std::string> TemplateFile::getProcessedContent() const
|
||||||
{
|
{
|
||||||
return mProcessedContent;
|
return mProcessedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TemplateFile::getName() const
|
std::string TemplateFile::getName() const
|
||||||
{
|
{
|
||||||
return mPath.stem().string();
|
return mPath.stem().string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateFile::loadContent()
|
void TemplateFile::loadContent()
|
||||||
{
|
{
|
||||||
//std::cout << "Trying to load file at: " << mPath << std::endl;
|
//std::cout << "Trying to load file at: " << mPath << std::endl;
|
||||||
mRawContent = File(mPath).readLines();
|
mRawContent = File(mPath).readLines();
|
||||||
mWorkingLine = 0;
|
mWorkingLine = 0;
|
||||||
mWorkingNode = mRootNode.get();
|
mWorkingNode = mRootNode.get();
|
||||||
mWorkingTextBody = std::make_unique<TemplateTextBody>(mWorkingNode);
|
mWorkingTextBody = std::make_unique<TemplateTextBody>(mWorkingNode);
|
||||||
for (const auto& line : mRawContent)
|
for (const auto& line : mRawContent)
|
||||||
{
|
{
|
||||||
processLine(line);
|
processLine(line);
|
||||||
mWorkingLine++;
|
mWorkingLine++;
|
||||||
}
|
}
|
||||||
onTextBodyFinished();
|
onTextBodyFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateFile::onTextBodyFinished(std::string working_string)
|
void TemplateFile::onTextBodyFinished(std::string working_string)
|
||||||
{
|
{
|
||||||
if (!working_string.empty())
|
if (!working_string.empty())
|
||||||
{
|
{
|
||||||
mWorkingTextBody->addLine(working_string);
|
mWorkingTextBody->addLine(working_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mWorkingTextBody->hasContent())
|
if (mWorkingTextBody->hasContent())
|
||||||
{
|
{
|
||||||
mWorkingNode->addChild(std::move(mWorkingTextBody));
|
mWorkingNode->addChild(std::move(mWorkingTextBody));
|
||||||
mWorkingTextBody = std::make_unique<TemplateTextBody>(mWorkingNode);
|
mWorkingTextBody = std::make_unique<TemplateTextBody>(mWorkingNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateFile::processLine(const std::string& line)
|
void TemplateFile::processLine(const std::string& line)
|
||||||
{
|
{
|
||||||
bool last_was_ldelimiter{ false };
|
bool last_was_ldelimiter{ false };
|
||||||
bool last_was_statement_rdelimiter{ false };
|
bool last_was_statement_rdelimiter{ false };
|
||||||
bool last_was_expression_rdelimiter{ false };
|
bool last_was_expression_rdelimiter{ false };
|
||||||
bool in_statement{ false };
|
bool in_statement{ false };
|
||||||
bool in_expression{ false };
|
bool in_expression{ false };
|
||||||
std::string working_string;
|
std::string working_string;
|
||||||
std::string last_working_string;
|
std::string last_working_string;
|
||||||
for (auto c : line)
|
for (auto c : line)
|
||||||
{
|
{
|
||||||
if (c == '{')
|
if (c == '{')
|
||||||
{
|
{
|
||||||
if (last_was_ldelimiter)
|
if (last_was_ldelimiter)
|
||||||
{
|
{
|
||||||
in_expression = true;
|
in_expression = true;
|
||||||
last_was_ldelimiter = false;
|
last_was_ldelimiter = false;
|
||||||
working_string = "";
|
working_string = "";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
last_was_ldelimiter = true;
|
last_was_ldelimiter = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (c == '%' && last_was_ldelimiter)
|
else if (c == '%' && last_was_ldelimiter)
|
||||||
{
|
{
|
||||||
last_was_ldelimiter = false;
|
last_was_ldelimiter = false;
|
||||||
in_statement = true;
|
in_statement = true;
|
||||||
last_working_string = working_string;
|
last_working_string = working_string;
|
||||||
working_string = "";
|
working_string = "";
|
||||||
}
|
}
|
||||||
else if (c == '%' && in_statement)
|
else if (c == '%' && in_statement)
|
||||||
{
|
{
|
||||||
last_was_statement_rdelimiter = true;
|
last_was_statement_rdelimiter = true;
|
||||||
}
|
}
|
||||||
else if (c == '}' && (last_was_statement_rdelimiter || in_expression || last_was_expression_rdelimiter))
|
else if (c == '}' && (last_was_statement_rdelimiter || in_expression || last_was_expression_rdelimiter))
|
||||||
{
|
{
|
||||||
if (last_was_statement_rdelimiter)
|
if (last_was_statement_rdelimiter)
|
||||||
{
|
{
|
||||||
onTextBodyFinished(last_working_string);
|
onTextBodyFinished(last_working_string);
|
||||||
onFoundStatement(working_string);
|
onFoundStatement(working_string);
|
||||||
last_was_statement_rdelimiter = false;
|
last_was_statement_rdelimiter = false;
|
||||||
working_string = "";
|
working_string = "";
|
||||||
}
|
}
|
||||||
else if (in_expression)
|
else if (in_expression)
|
||||||
{
|
{
|
||||||
last_was_expression_rdelimiter = true;
|
last_was_expression_rdelimiter = true;
|
||||||
in_expression = false;
|
in_expression = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
onTextBodyFinished();
|
onTextBodyFinished();
|
||||||
onFoundExpression(working_string);
|
onFoundExpression(working_string);
|
||||||
last_was_expression_rdelimiter = false;
|
last_was_expression_rdelimiter = false;
|
||||||
working_string = "";
|
working_string = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (last_was_ldelimiter && (!in_statement && !in_expression))
|
else if (last_was_ldelimiter && (!in_statement && !in_expression))
|
||||||
{
|
{
|
||||||
last_was_ldelimiter = false;
|
last_was_ldelimiter = false;
|
||||||
working_string += '{';
|
working_string += '{';
|
||||||
working_string += c;
|
working_string += c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
working_string += c;
|
working_string += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!working_string.empty())
|
if (!working_string.empty())
|
||||||
{
|
{
|
||||||
mWorkingTextBody->addLine(working_string);
|
mWorkingTextBody->addLine(working_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateFile::onFoundStatement(const std::string& statement_string)
|
void TemplateFile::onFoundStatement(const std::string& statement_string)
|
||||||
{
|
{
|
||||||
const auto statement_elements = StringUtils::split(statement_string);
|
const auto statement_elements = StringUtils::split(statement_string);
|
||||||
|
|
||||||
if (statement_elements.size() == 0)
|
if (statement_elements.size() == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto statement_type = statement_elements[0];
|
const auto statement_type = statement_elements[0];
|
||||||
if (statement_type == "block" && statement_elements.size() == 2)
|
if (statement_type == "block" && statement_elements.size() == 2)
|
||||||
{
|
{
|
||||||
onFoundBlock(statement_elements);
|
onFoundBlock(statement_elements);
|
||||||
}
|
}
|
||||||
else if (statement_type == "endblock")
|
else if (statement_type == "endblock")
|
||||||
{
|
{
|
||||||
onFoundEndBlock(statement_elements);
|
onFoundEndBlock(statement_elements);
|
||||||
}
|
}
|
||||||
else if (statement_type == "extends")
|
else if (statement_type == "extends")
|
||||||
{
|
{
|
||||||
onFoundExtends(statement_elements);
|
onFoundExtends(statement_elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateFile::onFoundBlock(const std::vector<std::string> args)
|
void TemplateFile::onFoundBlock(const std::vector<std::string> args)
|
||||||
{
|
{
|
||||||
if (args.size() != 2)
|
if (args.size() != 2)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto block = std::make_unique<TemplateBlock>(mWorkingNode, args[1]);
|
auto block = std::make_unique<TemplateBlock>(mWorkingNode, args[1]);
|
||||||
auto temp = block.get();
|
auto temp = block.get();
|
||||||
mWorkingNode->addChild(std::move(block));
|
mWorkingNode->addChild(std::move(block));
|
||||||
mWorkingNode = temp;
|
mWorkingNode = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateFile::onFoundEndBlock(const std::vector<std::string> args)
|
void TemplateFile::onFoundEndBlock(const std::vector<std::string> args)
|
||||||
{
|
{
|
||||||
mWorkingNode = mWorkingNode->getParent();
|
mWorkingNode = mWorkingNode->getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateFile::onFoundExtends(const std::vector<std::string> args)
|
void TemplateFile::onFoundExtends(const std::vector<std::string> args)
|
||||||
{
|
{
|
||||||
if (args.size() != 2)
|
if (args.size() != 2)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto extends = std::make_unique<TemplateExtends>(mWorkingNode, args[1]);
|
auto extends = std::make_unique<TemplateExtends>(mWorkingNode, args[1]);
|
||||||
mWorkingNode->addChild(std::move(extends));
|
mWorkingNode->addChild(std::move(extends));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateFile::onFoundExpression(const std::string& expression_string)
|
void TemplateFile::onFoundExpression(const std::string& expression_string)
|
||||||
{
|
{
|
||||||
auto expression = std::make_unique<TemplateExpression>(mWorkingNode, expression_string);
|
auto expression = std::make_unique<TemplateExpression>(mWorkingNode, expression_string);
|
||||||
mWorkingNode->addChild(std::move(expression));
|
mWorkingNode->addChild(std::move(expression));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateFile::dumpContent()
|
void TemplateFile::dumpContent()
|
||||||
{
|
{
|
||||||
auto content = mRootNode->getRawContent();
|
auto content = mRootNode->getRawContent();
|
||||||
//std::cout << content << std::endl;
|
//std::cout << content << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,42 +9,42 @@
|
||||||
class TemplateFile
|
class TemplateFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TemplateFile(const Path& path);
|
TemplateFile(const Path& path);
|
||||||
|
|
||||||
std::vector<std::string> getProcessedContent() const;
|
std::vector<std::string> getProcessedContent() const;
|
||||||
|
|
||||||
std::string getName() const;
|
std::string getName() const;
|
||||||
|
|
||||||
void loadContent();
|
void loadContent();
|
||||||
|
|
||||||
void onTextBodyFinished(std::string working_string = {});
|
void onTextBodyFinished(std::string working_string = {});
|
||||||
|
|
||||||
void processLine(const std::string& line);
|
void processLine(const std::string& line);
|
||||||
|
|
||||||
void onFoundStatement(const std::string& statement_string);
|
void onFoundStatement(const std::string& statement_string);
|
||||||
|
|
||||||
void onFoundBlock(const std::vector<std::string> args);
|
void onFoundBlock(const std::vector<std::string> args);
|
||||||
|
|
||||||
void onFoundEndBlock(const std::vector<std::string> args);
|
void onFoundEndBlock(const std::vector<std::string> args);
|
||||||
|
|
||||||
void onFoundExtends(const std::vector<std::string> args);
|
void onFoundExtends(const std::vector<std::string> args);
|
||||||
|
|
||||||
void onFoundExpression(const std::string& expression_string);
|
void onFoundExpression(const std::string& expression_string);
|
||||||
|
|
||||||
void dumpContent();
|
void dumpContent();
|
||||||
|
|
||||||
TemplateNode* getContent() const
|
TemplateNode* getContent() const
|
||||||
{
|
{
|
||||||
return mRootNode.get();
|
return mRootNode.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Path mPath;
|
Path mPath;
|
||||||
unsigned mWorkingLine{ 0 };
|
unsigned mWorkingLine{ 0 };
|
||||||
std::string mParentName;
|
std::string mParentName;
|
||||||
std::vector<std::string> mRawContent;
|
std::vector<std::string> mRawContent;
|
||||||
std::vector<std::string> mProcessedContent;
|
std::vector<std::string> mProcessedContent;
|
||||||
std::unique_ptr<TemplateNode> mRootNode;
|
std::unique_ptr<TemplateNode> mRootNode;
|
||||||
TemplateNode* mWorkingNode{ nullptr };
|
TemplateNode* mWorkingNode{ nullptr };
|
||||||
std::unique_ptr<TemplateTextBody> mWorkingTextBody;
|
std::unique_ptr<TemplateTextBody> mWorkingTextBody;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,169 @@
|
||||||
|
#include "TemplateNodes.h"
|
||||||
|
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
|
TemplateNode::TemplateNode(TemplateNode* parent)
|
||||||
|
: mParent(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateNode* TemplateNode::getParent() const
|
||||||
|
{
|
||||||
|
return mParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateNode::addChild(std::unique_ptr<TemplateNode> child)
|
||||||
|
{
|
||||||
|
mChildren.push_back(std::move(child));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t TemplateNode::getNumChildren() const
|
||||||
|
{
|
||||||
|
return mChildren.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateNode::getIdentifier() const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateNode* TemplateNode::getChild(std::size_t index) const
|
||||||
|
{
|
||||||
|
return mChildren[index].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateNode::getRawContent() const
|
||||||
|
{
|
||||||
|
std::string content;
|
||||||
|
for (const auto& child : mChildren)
|
||||||
|
{
|
||||||
|
content += child->getRawContent() + "\n";
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateNode::setExtensionParent(TemplateNode* parent)
|
||||||
|
{
|
||||||
|
mExtensionParent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateNode::render(TemplateNode* parentContext)
|
||||||
|
{
|
||||||
|
if (!parentContext && mExtensionParent)
|
||||||
|
{
|
||||||
|
parentContext = mExtensionParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string content;
|
||||||
|
for (size_t idx = 0; idx < mChildren.size(); idx++)
|
||||||
|
{
|
||||||
|
content += mChildren[idx]->render(parentContext);
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateExtends::TemplateExtends(TemplateNode* parent, const std::string& path)
|
||||||
|
: TemplateNode(parent)
|
||||||
|
{
|
||||||
|
mPath = StringUtils::stripQuotes(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string TemplateExtends::getRawContent() const
|
||||||
|
{
|
||||||
|
return "TemplateExtends: " + mPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateExtends::getPath() const
|
||||||
|
{
|
||||||
|
return mPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateBlock::TemplateBlock(TemplateNode* parent, const std::string& name)
|
||||||
|
: TemplateNode(parent),
|
||||||
|
mName(name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateBlock::addLine(const std::string& line)
|
||||||
|
{
|
||||||
|
mBody.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateBlock::getRawContent() const
|
||||||
|
{
|
||||||
|
std::string content = "TemplateBlock: " + mName + "\n";
|
||||||
|
content += TemplateNode::getRawContent();
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateBlock::renderAsParent(TemplateNode* base)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateBlock::render(TemplateNode* parentContext)
|
||||||
|
{
|
||||||
|
std::string content;
|
||||||
|
if (parentContext)
|
||||||
|
{
|
||||||
|
if (auto parent_node = parentContext->getFirstChildShallow<TemplateBlock>(getIdentifier()))
|
||||||
|
{
|
||||||
|
content = dynamic_cast<TemplateBlock*>(parent_node)->renderAsParent(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateExpression::TemplateExpression(TemplateNode* parent, const std::string& content)
|
||||||
|
: TemplateNode(parent),
|
||||||
|
mContent(content)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateExpression::getRawContent() const
|
||||||
|
{
|
||||||
|
return "TemplateExpression: " + mContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateTextBody::TemplateTextBody(TemplateNode* parent)
|
||||||
|
: TemplateNode(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateTextBody::addLine(const std::string& content)
|
||||||
|
{
|
||||||
|
mContent.push_back(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TemplateTextBody::hasContent() const
|
||||||
|
{
|
||||||
|
return !mContent.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateTextBody::render(TemplateNode* parentContext)
|
||||||
|
{
|
||||||
|
std::string content;
|
||||||
|
for (const auto& line : mContent)
|
||||||
|
{
|
||||||
|
content += line + '\n';
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TemplateTextBody::getRawContent() const
|
||||||
|
{
|
||||||
|
std::string content;
|
||||||
|
for (const auto& line : mContent)
|
||||||
|
{
|
||||||
|
content += "TemplateBody: " + line + "\n";
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
|
@ -1,97 +1,59 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class TemplateNode
|
class TemplateNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
TemplateNode(TemplateNode* parent);
|
||||||
|
|
||||||
TemplateNode(TemplateNode* parent)
|
virtual ~TemplateNode() = default;
|
||||||
: mParent(parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
TemplateNode* getParent() const;
|
||||||
|
|
||||||
TemplateNode* getParent() const
|
virtual void addChild(std::unique_ptr<TemplateNode> child);
|
||||||
{
|
|
||||||
return mParent;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void addChild(std::unique_ptr<TemplateNode> child)
|
std::size_t getNumChildren() const;
|
||||||
{
|
|
||||||
mChildren.push_back(std::move(child));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t getNumChildren() const
|
virtual std::string getIdentifier() const;
|
||||||
{
|
|
||||||
return mChildren.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::string getIdentifier() const
|
TemplateNode* getChild(std::size_t index) const;
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
TemplateNode* getChild(std::size_t index) const
|
virtual std::string getRawContent() const;
|
||||||
{
|
|
||||||
return mChildren[index].get();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::string getRawContent() const
|
template<typename T>
|
||||||
{
|
T* getFirstChildShallow(const std::string& identifier = {}) const
|
||||||
std::string content;
|
{
|
||||||
for (const auto& child : mChildren)
|
for (const auto& child : mChildren)
|
||||||
{
|
{
|
||||||
content += child->getRawContent() + "\n";
|
if (auto ret = dynamic_cast<T*>(child.get()))
|
||||||
}
|
{
|
||||||
return content;
|
if (!identifier.empty())
|
||||||
}
|
{
|
||||||
|
if (child->getIdentifier() == identifier)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
void setExtensionParent(TemplateNode* parent);
|
||||||
T* getFirstChildShallow(const std::string& identifier = {}) const
|
|
||||||
{
|
|
||||||
for (const auto& child : mChildren)
|
|
||||||
{
|
|
||||||
if (auto ret = dynamic_cast<T*>(child.get()))
|
|
||||||
{
|
|
||||||
if (!identifier.empty())
|
|
||||||
{
|
|
||||||
if (child->getIdentifier() == identifier)
|
|
||||||
{
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setExtensionParent(TemplateNode* parent)
|
virtual std::string render(TemplateNode* parentContext = nullptr);
|
||||||
{
|
|
||||||
mExtensionParent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::string render(TemplateNode* parentContext = nullptr)
|
|
||||||
{
|
|
||||||
if (!parentContext && mExtensionParent)
|
|
||||||
{
|
|
||||||
parentContext = mExtensionParent;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string content;
|
|
||||||
for (size_t idx = 0; idx < mChildren.size(); idx++)
|
|
||||||
{
|
|
||||||
content += mChildren[idx]->render(parentContext);
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::unique_ptr<TemplateNode> > mChildren;
|
std::vector<std::unique_ptr<TemplateNode> > mChildren;
|
||||||
TemplateNode* mParent{ nullptr };
|
TemplateNode* mParent{ nullptr };
|
||||||
TemplateNode* mExtensionParent{ nullptr };
|
TemplateNode* mExtensionParent{ nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
using TemplateNodePtr = std::unique_ptr<TemplateNode>;
|
using TemplateNodePtr = std::unique_ptr<TemplateNode>;
|
||||||
|
@ -99,133 +61,64 @@ using TemplateNodePtr = std::unique_ptr<TemplateNode>;
|
||||||
class TemplateExtends : public TemplateNode
|
class TemplateExtends : public TemplateNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TemplateExtends(TemplateNode* parent, const std::string& path)
|
TemplateExtends(TemplateNode* parent, const std::string& path);
|
||||||
: TemplateNode(parent)
|
|
||||||
{
|
|
||||||
mPath = StringUtils::stripQuotes(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string getRawContent() const override
|
virtual ~TemplateExtends() = default;
|
||||||
{
|
|
||||||
return "TemplateExtends: " + mPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string getPath() const
|
std::string getRawContent() const override;
|
||||||
{
|
std::string getPath() const;
|
||||||
return mPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mPath;
|
std::string mPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TemplateBlock : public TemplateNode
|
class TemplateBlock : public TemplateNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TemplateBlock(TemplateNode* parent, const std::string& name)
|
TemplateBlock(TemplateNode* parent, const std::string& name);
|
||||||
: TemplateNode(parent),
|
|
||||||
mName(name)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
virtual ~TemplateBlock() = default;
|
||||||
|
|
||||||
void addLine(const std::string& line)
|
void addLine(const std::string& line);
|
||||||
{
|
|
||||||
mBody.push_back(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string getRawContent() const override
|
std::string getRawContent() const override;
|
||||||
{
|
|
||||||
std::string content = "TemplateBlock: " + mName + "\n";
|
|
||||||
content += TemplateNode::getRawContent();
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string renderAsParent(TemplateNode* base)
|
std::string renderAsParent(TemplateNode* base);
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string render(TemplateNode* parentContext) override
|
std::string render(TemplateNode* parentContext) override;
|
||||||
{
|
|
||||||
std::string content;
|
|
||||||
if (parentContext)
|
|
||||||
{
|
|
||||||
if (auto parent_node = parentContext->getFirstChildShallow<TemplateBlock>(getIdentifier()))
|
|
||||||
{
|
|
||||||
content = dynamic_cast<TemplateBlock*>(parent_node)->renderAsParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mName;
|
std::string mName;
|
||||||
std::vector<std::string> mBody;
|
std::vector<std::string> mBody;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TemplateExpression : public TemplateNode
|
class TemplateExpression : public TemplateNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TemplateExpression(TemplateNode* parent, const std::string& content)
|
TemplateExpression(TemplateNode* parent, const std::string& content);
|
||||||
: TemplateNode(parent),
|
|
||||||
mContent(content)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
virtual ~TemplateExpression() = default;
|
||||||
|
|
||||||
std::string getRawContent() const override
|
std::string getRawContent() const override;
|
||||||
{
|
|
||||||
return "TemplateExpression: " + mContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mContent;
|
std::string mContent;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TemplateTextBody : public TemplateNode
|
class TemplateTextBody : public TemplateNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TemplateTextBody(TemplateNode* parent)
|
TemplateTextBody(TemplateNode* parent);
|
||||||
: TemplateNode(parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
virtual ~TemplateTextBody() = default;
|
||||||
|
|
||||||
void addLine(const std::string& content)
|
void addLine(const std::string& content);
|
||||||
{
|
|
||||||
mContent.push_back(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasContent() const
|
std::string getRawContent() const override;
|
||||||
{
|
|
||||||
return !mContent.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string render(TemplateNode* parentContext) override
|
bool hasContent() const;
|
||||||
{
|
|
||||||
std::string content;
|
|
||||||
for (const auto& line : mContent)
|
|
||||||
{
|
|
||||||
content += line + '\n';
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string getRawContent() const override
|
|
||||||
{
|
|
||||||
std::string content;
|
|
||||||
for (const auto& line : mContent)
|
|
||||||
{
|
|
||||||
content += "TemplateBody: " + line + "\n";
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
std::string render(TemplateNode* parentContext) override;
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> mContent;
|
std::vector<std::string> mContent;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,20 +9,20 @@
|
||||||
class TemplatingEngine
|
class TemplatingEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TemplatingEngine(const Path& workingDirectory);
|
TemplatingEngine(const Path& workingDirectory);
|
||||||
|
|
||||||
void loadTemplateFiles();
|
void loadTemplateFiles();
|
||||||
|
|
||||||
std::string processTemplate(const std::string& name);
|
std::string processTemplate(const std::string& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TemplateFile* getTemplateFile(const std::string& name);
|
TemplateFile* getTemplateFile(const std::string& name);
|
||||||
TemplateFile* getTemplateFile(const Path& path);
|
TemplateFile* getTemplateFile(const Path& path);
|
||||||
std::string render(TemplateNode* content);
|
std::string render(TemplateNode* content);
|
||||||
|
|
||||||
std::string processTemplate(TemplateFile* file, TemplateNode* parent = nullptr);
|
std::string processTemplate(TemplateFile* file, TemplateNode* parent = nullptr);
|
||||||
|
|
||||||
std::vector<std::unique_ptr<TemplateFile> > mTemplateFiles;
|
std::vector<std::unique_ptr<TemplateFile> > mTemplateFiles;
|
||||||
Path mWorkingDirectory;
|
Path mWorkingDirectory;
|
||||||
std::string mTemplateExtension{ ".html" };
|
std::string mTemplateExtension{ ".html" };
|
||||||
};
|
};
|
||||||
|
|
|
@ -131,7 +131,7 @@ void File::close()
|
||||||
FileFormat::Format File::inferFormat() const
|
FileFormat::Format File::inferFormat() const
|
||||||
{
|
{
|
||||||
const auto extension = getExtension();
|
const auto extension = getExtension();
|
||||||
return FileFormat::InferFormat(extension);
|
return FileFormat::inferFormat(extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
void File::writeText(const std::string& text)
|
void File::writeText(const std::string& text)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "FileFormats.h"
|
#include "FileFormats.h"
|
||||||
|
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
FileFormat::ExtensionMap FileFormat::mExtensions = []
|
FileFormat::ExtensionMap FileFormat::mExtensions = []
|
||||||
{
|
{
|
||||||
ExtensionMap ret;
|
ExtensionMap ret;
|
||||||
|
@ -8,3 +10,25 @@ FileFormat::ExtensionMap FileFormat::mExtensions = []
|
||||||
ret[Format::Wav] = ".wav";
|
ret[Format::Wav] = ".wav";
|
||||||
return ret;
|
return ret;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
bool FileFormat::isFormat(const std::string& extension, Format format)
|
||||||
|
{
|
||||||
|
return StringUtils::ToLower(extension) == mExtensions[format];
|
||||||
|
}
|
||||||
|
|
||||||
|
FileFormat::Format FileFormat::inferFormat(const std::string& query)
|
||||||
|
{
|
||||||
|
for(const auto& extension : mExtensions)
|
||||||
|
{
|
||||||
|
if(extension.second == query)
|
||||||
|
{
|
||||||
|
return extension.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Format::Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FileFormat::getExtension(Format format)
|
||||||
|
{
|
||||||
|
return mExtensions[format];
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "StringUtils.h"
|
|
||||||
|
|
||||||
class FileFormat{
|
class FileFormat{
|
||||||
|
|
||||||
|
@ -27,31 +26,14 @@ public:
|
||||||
|
|
||||||
using ExtensionMap = std::map<Format, std::string>;
|
using ExtensionMap = std::map<Format, std::string>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static bool isFormat(const std::string& extension, Format format);
|
||||||
|
|
||||||
|
static Format inferFormat(const std::string& query);
|
||||||
|
|
||||||
|
static std::string getExtension(Format format);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static ExtensionMap mExtensions;
|
static ExtensionMap mExtensions;
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
bool IsFormat(const std::string& extension, Format format)
|
|
||||||
{
|
|
||||||
return StringUtils::ToLower(extension) == mExtensions[format];
|
|
||||||
}
|
|
||||||
|
|
||||||
static Format InferFormat(const std::string& query)
|
|
||||||
{
|
|
||||||
for(const auto& extension : mExtensions)
|
|
||||||
{
|
|
||||||
if(extension.second == query)
|
|
||||||
{
|
|
||||||
return extension.first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Format::Unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetExtension(Format format)
|
|
||||||
{
|
|
||||||
return mExtensions[format];
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,77 +4,77 @@
|
||||||
|
|
||||||
void HttpHeader::parse(const std::vector<std::string >& message)
|
void HttpHeader::parse(const std::vector<std::string >& message)
|
||||||
{
|
{
|
||||||
std::string tag;
|
std::string tag;
|
||||||
std::string value;
|
std::string value;
|
||||||
bool foundDelimiter{false};
|
bool foundDelimiter{false};
|
||||||
for (const auto& line : message)
|
for (const auto& line : message)
|
||||||
{
|
{
|
||||||
for(std::size_t idx = 0; idx< line.size(); idx++)
|
for(std::size_t idx = 0; idx< line.size(); idx++)
|
||||||
{
|
{
|
||||||
const auto c = line[idx];
|
const auto c = line[idx];
|
||||||
if (c == StringUtils::COLON)
|
if (c == StringUtils::COLON)
|
||||||
{
|
{
|
||||||
foundDelimiter = true;
|
foundDelimiter = true;
|
||||||
}
|
}
|
||||||
else if(foundDelimiter)
|
else if(foundDelimiter)
|
||||||
{
|
{
|
||||||
value.push_back(c);
|
value.push_back(c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tag.push_back(c);
|
tag.push_back(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.empty() || value.empty())
|
if (tag.empty() || value.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == "Host")
|
if (tag == "Host")
|
||||||
{
|
{
|
||||||
mHost = value;
|
mHost = value;
|
||||||
}
|
}
|
||||||
else if (tag == "User-Agent")
|
else if (tag == "User-Agent")
|
||||||
{
|
{
|
||||||
mUserAgent = value;
|
mUserAgent = value;
|
||||||
}
|
}
|
||||||
else if (tag == "Accept")
|
else if (tag == "Accept")
|
||||||
{
|
{
|
||||||
mAccept = value;
|
mAccept = value;
|
||||||
}
|
}
|
||||||
else if (tag == "Accept-Language")
|
else if (tag == "Accept-Language")
|
||||||
{
|
{
|
||||||
mAcceptLanguage = value;
|
mAcceptLanguage = value;
|
||||||
}
|
}
|
||||||
else if (tag == "Accept-Encoding")
|
else if (tag == "Accept-Encoding")
|
||||||
{
|
{
|
||||||
mAcceptEncoding = value;
|
mAcceptEncoding = value;
|
||||||
}
|
}
|
||||||
else if (tag == "Connection")
|
else if (tag == "Connection")
|
||||||
{
|
{
|
||||||
mConnection = value;
|
mConnection = value;
|
||||||
}
|
}
|
||||||
else if (tag == "Referer")
|
else if (tag == "Referer")
|
||||||
{
|
{
|
||||||
mReferer = value;
|
mReferer = value;
|
||||||
}
|
}
|
||||||
else if (tag == "Sec-Fetch-Dest")
|
else if (tag == "Sec-Fetch-Dest")
|
||||||
{
|
{
|
||||||
mSecFetchDest = value;
|
mSecFetchDest = value;
|
||||||
}
|
}
|
||||||
else if (tag == "Sec-Fetch-Mode")
|
else if (tag == "Sec-Fetch-Mode")
|
||||||
{
|
{
|
||||||
mSecFetchMode = value;
|
mSecFetchMode = value;
|
||||||
}
|
}
|
||||||
else if (tag == "Sec-Fetch-Site")
|
else if (tag == "Sec-Fetch-Site")
|
||||||
{
|
{
|
||||||
mSecFetchSite = value;
|
mSecFetchSite = value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mOtherFields[tag] = value;
|
mOtherFields[tag] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,20 +7,20 @@
|
||||||
class HttpHeader
|
class HttpHeader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void parse(const std::vector<std::string >& message);
|
void parse(const std::vector<std::string >& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string mHost;
|
std::string mHost;
|
||||||
std::string mUserAgent;
|
std::string mUserAgent;
|
||||||
std::string mAccept;
|
std::string mAccept;
|
||||||
std::string mAcceptLanguage;
|
std::string mAcceptLanguage;
|
||||||
std::string mAcceptEncoding;
|
std::string mAcceptEncoding;
|
||||||
std::string mConnection;
|
std::string mConnection;
|
||||||
std::string mReferer;
|
std::string mReferer;
|
||||||
std::string mSecFetchDest;
|
std::string mSecFetchDest;
|
||||||
std::string mSecFetchMode;
|
std::string mSecFetchMode;
|
||||||
std::string mSecFetchSite;
|
std::string mSecFetchSite;
|
||||||
|
|
||||||
std::map<std::string, std::string> mOtherFields;
|
std::map<std::string, std::string> mOtherFields;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,63 +6,63 @@
|
||||||
|
|
||||||
void HttpRequest::parseMessage(const std::string& message)
|
void HttpRequest::parseMessage(const std::string& message)
|
||||||
{
|
{
|
||||||
std::stringstream ss(message);
|
std::stringstream ss(message);
|
||||||
|
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
bool firstLine {true};
|
bool firstLine {true};
|
||||||
|
|
||||||
std::vector<std::string> headers;
|
std::vector<std::string> headers;
|
||||||
while(std::getline(ss, buffer, '\n'))
|
while(std::getline(ss, buffer, '\n'))
|
||||||
{
|
{
|
||||||
if (firstLine)
|
if (firstLine)
|
||||||
{
|
{
|
||||||
parseFirstLine(buffer);
|
parseFirstLine(buffer);
|
||||||
firstLine = false;
|
firstLine = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
headers.push_back(buffer);
|
headers.push_back(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mHeader.parse(headers);
|
mHeader.parse(headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpRequest::parseFirstLine(const std::string& line)
|
void HttpRequest::parseFirstLine(const std::string& line)
|
||||||
{
|
{
|
||||||
bool inPath{false};
|
bool inPath{false};
|
||||||
bool inMethod{true};
|
bool inMethod{true};
|
||||||
bool inProtocol{false};
|
bool inProtocol{false};
|
||||||
|
|
||||||
for (std::size_t idx=0; idx<line.size();idx++)
|
for (std::size_t idx=0; idx<line.size();idx++)
|
||||||
{
|
{
|
||||||
const auto c = line[idx];
|
const auto c = line[idx];
|
||||||
if (inPath)
|
if (inPath)
|
||||||
{
|
{
|
||||||
if (StringUtils::IsSpace(c))
|
if (StringUtils::IsSpace(c))
|
||||||
{
|
{
|
||||||
inPath = false;
|
inPath = false;
|
||||||
inMethod = true;
|
inMethod = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mMethod.push_back(c);
|
mMethod.push_back(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (inMethod)
|
else if (inMethod)
|
||||||
{
|
{
|
||||||
if (StringUtils::IsSpace(c))
|
if (StringUtils::IsSpace(c))
|
||||||
{
|
{
|
||||||
inMethod = false;
|
inMethod = false;
|
||||||
inProtocol = true;
|
inProtocol = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mPath.push_back(c);
|
mPath.push_back(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (inProtocol)
|
else if (inProtocol)
|
||||||
{
|
{
|
||||||
mProtocolVersion.push_back(c);
|
mProtocolVersion.push_back(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,16 +7,16 @@
|
||||||
class HttpRequest
|
class HttpRequest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HttpRequest() = default;
|
HttpRequest() = default;
|
||||||
|
|
||||||
void parseMessage(const std::string& message);
|
void parseMessage(const std::string& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void parseFirstLine(const std::string& line);
|
void parseFirstLine(const std::string& line);
|
||||||
|
|
||||||
HttpHeader mHeader;
|
HttpHeader mHeader;
|
||||||
std::string mMethod;
|
std::string mMethod;
|
||||||
std::string mPath;
|
std::string mPath;
|
||||||
std::string mProtocolVersion;
|
std::string mProtocolVersion;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
|
|
||||||
class HttpResponse
|
class HttpResponse
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HttpResponse();
|
HttpResponse();
|
||||||
|
|
||||||
~HttpResponse();
|
~HttpResponse();
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "ZlibEncoder.h"
|
#include "ZlibEncoder.h"
|
||||||
#include "CyclicRedundancyChecker.h"
|
#include "CyclicRedundancyChecker.h"
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "BufferBitStream.h"
|
#include "BufferBitStream.h"
|
||||||
#include "OutputBitStream.h"
|
#include "OutputBitStream.h"
|
||||||
#include "ImageBitStream.h"
|
#include "ImageBitStream.h"
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
#include "PngFilter.h"
|
#include "PngFilter.h"
|
||||||
#include "Lz77Encoder.h"
|
#include "Lz77Encoder.h"
|
||||||
|
|
Loading…
Reference in a new issue