Compare commits

..

No commits in common. "849d8d8ca2ff8cd6acc5e0bc176e1da8e7dab58d" and "bb222fd84d7d0dd6bd75d12ccd2f6adf179c42c0" have entirely different histories.

706 changed files with 5203 additions and 9262 deletions

View file

@ -1,8 +1,10 @@
Notes Toolkit (NotesTK) is a set of tools for building applications focused on taking and organising notes.
Copyright (C) 2023 James Grogan (grogan.ox@gmail.com)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
See https://opensource.org/licenses/MIT

View file

@ -1,14 +1,61 @@
# Stuff From Scratch
# NotesTK
This is a hobby-repo I use for learning about different software technologies by trying to build stuff from scratch.
Notes Toolkit (NotesTK) is a set of tools for building applications focused on taking and organising notes, like study or research materials.
It covers a bunch of areas:
## Project Goals
* Build tooling
* Audio and Video
* 3D modelling
* Desktop window management and UIs
* Cross-platform
* Low third-party dependencies
* Permissive licensing
* Simplicity over performance
Nothing here should be used in a real project :)
## Project Status
🚨🚨🚨 The codebase is at a very early/prototype stage and under heavy active development🚨🚨🚨
In addition to feature development I've been using it to get up-to-speed on various media formats and desktop and rendering APIs. It is strongly recommended to only use it as a reading reference.
Expect:
* No Docs or tagged releases
* Large commits and significant breaking changes
* Unreliable/untested APIs
* Naive/low-performance implementations
The only currently recommended use case is if you are implementing some element of the library functionality and want to see how someone else has tackled it, maybe you will see something useful.
# Building
Many project features (e.g. Wayland integration) only build if suitable third-party dependencies are found on the system, otherwise they will be automatically disabled. You can find dependency requirements in the `README.md` file in each module's `src`directory.
A minimal set of dependencies for each platform are included below.
## Linux
Install dependencies:
```bash
sudo apt-get install build-essential pkg-config cmake
```
Build:
```bash
mkdir build
cd build
cmake $PATH_TO_SOURCE
make
apps/$NAME_OF_APP
```
## Windows
Tested with Visual Studio 17 with 'Desktop Development with C++' tooling, including ATL and Windows SDK 10 (10.0.19041.0). Additionally, install `cmake`.
```bash
mkdir build
cd build
cmake $PATH_TO_SOURCE
```
You can open the resulting `NotesTK.sln`in Visual Studio and build.

View file

@ -16,7 +16,7 @@
#include "DesktopManager.h"
#include "MainApplication.h"
NotesTk::NotesTk(Ptr<CommandLineArgs> args, Ptr<MainApplication> mainApp)
NotesTk::NotesTk(std::unique_ptr<CommandLineArgs> args, std::unique_ptr<MainApplication> mainApp)
: GuiApplication(std::move(args), std::move(mainApp))
{

View file

@ -5,7 +5,7 @@
class NotesTk : public GuiApplication
{
public:
NotesTk(Ptr<CommandLineArgs> args = nullptr, Ptr<MainApplication> mainApp = nullptr);
NotesTk(std::unique_ptr<CommandLineArgs> args = nullptr, std::unique_ptr<MainApplication> mainApp = nullptr);
protected:
void initializeViews() override;

View file

@ -12,7 +12,7 @@ AudioEditorView::AudioEditorView()
addWidget(std::move(label));
}
Ptr<AudioEditorView> AudioEditorView::Create()
std::unique_ptr<AudioEditorView> AudioEditorView::Create()
{
return std::make_unique<AudioEditorView>();
}

View file

@ -8,7 +8,7 @@ public:
AudioEditorView();
static Ptr<AudioEditorView> Create();
static std::unique_ptr<AudioEditorView> Create();
};
using AudioEditorViewUPtr = Ptr<AudioEditorView>;
using AudioEditorViewUPtr = std::unique_ptr<AudioEditorView>;

View file

@ -1,6 +1,6 @@
#include "CanvasController.h"
Ptr<CanvasController> CanvasController::Create()
std::unique_ptr<CanvasController> CanvasController::Create()
{
return std::make_unique<CanvasController>();
}

View file

@ -1,9 +1,9 @@
#pragma once
#include "Pointer.h"
#include <memory>
class CanvasController
{
public:
static Ptr<CanvasController> Create();
static std::unique_ptr<CanvasController> Create();
};

View file

@ -24,6 +24,6 @@ private:
CanvasDrawCommand mActiveDrawingCommand{CanvasDrawCommand::LINE};
Vector<Ptr<GeometryNode> > mSceneNodes;
std::vector<std::unique_ptr<GeometryNode> > mSceneNodes;
bool mContentDirty{false};
};

View file

@ -27,7 +27,7 @@ CanvasView::~CanvasView()
}
Ptr<CanvasView> CanvasView::Create()
std::unique_ptr<CanvasView> CanvasView::Create()
{
return std::make_unique<CanvasView>();
}
@ -70,7 +70,7 @@ void CanvasView::onDrawCommandChanged(CanvasDrawCommand command)
mDrawingArea->setActiveDrawingCommand(command);
}
Ptr<Widget> CanvasView::initializeCacheButtons()
std::unique_ptr<Widget> CanvasView::initializeCacheButtons()
{
auto saveButton = Button::Create();
saveButton->setLabel("Save");

View file

@ -13,17 +13,17 @@ public:
~CanvasView();
static Ptr<CanvasView> Create();
static std::unique_ptr<CanvasView> Create();
private:
void onDrawCommandChanged(CanvasDrawCommand command);
void initialize();
Ptr<Widget> initializeCacheButtons();
std::unique_ptr<Widget> initializeCacheButtons();
Ptr<CanvasController> mController;
std::unique_ptr<CanvasController> mController;
CanvasDrawingArea* mDrawingArea{nullptr};
};
using CanvasViewPtr = Ptr<CanvasView>;
using CanvasViewPtr = std::unique_ptr<CanvasView>;

View file

@ -28,7 +28,7 @@ ImageEditorView::~ImageEditorView()
}
Ptr<ImageEditorView> ImageEditorView::Create()
std::unique_ptr<ImageEditorView> ImageEditorView::Create()
{
return std::make_unique<ImageEditorView>();
}

View file

@ -10,7 +10,7 @@ public:
virtual ~ImageEditorView();
static Ptr<ImageEditorView> Create();
static std::unique_ptr<ImageEditorView> Create();
};
using ImageEditorViewUPtr = Ptr<ImageEditorView>;
using ImageEditorViewUPtr = std::unique_ptr<ImageEditorView>;

View file

@ -16,5 +16,5 @@ private:
unsigned mNumX{5};
unsigned mNumY{5};
Ptr<GridNode> mGridNode;
std::unique_ptr<GridNode> mGridNode;
};

View file

@ -13,8 +13,8 @@
#include "windows.h"
#include <iostream>
#include "Vector.h"
#include "String.h"
#include <vector>
#include <string>
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{

View file

@ -1,4 +1,4 @@
#include "Pointer.h"
#include <memory>
#include "NotesTk.h"
#include "MainApplication.h"
@ -12,7 +12,7 @@ int main(int argc, char *argv[])
// Start the gui app
auto app = NotesTk(std::move(args));
app.setUiInterfaceBackend(UiInterfaceFactory::Backend::WAYLAND_RASTER);
//app.setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER);
app.run();
return 0;

View file

@ -10,7 +10,7 @@
#include <iostream>
Ptr<MeshViewerView> MeshViewerView::Create()
std::unique_ptr<MeshViewerView> MeshViewerView::Create()
{
return std::make_unique<MeshViewerView>();
}

View file

@ -10,10 +10,10 @@ class MeshViewerView : public Widget
public:
MeshViewerView();
~MeshViewerView();
static Ptr<MeshViewerView> Create();
static std::unique_ptr<MeshViewerView> Create();
void doPaint(const PaintEvent* event) override;
private:
Ptr<AbstractMesh> mMesh;
Ptr<MeshNode> mMeshNode;
std::unique_ptr<AbstractMesh> mMesh;
std::unique_ptr<MeshNode> mMeshNode;
};

View file

@ -6,17 +6,17 @@ PlainTextDocument::PlainTextDocument()
}
Ptr<PlainTextDocument> PlainTextDocument::Create()
std::unique_ptr<PlainTextDocument> PlainTextDocument::Create()
{
return std::make_unique<PlainTextDocument>();
}
String PlainTextDocument::GetContent() const
std::string PlainTextDocument::GetContent() const
{
return mContent;
}
void PlainTextDocument::SetContent(const String& content)
void PlainTextDocument::SetContent(const std::string& content)
{
mContent = content;
}

View file

@ -1,24 +1,24 @@
#pragma once
#include "String.h"
#include "Pointer.h"
#include <string>
#include <memory>
class PlainTextDocument
{
String mContent;
std::string mContent;
public:
PlainTextDocument();
static Ptr<PlainTextDocument> Create();
static std::unique_ptr<PlainTextDocument> Create();
String GetContent() const;
std::string GetContent() const;
void SetContent(const String& content);
void SetContent(const std::string& content);
void Clear();
};
using PlainTextDocumentUPtr = Ptr<PlainTextDocument>;
using PlainTextDocumentUPtr = std::unique_ptr<PlainTextDocument>;

View file

@ -9,17 +9,17 @@ TextEditorController::TextEditorController()
}
Ptr<TextEditorController> TextEditorController::Create()
std::unique_ptr<TextEditorController> TextEditorController::Create()
{
return std::make_unique<TextEditorController>();
}
void TextEditorController::SetContent(const String& content)
void TextEditorController::SetContent(const std::string& content)
{
mModel->GetDocument()->SetContent(content);
}
String TextEditorController::GetContent() const
std::string TextEditorController::GetContent() const
{
return mModel->GetDocument()->GetContent();
}

View file

@ -1,5 +1,5 @@
#pragma once
#include "Pointer.h"
#include <memory>
#include <filesystem>
#include "TextEditorModel.h"
@ -9,7 +9,7 @@ public:
TextEditorController();
static Ptr<TextEditorController> Create();
static std::unique_ptr<TextEditorController> Create();
void OnSave();
@ -17,9 +17,9 @@ public:
void OnLoad();
String GetContent() const;
std::string GetContent() const;
void SetContent(const String& content);
void SetContent(const std::string& content);
void SetSavePath(const std::filesystem::path& path);
@ -31,4 +31,4 @@ private:
std::filesystem::path mLoadPath;
};
using TextEditorControllerUPtr = Ptr<TextEditorController>;
using TextEditorControllerUPtr = std::unique_ptr<TextEditorController>;

View file

@ -6,7 +6,7 @@ TextEditorModel::TextEditorModel()
}
Ptr<TextEditorModel> TextEditorModel::Create()
std::unique_ptr<TextEditorModel> TextEditorModel::Create()
{
return std::make_unique<TextEditorModel>();
}

View file

@ -1,7 +1,7 @@
#pragma once
#include "PlainTextDocument.h"
#include "Pointer.h"
#include <memory>
class TextEditorModel
{
@ -11,9 +11,9 @@ public:
TextEditorModel();
static Ptr<TextEditorModel> Create();
static std::unique_ptr<TextEditorModel> Create();
PlainTextDocument* GetDocument() const;
};
using TextEditorModelUPtr = Ptr<TextEditorModel>;
using TextEditorModelUPtr = std::unique_ptr<TextEditorModel>;

View file

@ -81,7 +81,7 @@ void TextEditorView::initialize()
addWidget(std::move(hSpacer));
}
Ptr<TextEditorView> TextEditorView::Create()
std::unique_ptr<TextEditorView> TextEditorView::Create()
{
return std::make_unique<TextEditorView>();
}

View file

@ -13,7 +13,7 @@ class TextEditorView : public Widget
public:
TextEditorView();
static Ptr<TextEditorView> Create();
static std::unique_ptr<TextEditorView> Create();
TextEditorController* getController();
@ -23,4 +23,4 @@ private:
TextBox* mTextBox;
TextEditorControllerUPtr mController;
};
using TextEditorViewUPtr = Ptr<TextEditorView>;
using TextEditorViewUPtr = std::unique_ptr<TextEditorView>;

View file

@ -14,7 +14,7 @@ WebClientView::WebClientView()
addWidget(std::move(label));
}
Ptr<WebClientView> WebClientView::Create()
std::unique_ptr<WebClientView> WebClientView::Create()
{
return std::make_unique<WebClientView>();
}

View file

@ -8,7 +8,7 @@ public:
WebClientView();
static Ptr<WebClientView> Create();
static std::unique_ptr<WebClientView> Create();
};
using WebClientViewUPtr = Ptr<WebClientView>;
using WebClientViewUPtr = std::unique_ptr<WebClientView>;

View file

@ -23,7 +23,7 @@ Path ContentFile::getFilename() const
return mFilename;
}
String ContentFile::getOutputLocation() const
std::string ContentFile::getOutputLocation() const
{
const auto metadata_item = getMetadataItem("save_as");
return metadata_item.empty() ? PathUtils::getBaseFilename(mFilename) : metadata_item;
@ -55,7 +55,7 @@ void ContentFile::doLinkTagSubstitution(const Path& basePath)
}
}
String ContentFile::getMetadataItem(const String& key) const
std::string ContentFile::getMetadataItem(const std::string& key) const
{
const auto check = mMetadata.find(key);
if (check == mMetadata.end())

View file

@ -3,17 +3,17 @@
#include "MarkdownContentParser.h"
#include "File.h"
#include "String.h"
#include <string>
#include <iostream>
#include Map.h
#include <unordered_map>
class MarkdownDocument;
class ContentFile
{
public:
using FileMetadata = Map<String, String>;
using FileContentBody = Vector<String>;
using FileMetadata = std::unordered_map<std::string, std::string>;
using FileContentBody = std::vector<std::string>;
ContentFile(const Path& filename);
@ -23,9 +23,9 @@ public:
virtual void load();
String getMetadataItem(const String& key) const;
std::string getMetadataItem(const std::string& key) const;
virtual String getOutputLocation() const;
virtual std::string getOutputLocation() const;
MarkdownDocument* getContentBody() const
{
@ -36,15 +36,15 @@ public:
void write(const Path& path);
void setProcessedOutput(const String& output)
void setProcessedOutput(const std::string& output)
{
mProcessedOutput = output;
}
protected:
Path mFilename;
FileMetadata mMetadata;
Ptr<MarkdownDocument> mContentBody;
String mProcessedOutput;
std::unique_ptr<MarkdownDocument> mContentBody;
std::string mProcessedOutput;
};
class ContentArticle : public ContentFile

View file

@ -7,7 +7,7 @@
#include "File.h"
std::pair<MarkdownContentParser::FileMetadata, Ptr<MarkdownDocument>> MarkdownContentParser::run(const Path& path)
std::pair<MarkdownContentParser::FileMetadata, std::unique_ptr<MarkdownDocument>> MarkdownContentParser::run(const Path& path)
{
FileMetadata metadata;
FileMetadata output_metadata;
@ -15,7 +15,7 @@ std::pair<MarkdownContentParser::FileMetadata, Ptr<MarkdownDocument>> MarkdownCo
const auto lines = File(path).readLines();
bool metadata_finished = false;
String content_body;
std::string content_body;
for (const auto& line : lines)
{
if (!metadata_finished)
@ -54,11 +54,11 @@ std::pair<MarkdownContentParser::FileMetadata, Ptr<MarkdownDocument>> MarkdownCo
return {output_metadata, std::move(document)};
}
Optional<MarkdownContentParser::FileMetadataItem> MarkdownContentParser::checkForMetadataItem(const String& line) const
std::optional<MarkdownContentParser::FileMetadataItem> MarkdownContentParser::checkForMetadataItem(const std::string& line) const
{
unsigned char_count = 0;
String prefix;
String suffix;
std::string prefix;
std::string suffix;
bool building_prefix = true;
for (const auto c : line)
{

View file

@ -1,10 +1,10 @@
#pragma once
#include "String.h"
#include <string>
#include <optional>
#include Map.h
#include <unordered_map>
#include <filesystem>
#include "Vector.h"
#include <vector>
using Path = std::filesystem::path;
@ -13,10 +13,10 @@ class MarkdownDocument;
class MarkdownContentParser
{
public:
using FileMetadataItem = std::pair<String, String>;
using FileMetadata = Map<String, String>;
using FileMetadataItem = std::pair<std::string, std::string>;
using FileMetadata = std::unordered_map<std::string, std::string>;
std::pair<FileMetadata, Ptr<MarkdownDocument>> run(const Path& path);
std::pair<FileMetadata, std::unique_ptr<MarkdownDocument>> run(const Path& path);
private:
Optional<FileMetadataItem> checkForMetadataItem(const String& line) const;
std::optional<FileMetadataItem> checkForMetadataItem(const std::string& line) const;
};

View file

@ -5,7 +5,7 @@ Path SiteGeneratorConfig::getThemePath() const
return mThemesPath;
}
String SiteGeneratorConfig::getActiveTheme() const
std::string SiteGeneratorConfig::getActiveTheme() const
{
return mActiveTheme;
}
@ -15,7 +15,7 @@ void SiteGeneratorConfig::setThemePath(const Path& path)
mThemesPath = path;
}
void SiteGeneratorConfig::setActiveTheme(const String& theme)
void SiteGeneratorConfig::setActiveTheme(const std::string& theme)
{
mActiveTheme = theme;
}

View file

@ -1,6 +1,6 @@
#pragma once
#include "String.h"
#include <string>
#include <filesystem>
using Path = std::filesystem::path;
@ -10,13 +10,13 @@ class SiteGeneratorConfig
public:
Path getThemePath() const;
String getActiveTheme() const;
std::string getActiveTheme() const;
void setThemePath(const Path& path);
void setActiveTheme(const String& theme);
void setActiveTheme(const std::string& theme);
private:
Path mThemesPath;
String mActiveTheme;
std::string mActiveTheme;
};

View file

@ -30,7 +30,7 @@ WebsiteGenerator::~WebsiteGenerator()
}
void WebsiteGenerator::findProject(const String& searchPath)
void WebsiteGenerator::findProject(const std::string& searchPath)
{
const auto config_path = std::filesystem::path(searchPath) / "config.toml";
if (std::filesystem::exists(config_path))

View file

@ -1,10 +1,10 @@
#pragma once
#include "String.h"
#include <string>
#include <iostream>
#include <filesystem>
#include Map.h
#include "Vector.h"
#include <unordered_map>
#include <vector>
using Path = std::filesystem::path;
@ -22,7 +22,7 @@ public:
void doSubstitutions();
void findProject(const String& searchPath);
void findProject(const std::string& searchPath);
void parseContentFiles();
@ -47,9 +47,9 @@ private:
std::filesystem::path mProjectPath;
Ptr<SiteGeneratorConfig> mConfig;
Ptr<TemplatingEngine> mTemplateEngine;
std::unique_ptr<SiteGeneratorConfig> mConfig;
std::unique_ptr<TemplatingEngine> mTemplateEngine;
Vector<Ptr<ContentPage> > mPages;
Vector<Ptr<ContentArticle> > mArticles;
std::vector<std::unique_ptr<ContentPage> > mPages;
std::vector<std::unique_ptr<ContentArticle> > mArticles;
};

View file

@ -1,46 +0,0 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SOURCE_DIR=$SCRIPT_DIR/src
CORE_SRC_DIR=$SOURCE_DIR/base/core
g++ $SOURCE_DIR/main.cpp \
$CORE_SRC_DIR/base_types/Error.cpp \
$CORE_SRC_DIR/base_types/Index.cpp \
$CORE_SRC_DIR/base_types/Char.cpp \
$SOURCE_DIR/base/compiler/buildsystem/BuildEnvironment.cpp \
$SOURCE_DIR/base/compiler/buildsystem/BuildConfig.cpp \
$SOURCE_DIR/base/compiler/buildsystem/BuildBinary.cpp \
$SOURCE_DIR/base/compiler/buildsystem/BuildTarget.cpp \
$SOURCE_DIR/base/compiler/buildsystem/BuildLibrary.cpp \
$SOURCE_DIR/base/compiler/buildsystem/BuildExecutable.cpp \
$SOURCE_DIR/base/compiler/buildsystem/BuildSession.cpp \
$CORE_SRC_DIR/data_structures/String.cpp \
$CORE_SRC_DIR/filesystem/FileSystemPath.cpp \
$CORE_SRC_DIR/filesystem/File.cpp \
$CORE_SRC_DIR/filesystem/FileFormats.cpp \
$CORE_SRC_DIR/filesystem/posix/FilePosixImpl.cpp \
$CORE_SRC_DIR/filesystem/Directory.cpp \
$CORE_SRC_DIR/logging/ConsoleLogger.cpp \
$CORE_SRC_DIR/logging/Logger.cpp \
$CORE_SRC_DIR/serialization/yaml/YamlDocuments.cpp \
$CORE_SRC_DIR/serialization/yaml/YamlDocument.cpp \
$CORE_SRC_DIR/serialization/yaml/YamlParser.cpp \
$CORE_SRC_DIR/streams/FileStream.cpp \
$CORE_SRC_DIR/streams/Stream.cpp \
$CORE_SRC_DIR/system/process/Process.cpp \
$CORE_SRC_DIR/time/Time.cpp \
-o builder -g -fno-exceptions -fno-rtti \
-I$CORE_SRC_DIR/base_types \
-I$SOURCE_DIR/base/compiler/buildsystem \
-I$CORE_SRC_DIR/data_structures \
-I$CORE_SRC_DIR/encoding \
-I$CORE_SRC_DIR/filesystem \
-I$CORE_SRC_DIR/filesystem/posix \
-I$CORE_SRC_DIR/logging \
-I$CORE_SRC_DIR/memory \
-I$CORE_SRC_DIR/serialization/yaml \
-I$CORE_SRC_DIR/streams \
-I$CORE_SRC_DIR/system/process \
-I$CORE_SRC_DIR/time

View file

@ -1,7 +1,7 @@
#pragma once
#include "String.h"
#include "Pointer.h"
#include <string>
#include <memory>
class CircuitElement

View file

@ -1,13 +1,13 @@
#pragma once
#include "Pointer.h"
#include "Vector.h"
#include <memory>
#include <vector>
#include "CircuitElement.h"
#include "LogicGate.h"
#include "Terminal.h"
using LogicGatePtr = Ptr<LogicGate>;
using LogicGatePtr = std::unique_ptr<LogicGate>;
class ElectronicCircuit
{
@ -20,33 +20,33 @@ public:
void addLogicGate(LogicGatePtr gate);
const Vector<Terminal*>& getInputTerminals() const
const std::vector<Terminal*>& getInputTerminals() const
{
return mInputTerminals;
}
const Vector<Terminal*>& getOutputTerminals() const
const std::vector<Terminal*>& getOutputTerminals() const
{
return mOutputTerminals;
}
const Vector<LogicGate*>& getLogicGates() const
const std::vector<LogicGate*>& getLogicGates() const
{
return mLogicGates;
}
const Vector<Wire*>& getWires() const
const std::vector<Wire*>& getWires() const
{
return mWires;
}
private:
Vector<Terminal*> mInputTerminals;
Vector<Terminal*> mOutputTerminals;
std::vector<Terminal*> mInputTerminals;
std::vector<Terminal*> mOutputTerminals;
Vector<Wire*> mWires;
std::vector<Wire*> mWires;
Vector<LogicGate*> mLogicGates;
std::vector<LogicGate*> mLogicGates;
Vector<Ptr<CircuitElement> > mElements;
std::vector<std::unique_ptr<CircuitElement> > mElements;
};

View file

@ -1,6 +1,6 @@
#include "Terminal.h"
Terminal::Terminal(TerminalType type, const String& label)
Terminal::Terminal(TerminalType type, const std::string& label)
: mLabel(label),
mType(type)

View file

@ -2,7 +2,7 @@
#include "CircuitElement.h"
#include "String.h"
#include <string>
class Wire;
@ -15,7 +15,7 @@ public:
OUTPUT
};
Terminal(TerminalType type, const String& label = {});
Terminal(TerminalType type, const std::string& label = {});
Wire* getConnection() const;
@ -27,8 +27,8 @@ public:
void setConnection(Wire* connection);
private:
String mLabel;
std::string mLabel;
TerminalType mType;
Wire* mConnection{ nullptr };
};
using TerminalPtr = Ptr<Terminal>;
using TerminalPtr = std::unique_ptr<Terminal>;

View file

@ -1,14 +1,14 @@
#pragma once
#include <map>
#include "Vector.h"
#include <vector>
class TruthTable
{
public:
using TableData = std::map<Vector<bool>, Vector<bool> >;
using TableData = std::map<std::vector<bool>, std::vector<bool> >;
TruthTable(size_t, size_t)
TruthTable(std::size_t, std::size_t)
//: mNumInputColumns(numInputColumns),
// mNumOutputColumns(numOutputColumns)
{
@ -25,8 +25,8 @@ public:
static const TruthTable::TableData AND_TRUTH_TABLE;
private:
//size_t mNumInputColumns{ 0 };
//size_t mNumOutputColumns{ 0 };
//std::size_t mNumInputColumns{ 0 };
//std::size_t mNumOutputColumns{ 0 };
TableData mTable;
};

View file

@ -18,7 +18,7 @@ private:
CircuitElement* mInput{ nullptr };
CircuitElement* mOutput{ nullptr };
};
using WirePtr = Ptr<Wire>;
using WirePtr = std::unique_ptr<Wire>;
class Fanout : public CircuitElement
{

View file

@ -1,6 +1,6 @@
#include "LogicGate.h"
NInMOutLogicGate::NInMOutLogicGate(size_t numIn, size_t numOut, Vector<Wire*> inputs, Vector<Wire*> outputs)
NInMOutLogicGate::NInMOutLogicGate(std::size_t numIn, std::size_t numOut, std::vector<Wire*> inputs, std::vector<Wire*> outputs)
: LogicGate(),
mNumIn(numIn),
mNumOut(numOut)
@ -11,7 +11,7 @@ NInMOutLogicGate::NInMOutLogicGate(size_t numIn, size_t numOut, Vector<Wire*> in
}
else
{
mInputs = Vector<Wire*>(numIn, nullptr);
mInputs = std::vector<Wire*>(numIn, nullptr);
}
if (outputs.size() == mNumOut)
@ -20,21 +20,21 @@ NInMOutLogicGate::NInMOutLogicGate(size_t numIn, size_t numOut, Vector<Wire*> in
}
else
{
mOutputs = Vector<Wire*>(numOut, nullptr);
mOutputs = std::vector<Wire*>(numOut, nullptr);
}
}
size_t NInMOutLogicGate::getNumInputs() const
std::size_t NInMOutLogicGate::getNumInputs() const
{
return mNumIn;
}
size_t NInMOutLogicGate::getNumOutputs() const
std::size_t NInMOutLogicGate::getNumOutputs() const
{
return mNumOut;
}
Wire* NInMOutLogicGate::getInput(size_t idx) const
Wire* NInMOutLogicGate::getInput(std::size_t idx) const
{
if (idx < mNumIn)
{
@ -46,7 +46,7 @@ Wire* NInMOutLogicGate::getInput(size_t idx) const
}
}
Wire* NInMOutLogicGate::getOutput(size_t idx) const
Wire* NInMOutLogicGate::getOutput(std::size_t idx) const
{
if (idx < mNumOut)
{
@ -58,7 +58,7 @@ Wire* NInMOutLogicGate::getOutput(size_t idx) const
}
}
void NInMOutLogicGate::setAtInput(size_t idx, Wire* value)
void NInMOutLogicGate::setAtInput(std::size_t idx, Wire* value)
{
if (idx < mInputs.size())
{
@ -66,7 +66,7 @@ void NInMOutLogicGate::setAtInput(size_t idx, Wire* value)
}
}
void NInMOutLogicGate::setAtOutput(size_t idx, Wire* value)
void NInMOutLogicGate::setAtOutput(std::size_t idx, Wire* value)
{
if (idx < mOutputs.size())
{

View file

@ -4,8 +4,8 @@
#include "TruthTable.h"
#include "Wire.h"
#include "Pointer.h"
#include "Vector.h"
#include <memory>
#include <vector>
class LogicGate : public CircuitElement
{
@ -20,13 +20,13 @@ public:
};
virtual ~LogicGate() = default;
virtual size_t getNumInputs() const = 0;
virtual std::size_t getNumInputs() const = 0;
virtual size_t getNumOutputs() const = 0;
virtual std::size_t getNumOutputs() const = 0;
virtual Wire* getInput(size_t idx) const = 0;
virtual Wire* getInput(std::size_t idx) const = 0;
virtual Wire* getOutput(size_t idx) const = 0;
virtual Wire* getOutput(std::size_t idx) const = 0;
virtual const TruthTable& getTruthTable() = 0;
@ -41,28 +41,28 @@ public:
class NInMOutLogicGate : public LogicGate
{
public:
NInMOutLogicGate(size_t numIn, size_t numOut, Vector<Wire*> inputs = {}, Vector<Wire*> outputs = {});
NInMOutLogicGate(std::size_t numIn, std::size_t numOut, std::vector<Wire*> inputs = {}, std::vector<Wire*> outputs = {});
virtual ~NInMOutLogicGate() = default;
size_t getNumInputs() const override;
std::size_t getNumInputs() const override;
size_t getNumOutputs() const override;
std::size_t getNumOutputs() const override;
Wire* getInput(size_t idx) const override;
Wire* getInput(std::size_t idx) const override;
Wire* getOutput(size_t idx) const override;
Wire* getOutput(std::size_t idx) const override;
void setAtInput(size_t idx, Wire* value);
void setAtInput(std::size_t idx, Wire* value);
void setAtOutput(size_t idx, Wire* value);
void setAtOutput(std::size_t idx, Wire* value);
private:
size_t mNumIn{ 1 };
size_t mNumOut{ 1 };
std::size_t mNumIn{ 1 };
std::size_t mNumOut{ 1 };
Vector<Wire*> mInputs;
Vector<Wire*> mOutputs;
std::vector<Wire*> mInputs;
std::vector<Wire*> mOutputs;
};
class TwoInOneOutLogicGate : public NInMOutLogicGate

View file

@ -37,12 +37,12 @@ void ElectronicCircuitNode::buildWireConnections()
for (auto gate : mContent->getLogicGates())
{
for (size_t idx = 0; idx < gate->getNumInputs(); idx++)
for (std::size_t idx = 0; idx < gate->getNumInputs(); idx++)
{
mWireInputConnections[gate->getInput(idx)] = gate;
}
for (size_t idx = 0; idx < gate->getNumOutputs(); idx++)
for (std::size_t idx = 0; idx < gate->getNumOutputs(); idx++)
{
mWireOutputConnections[gate->getOutput(idx)] = gate;
}

View file

@ -4,7 +4,7 @@
#include "ElectronicCircuit.h"
#include Map.h
#include <unordered_map>
class WireNode;
class TerminalNode;
@ -31,13 +31,13 @@ private:
ElectronicCircuit* mContent{ nullptr };
bool mContentDirty{ true };
Vector<Ptr<TerminalNode> > mInputTerminalNodes;
Vector<Ptr<TerminalNode> > mOutputTerminalNodes;
Vector<Ptr<WireNode> > mWireNodes;
Vector<Ptr<LogicGateNode> > mLogicGateNodes;
std::vector<std::unique_ptr<TerminalNode> > mInputTerminalNodes;
std::vector<std::unique_ptr<TerminalNode> > mOutputTerminalNodes;
std::vector<std::unique_ptr<WireNode> > mWireNodes;
std::vector<std::unique_ptr<LogicGateNode> > mLogicGateNodes;
Map<Wire*, CircuitElement*> mWireInputConnections;
Map<Wire*, CircuitElement*> mWireOutputConnections;
std::unordered_map<Wire*, CircuitElement*> mWireInputConnections;
std::unordered_map<Wire*, CircuitElement*> mWireOutputConnections;
Map<CircuitElement*, CircuitElementNode*> mNodesForContent;
std::unordered_map<CircuitElement*, CircuitElementNode*> mNodesForContent;
};

View file

@ -21,9 +21,9 @@ LogicGateNode::~LogicGateNode()
Point2 LogicGateNode::getConnectionLocation(Wire* wire) const
{
bool is_input{ false };
size_t connection_id{ 0 };
std::size_t connection_id{ 0 };
for (size_t idx = 0; idx < mContent->getNumInputs(); idx++)
for (std::size_t idx = 0; idx < mContent->getNumInputs(); idx++)
{
if (mContent->getInput(idx) == wire)
{
@ -33,7 +33,7 @@ Point2 LogicGateNode::getConnectionLocation(Wire* wire) const
}
}
for (size_t idx = 0; idx < mContent->getNumOutputs(); idx++)
for (std::size_t idx = 0; idx < mContent->getNumOutputs(); idx++)
{
if (mContent->getOutput(idx) == wire)
{

View file

@ -25,6 +25,6 @@ private:
LogicGate* mContent{ nullptr };
bool mContentDirty{ true };
Ptr<PathNode> mPrimaryPath;
Ptr<CircleNode> mNegationGlyph;
std::unique_ptr<PathNode> mPrimaryPath;
std::unique_ptr<CircleNode> mNegationGlyph;
};

View file

@ -1,11 +1,11 @@
#include "LogicGatePrimitiveShapes.h"
String LogicGatePrimitiveShapes::getAndGateShape()
std::string LogicGatePrimitiveShapes::getAndGateShape()
{
return "M4 8 h24 a16 16 0 0 1 0 32 h-24Z";
}
Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, size_t idx)
Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, std::size_t idx)
{
if (isInput)
{
@ -24,12 +24,12 @@ Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, size
}
}
String LogicGatePrimitiveShapes::getOrGateShape()
std::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, size_t idx)
Point2 LogicGatePrimitiveShapes::getOrGateConnectionLocation(bool isInput, std::size_t idx)
{
if (isInput)
{

View file

@ -2,16 +2,16 @@
#include "Point.h"
#include "String.h"
#include <string>
class LogicGatePrimitiveShapes
{
public:
static Point2 getAndGateConnectionLocation(bool isInput, size_t idx);
static Point2 getAndGateConnectionLocation(bool isInput, std::size_t idx);
static String getAndGateShape();
static std::string getAndGateShape();
static Point2 getOrGateConnectionLocation(bool isInput, size_t idx);
static Point2 getOrGateConnectionLocation(bool isInput, std::size_t idx);
static String getOrGateShape();
static std::string getOrGateShape();
};

View file

@ -19,7 +19,7 @@ public:
private:
void createOrUpdateGeometry(SceneInfo* sceneInfo);
Ptr<CircleNode> mMarker;
std::unique_ptr<CircleNode> mMarker;
Terminal* mContent{ nullptr };
bool mContentDirty{ true };

View file

@ -48,7 +48,7 @@ void WireNode::createOrUpdateGeometry(SceneInfo*)
auto loc = mOutputLocation;
loc.moveBy(-mInputLocation.getX(), -mInputLocation.getY(), -mInputLocation.getZ());
Vector<Point2> points;
std::vector<Point2> points;
if (loc.getY() == 0.0)
{

View file

@ -26,5 +26,5 @@ private:
Point2 mInputLocation;
Point2 mOutputLocation;
Ptr<LineNode> mLine;
std::unique_ptr<LineNode> mLine;
};

View file

@ -9,7 +9,7 @@ MetaMidiEvent::MetaMidiEvent()
}
Ptr<MetaMidiEvent> MetaMidiEvent::Create()
std::unique_ptr<MetaMidiEvent> MetaMidiEvent::Create()
{
return std::make_unique<MetaMidiEvent>();
}
@ -79,7 +79,7 @@ void MetaMidiEvent::SetValue(int value)
mValue = value;
}
void MetaMidiEvent::SetLabel(const String& label)
void MetaMidiEvent::SetLabel(const std::string& label)
{
mLabel = label;
}

View file

@ -2,8 +2,8 @@
#include "MidiEvent.h"
#include "MidiElements.h"
#include "Pointer.h"
#include "String.h"
#include <memory>
#include <string>
class MetaMidiEvent : public MidiEvent
{
@ -51,13 +51,13 @@ private:
public:
MetaMidiEvent();
static Ptr<MetaMidiEvent> Create();
static std::unique_ptr<MetaMidiEvent> Create();
void SetValue(int value);
void SetType(char c);
Type GetType() const;
void SetLabel(const String& label);
void SetLabel(const std::string& label);
void SetTimeSignature(const MidiTimeSignature& timeSig);
void SetTimeCode(const MidiSmtpeTimecode& timeCode);
void SetKeySignature(const MidiKeySignature& keySig);
@ -65,11 +65,11 @@ public:
private:
Type mType {Type::UNSET};
char mUnKnownMarker{0};
String mLabel;
std::string mLabel;
int mValue { 0 };
MidiTimeSignature mTimeSig;
MidiSmtpeTimecode mTimecode;
MidiKeySignature mKeySig;
};
using MetaMidiEventPtr = Ptr<MetaMidiEvent>;
using MetaMidiEventPtr = std::unique_ptr<MetaMidiEvent>;

View file

@ -9,7 +9,7 @@ MidiChannelEvent::MidiChannelEvent()
}
Ptr<MidiChannelEvent> MidiChannelEvent::Create()
std::unique_ptr<MidiChannelEvent> MidiChannelEvent::Create()
{
return std::make_unique<MidiChannelEvent>();
}

View file

@ -1,7 +1,7 @@
#pragma once
#include "MidiEvent.h"
#include "String.h"
#include <string>
class MidiChannelEvent : public MidiEvent
{
@ -52,7 +52,7 @@ private:
public:
MidiChannelEvent();
static Ptr<MidiChannelEvent> Create();
static std::unique_ptr<MidiChannelEvent> Create();
void SetTypeAndChannel(char c);
void SetType(Type type);
@ -69,4 +69,4 @@ private:
int mValue1 {1};
};
using MidiChannelEventPtr = Ptr<MidiChannelEvent>;
using MidiChannelEventPtr = std::unique_ptr<MidiChannelEvent>;

View file

@ -7,7 +7,7 @@ MidiDocument::MidiDocument()
}
Ptr<MidiDocument> MidiDocument::Create()
std::unique_ptr<MidiDocument> MidiDocument::Create()
{
return std::make_unique<MidiDocument>();
}
@ -32,9 +32,9 @@ void MidiDocument::SetTimeDivision(const MidiTimeDivision& timeDivision)
mTimeDivision = timeDivision;
}
String MidiDocument::Serialize() const
std::string MidiDocument::Serialize() const
{
String output = "MidiDocument\n";
std::string output = "MidiDocument\n";
output += "Format type: " + std::to_string(mFormatType) + "\n";
output += "Expected Tracks: " + std::to_string(mExpectedTracks) + "\n";
output += "Use fps: " + std::to_string(mTimeDivision.mUseFps) + "\n";

View file

@ -1,20 +1,20 @@
#pragma once
#include "Vector.h"
#include "Pointer.h"
#include "String.h"
#include <vector>
#include <memory>
#include <string>
#include "MidiElements.h"
class MidiTrack;
using MidiTrackPtr = Ptr<MidiTrack>;
using MidiTrackPtr = std::unique_ptr<MidiTrack>;
class MidiDocument
{
public:
MidiDocument();
static Ptr<MidiDocument> Create();
static std::unique_ptr<MidiDocument> Create();
void AddTrack(MidiTrackPtr track);
@ -22,13 +22,13 @@ public:
void SetExpectedTracks(int expected);
void SetTimeDivision(const MidiTimeDivision& timeDivision);
String Serialize() const;
std::string Serialize() const;
private:
int mFormatType = 0;
int mExpectedTracks = 0;
MidiTimeDivision mTimeDivision;
Vector<MidiTrackPtr> mTracks;
std::vector<MidiTrackPtr> mTracks;
};
using MidiDocumentPtr = Ptr<MidiDocument>;
using MidiDocumentPtr = std::unique_ptr<MidiDocument>;

View file

@ -6,7 +6,7 @@ MidiEvent::MidiEvent()
}
Ptr<MidiEvent> MidiEvent::Create()
std::unique_ptr<MidiEvent> MidiEvent::Create()
{
return std::make_unique<MidiEvent>();
}

View file

@ -1,6 +1,6 @@
#pragma once
#include "Pointer.h"
#include <memory>
class MidiEvent
{
@ -13,7 +13,7 @@ public:
MidiEvent();
virtual ~MidiEvent() = default;
static Ptr<MidiEvent> Create();
static std::unique_ptr<MidiEvent> Create();
void SetTimeDelta(int delta);
@ -26,4 +26,4 @@ private:
int mTimeDelta{0};
};
using MidiEventPtr = Ptr<MidiEvent>;
using MidiEventPtr = std::unique_ptr<MidiEvent>;

View file

@ -17,19 +17,19 @@ void MidiTrack::AddEvent(MidiEventPtr event)
mEvents.push_back(std::move(event));
}
MidiEvent* MidiTrack::GetEvent(size_t idx) const
MidiEvent* MidiTrack::GetEvent(std::size_t idx) const
{
return mEvents[idx].get();
}
size_t MidiTrack::GetNumEvents()
std::size_t MidiTrack::GetNumEvents()
{
return mEvents.size();
}
String MidiTrack::Serialize() const
std::string MidiTrack::Serialize() const
{
String output = "MidiTrack\n";
std::string output = "MidiTrack\n";
output += "Num Events: " + std::to_string(mEvents.size()) + "\n";
return output;
}

View file

@ -1,12 +1,12 @@
#pragma once
#include "Vector.h"
#include "Pointer.h"
#include "String.h"
#include <vector>
#include <memory>
#include <string>
#include "MidiEvent.h"
class MidiEvent;
using MidiEventPtr = Ptr<MidiEvent>;
using MidiEventPtr = std::unique_ptr<MidiEvent>;
class MidiTrack
{
@ -18,13 +18,13 @@ public:
void AddEvent(MidiEventPtr event);
MidiEvent* GetEvent(size_t idx) const;
MidiEvent* GetEvent(std::size_t idx) const;
size_t GetNumEvents();
std::size_t GetNumEvents();
String Serialize() const;
std::string Serialize() const;
private:
Vector<MidiEventPtr> mEvents;
std::vector<MidiEventPtr> mEvents;
};

View file

@ -1,7 +1,7 @@
#include "MidiChannelEventAdapter.h"
#include "BinaryStream.h"
#include "Bits.h"
#include "ByteUtils.h"
#include <iostream>
#include <bitset>
@ -19,7 +19,7 @@ int MidiChannelEventAdapter::readEvent(std::ifstream* file, char firstByte, Midi
unsigned byteCount = 0;
//std::cout << "Channel: " << midi_channel << std::endl;
const bool isStatusByte = Bits::MostSignificantBitIsOne(firstByte);
const bool isStatusByte = ByteUtils::MostSignificantBitIsOne(firstByte);
if(isStatusByte)
{
event->SetTypeAndChannel(firstByte);

View file

@ -1,7 +1,7 @@
#include "MidiMetaEventAdapter.h"
#include "BinaryStream.h"
#include "Bits.h"
#include "ByteUtils.h"
#include <iostream>
#include <bitset>
@ -83,7 +83,7 @@ int MidiMetaEventAdapter::ReadStringEvent(std::ifstream* file, MetaMidiEvent* ev
int length = *BinaryStream::getNextByteAsInt(file);
byteCount++;
String name;
std::string name;
BinaryStream::getNextString(file, name, length);
byteCount += length;
event->SetLabel(name);
@ -104,11 +104,11 @@ int MidiMetaEventAdapter::ReadIntEvent(std::ifstream* file, MetaMidiEvent* event
byteCount ++;
}
String buffer;
std::string buffer;
BinaryStream::getNextNBytes(file, buffer.data(), length);
byteCount += length;
const int value = Bits::ToType<Bits::DWord>(buffer.data(), length);
const int value = ByteUtils::ToType<ByteUtils::DWord>(buffer.data(), length);
event->SetValue(value);
return byteCount;
}
@ -119,11 +119,11 @@ int MidiMetaEventAdapter::ReadChannelPrefixEvent(std::ifstream* file, MetaMidiEv
int length = *BinaryStream::getNextByteAsInt(file);
byteCount ++;
String buffer;
std::string buffer;
BinaryStream::getNextNBytes(file, buffer.data(), length);
byteCount += length;
const int value = Bits::ToType<Bits::DWord>(buffer.data(), length);
const int value = ByteUtils::ToType<ByteUtils::DWord>(buffer.data(), length);
event->SetValue(value);
lastMidiChannel = value;
return byteCount;

View file

@ -1,7 +1,7 @@
#include "MidiReader.h"
#include "MidiDocument.h"
#include "Bits.h"
#include "ByteUtils.h"
#include "MidiTrack.h"
#include "BinaryStream.h"
#include "FileLogger.h"

View file

@ -7,7 +7,7 @@
#include "File.h"
#include <filesystem>
#include "String.h"
#include <string>
using Path = std::filesystem::path;
@ -29,7 +29,7 @@ private:
int processEvent(MidiTrack* track);
private:
Ptr<File> mFile;
std::unique_ptr<File> mFile;
MidiDocumentPtr mDocument;
int mLastMidiChannel {0};
MidiChannelEvent::Type mLastChannelEventType;

View file

@ -1,7 +1,7 @@
#include "MidiTimeAdapter.h"
#include "BinaryStream.h"
#include "Bits.h"
#include "ByteUtils.h"
#include <iostream>
#include <bitset>
@ -13,7 +13,7 @@ int MidiTimeAdapter::ReadEventTimeDelta(std::ifstream* file, int& delta)
file->get(c);
byteCount++;
if(!Bits::MostSignificantBitIsOne(c))
if(!ByteUtils::MostSignificantBitIsOne(c))
{
delta = int(c);
//std::cout << "Time delta final: " << delta << std::endl;
@ -54,13 +54,13 @@ int MidiTimeAdapter::ReadTimeDivision(std::ifstream* file, MidiTimeDivision& div
return -1;
}
division.mUseFps = Bits::GetWordFirstBit(*time_division);
division.mUseFps = ByteUtils::GetWordFirstBit(*time_division);
if (division.mUseFps)
{
const int TOP_7_BITS = 0x7F00; // 0111 1111 - 0000 0000
division.mFps = ((~(*time_division) & TOP_7_BITS) >> 8) - 1; // Reverse 2complement of next 7 bits
}
division.mTicks = Bits::GetWordLastByte(*time_division);
division.mTicks = ByteUtils::GetWordLastByte(*time_division);
return 2; // Bytes advanced
}

View file

@ -28,22 +28,22 @@ void QuantumCircuit::addLogicGate(QuantumGatePtr gate)
mElements.push_back(std::move(gate));
}
const Vector<QuantumTerminal*>& QuantumCircuit::getInputTerminals() const
const std::vector<QuantumTerminal*>& QuantumCircuit::getInputTerminals() const
{
return mInputTerminals;
}
const Vector<QuantumTerminal*>& QuantumCircuit::getOutputTerminals() const
const std::vector<QuantumTerminal*>& QuantumCircuit::getOutputTerminals() const
{
return mOutputTerminals;
}
const Vector<QuantumGate*>& QuantumCircuit::getLogicGates() const
const std::vector<QuantumGate*>& QuantumCircuit::getLogicGates() const
{
return mGates;
}
const Vector<QuantumWire*>& QuantumCircuit::getQuantumWires() const
const std::vector<QuantumWire*>& QuantumCircuit::getQuantumWires() const
{
return mWires;
}
@ -94,7 +94,7 @@ void QuantumCircuit::buildWireConnections()
{
if (wire->getOutput() == gate)
{
for (size_t idx = 0; idx < gate->getNumInputs(); idx++)
for (std::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 (size_t idx = 0; idx < gate->getNumOutputs(); idx++)
for (std::size_t idx = 0; idx < gate->getNumOutputs(); idx++)
{
if (gate->getOutput(idx) == nullptr)
{

View file

@ -6,7 +6,7 @@
#include "QuantumWire.h"
#include "QuantumState.h"
#include "Vector.h"
#include <vector>
class QuantumCircuit
{
@ -21,24 +21,24 @@ public:
void buildWireConnections();
const Vector<QuantumTerminal*>& getInputTerminals() const;
const std::vector<QuantumTerminal*>& getInputTerminals() const;
const Vector<QuantumTerminal*>& getOutputTerminals() const;
const std::vector<QuantumTerminal*>& getOutputTerminals() const;
const Vector<QuantumGate*>& getLogicGates() const;
const std::vector<QuantumGate*>& getLogicGates() const;
const Vector<QuantumWire*>& getQuantumWires() const;
const std::vector<QuantumWire*>& getQuantumWires() const;
QuantumState getInputState() const;
private:
bool connectivityIsValid() const;
Vector<QuantumTerminal*> mInputTerminals;
Vector<QuantumTerminal*> mOutputTerminals;
std::vector<QuantumTerminal*> mInputTerminals;
std::vector<QuantumTerminal*> mOutputTerminals;
Vector<QuantumWire*> mWires;
Vector<QuantumGate*> mGates;
std::vector<QuantumWire*> mWires;
std::vector<QuantumGate*> mGates;
Vector<Ptr<QuantumCircuitElement> > mElements;
std::vector<std::unique_ptr<QuantumCircuitElement> > mElements;
};

View file

@ -10,18 +10,18 @@
#include "StringUtils.h"
#include "FileLogger.h"
Ptr<QuantumCircuit> QuantumCircuitReader::read(const Path& path)
std::unique_ptr<QuantumCircuit> QuantumCircuitReader::read(const Path& path)
{
File file(path);
return read(file.readText());
}
Ptr<QuantumCircuit> QuantumCircuitReader::read(const String& content)
std::unique_ptr<QuantumCircuit> QuantumCircuitReader::read(const std::string& content)
{
auto circuit = std::make_unique<QuantumCircuit>();
mWorkingCircuit = circuit.get();
size_t cursor = 0;
std::size_t cursor = 0;
for (const auto& line : StringUtils::toLines(content))
{
onLine(line, cursor);
@ -31,15 +31,15 @@ Ptr<QuantumCircuit> QuantumCircuitReader::read(const String& content)
return circuit;
}
void QuantumCircuitReader::onLine(const String& line, size_t jdx)
void QuantumCircuitReader::onLine(const std::string& line, std::size_t jdx)
{
mWorkingString.clear();
size_t cursor = 0;
std::size_t cursor = 0;
while (cursor < line.size())
{
const auto c = line[cursor];
MLOG_INFO("Working char: " << String(1, c));
MLOG_INFO("Working char: " << std::string(1, c));
if (c == '|')
{
@ -103,7 +103,7 @@ void QuantumCircuitReader::onLineEnd()
mWorkingElement = nullptr;
}
void QuantumCircuitReader::onGate(Location, const String value)
void QuantumCircuitReader::onGate(Location, const std::string value)
{
MLOG_INFO("Got gate: " << value);
@ -128,9 +128,9 @@ void QuantumCircuitReader::onGate(Location, const String value)
}
}
String QuantumCircuitReader::checkForGate(const String& segment)
std::string QuantumCircuitReader::checkForGate(const std::string& segment)
{
String working_string;
std::string working_string;
for (const auto c : segment)
{
if (c == '-')
@ -142,7 +142,7 @@ String QuantumCircuitReader::checkForGate(const String& segment)
return working_string;
}
void QuantumCircuitReader::onKet(Location, const String value)
void QuantumCircuitReader::onKet(Location, const std::string value)
{
MLOG_INFO("Got input state: " << value);
Qubit qubit;
@ -157,9 +157,9 @@ void QuantumCircuitReader::onKet(Location, const String value)
mWorkingCircuit->addInputTerminal(std::move(input_terminal));
}
size_t QuantumCircuitReader::getWireEnd(const String& segment)
std::size_t QuantumCircuitReader::getWireEnd(const std::string& segment)
{
size_t idx = 0;
std::size_t idx = 0;
for (const auto c : segment)
{
if (c != '-')
@ -171,9 +171,9 @@ size_t QuantumCircuitReader::getWireEnd(const String& segment)
return idx;
}
String QuantumCircuitReader::checkForKet(const String& segment)
std::string QuantumCircuitReader::checkForKet(const std::string& segment)
{
String working_string;
std::string working_string;
bool found{ false };
for (const auto c : segment)

View file

@ -1,7 +1,7 @@
#pragma once
#include <filesystem>
#include "String.h"
#include <string>
using Path = std::filesystem::path;
@ -11,30 +11,30 @@ class QuantumCircuitElement;
class QuantumCircuitReader
{
public:
Ptr<QuantumCircuit> read(const Path& path);
std::unique_ptr<QuantumCircuit> read(const Path& path);
Ptr<QuantumCircuit> read(const String& content);
std::unique_ptr<QuantumCircuit> read(const std::string& content);
private:
using Location = std::pair<size_t, size_t>;
using Location = std::pair<std::size_t, std::size_t>;
void onLine(const String& line, size_t jdx);
void onLine(const std::string& line, std::size_t jdx);
String checkForKet(const String& segment);
std::string checkForKet(const std::string& segment);
String checkForGate(const String& segment);
std::string checkForGate(const std::string& segment);
size_t getWireEnd(const String& segment);
std::size_t getWireEnd(const std::string& segment);
void onGate(Location loc, const String value);
void onGate(Location loc, const std::string value);
void onKet(Location loc, const String value);
void onKet(Location loc, const std::string value);
void onLineEnd();
void onVertialQuantumWire(Location loc);
String mWorkingString;
std::string mWorkingString;
QuantumCircuitElement* mWorkingElement{ nullptr };
QuantumCircuit* mWorkingCircuit{ nullptr };
};

View file

@ -1,13 +1,13 @@
#include "QuantumState.h"
const Vector<Qubit>& QuantumState::getData() const
const std::vector<Qubit>& QuantumState::getData() const
{
return mState;
}
String QuantumState::toString() const
std::string QuantumState::toString() const
{
String out;
std::string out;
for (const auto& qubit : mState)
{
out += "|" + qubit.toString() + "\n";

View file

@ -2,8 +2,8 @@
#include "Qubit.h"
#include "Vector.h"
#include "String.h"
#include <vector>
#include <string>
class QuantumState
{
@ -13,10 +13,10 @@ public:
mState.push_back(data);
}
const Vector<Qubit>& getData() const;
const std::vector<Qubit>& getData() const;
String toString() const;
std::string toString() const;
private:
Vector<Qubit> mState;
std::vector<Qubit> mState;
};

View file

@ -29,9 +29,9 @@ bool Qubit::isIn1State() const
return mBeta.getReal() == 1.0 && mAlpha.getMagnitude() == 0.0;
}
String Qubit::toString(size_t precision) const
std::string Qubit::toString(std::size_t precision) const
{
Stringstream sstr;
std::stringstream sstr;
sstr.precision(precision);
sstr << "alpha " << mAlpha.getReal() << " " << mAlpha.getImaginary() << "i , beta " << mBeta.getReal() << " " << mBeta.getImaginary() << "i";
return sstr.str();

View file

@ -2,7 +2,7 @@
#include "ComplexNumber.h"
#include "String.h"
#include <string>
class Qubit
{
@ -17,7 +17,7 @@ public:
bool isIn1State() const;
String toString(size_t precision=3) const;
std::string toString(std::size_t precision=3) const;
private:
ComplexNumber mAlpha;
ComplexNumber mBeta;

View file

@ -1,6 +1,6 @@
#pragma once
#include "Pointer.h"
#include <memory>
class QuantumCircuitElement
{

View file

@ -1,6 +1,6 @@
#include "QuantumGate.h"
NInMOutQuantumGate::NInMOutQuantumGate(size_t numIn, size_t numOut, Vector<AbstractQuantumWire*> inputs, Vector<AbstractQuantumWire*> outputs)
NInMOutQuantumGate::NInMOutQuantumGate(std::size_t numIn, std::size_t numOut, std::vector<AbstractQuantumWire*> inputs, std::vector<AbstractQuantumWire*> outputs)
: QuantumGate(),
mNumIn(numIn),
mNumOut(numOut)
@ -11,7 +11,7 @@ NInMOutQuantumGate::NInMOutQuantumGate(size_t numIn, size_t numOut, Vector<Abstr
}
else
{
mInputs = Vector<AbstractQuantumWire*>(numIn, nullptr);
mInputs = std::vector<AbstractQuantumWire*>(numIn, nullptr);
}
if (outputs.size() == mNumOut)
@ -20,21 +20,21 @@ NInMOutQuantumGate::NInMOutQuantumGate(size_t numIn, size_t numOut, Vector<Abstr
}
else
{
mOutputs = Vector<AbstractQuantumWire*>(numOut, nullptr);
mOutputs = std::vector<AbstractQuantumWire*>(numOut, nullptr);
}
}
size_t NInMOutQuantumGate::getNumInputs() const
std::size_t NInMOutQuantumGate::getNumInputs() const
{
return mNumIn;
}
size_t NInMOutQuantumGate::getNumOutputs() const
std::size_t NInMOutQuantumGate::getNumOutputs() const
{
return mNumOut;
}
AbstractQuantumWire* NInMOutQuantumGate::getInput(size_t idx) const
AbstractQuantumWire* NInMOutQuantumGate::getInput(std::size_t idx) const
{
if (idx < mNumIn)
{
@ -46,7 +46,7 @@ AbstractQuantumWire* NInMOutQuantumGate::getInput(size_t idx) const
}
}
AbstractQuantumWire* NInMOutQuantumGate::getOutput(size_t idx) const
AbstractQuantumWire* NInMOutQuantumGate::getOutput(std::size_t idx) const
{
if (idx < mNumOut)
{
@ -58,7 +58,7 @@ AbstractQuantumWire* NInMOutQuantumGate::getOutput(size_t idx) const
}
}
void NInMOutQuantumGate::setAtInput(size_t idx, AbstractQuantumWire* value)
void NInMOutQuantumGate::setAtInput(std::size_t idx, AbstractQuantumWire* value)
{
if (idx < mInputs.size())
{
@ -66,7 +66,7 @@ void NInMOutQuantumGate::setAtInput(size_t idx, AbstractQuantumWire* value)
}
}
void NInMOutQuantumGate::setAtOutput(size_t idx, AbstractQuantumWire* value)
void NInMOutQuantumGate::setAtOutput(std::size_t idx, AbstractQuantumWire* value)
{
if (idx < mOutputs.size())
{

View file

@ -4,7 +4,7 @@
#include "QuantumWire.h"
#include "Vector.h"
#include <vector>
class QuantumGate : public QuantumCircuitElement
{
@ -20,17 +20,17 @@ public:
};
virtual ~QuantumGate() = default;
virtual size_t getNumInputs() const = 0;
virtual std::size_t getNumInputs() const = 0;
virtual size_t getNumOutputs() const = 0;
virtual std::size_t getNumOutputs() const = 0;
virtual AbstractQuantumWire* getInput(size_t idx) const = 0;
virtual AbstractQuantumWire* getInput(std::size_t idx) const = 0;
virtual AbstractQuantumWire* getOutput(size_t idx) const = 0;
virtual AbstractQuantumWire* getOutput(std::size_t idx) const = 0;
virtual void setAtInput(size_t idx, AbstractQuantumWire* value) = 0;
virtual void setAtInput(std::size_t idx, AbstractQuantumWire* value) = 0;
virtual void setAtOutput(size_t idx, AbstractQuantumWire* value) = 0;
virtual void setAtOutput(std::size_t idx, AbstractQuantumWire* value) = 0;
virtual GateType getGateType() const = 0;
@ -39,27 +39,27 @@ public:
return Type::GATE;
}
};
using QuantumGatePtr = Ptr<QuantumGate>;
using QuantumGatePtr = std::unique_ptr<QuantumGate>;
class NInMOutQuantumGate : public QuantumGate
{
public:
NInMOutQuantumGate(size_t numIn, size_t numOut, Vector<AbstractQuantumWire*> inputs = {}, Vector<AbstractQuantumWire*> outputs = {});
NInMOutQuantumGate(std::size_t numIn, std::size_t numOut, std::vector<AbstractQuantumWire*> inputs = {}, std::vector<AbstractQuantumWire*> outputs = {});
virtual ~NInMOutQuantumGate() = default;
size_t getNumInputs() const override;
std::size_t getNumInputs() const override;
size_t getNumOutputs() const override;
std::size_t getNumOutputs() const override;
AbstractQuantumWire* getInput(size_t idx) const override;
AbstractQuantumWire* getInput(std::size_t idx) const override;
AbstractQuantumWire* getOutput(size_t idx) const override;
AbstractQuantumWire* getOutput(std::size_t idx) const override;
void setAtInput(size_t idx, AbstractQuantumWire* value) override;
void setAtInput(std::size_t idx, AbstractQuantumWire* value) override;
void setAtOutput(size_t idx, AbstractQuantumWire* value) override;
void setAtOutput(std::size_t idx, AbstractQuantumWire* value) override;
bool isFullyConnected() const override
{
@ -82,11 +82,11 @@ public:
}
private:
size_t mNumIn{ 1 };
size_t mNumOut{ 1 };
std::size_t mNumIn{ 1 };
std::size_t mNumOut{ 1 };
Vector<AbstractQuantumWire*> mInputs;
Vector<AbstractQuantumWire*> mOutputs;
std::vector<AbstractQuantumWire*> mInputs;
std::vector<AbstractQuantumWire*> mOutputs;
};
class TwoInOneOutQuantumGate : public NInMOutQuantumGate

View file

@ -1,6 +1,6 @@
#include "QuantumTerminal.h"
QuantumTerminal::QuantumTerminal(TerminalType type, const String& label)
QuantumTerminal::QuantumTerminal(TerminalType type, const std::string& label)
: mLabel(label),
mType(type)
{

View file

@ -3,8 +3,8 @@
#include "QuantumCircuitElement.h"
#include "Qubit.h"
#include "String.h"
#include "Pointer.h"
#include <string>
#include <memory>
class QuantumWire;
@ -17,7 +17,7 @@ public:
OUTPUT
};
QuantumTerminal(TerminalType type, const String& label = {});
QuantumTerminal(TerminalType type, const std::string& label = {});
QuantumWire* getConnection() const;
@ -40,9 +40,9 @@ public:
void setValue(const Qubit& value);
private:
String mLabel;
std::string mLabel;
TerminalType mType;
Qubit mValue;
QuantumWire* mConnection{ nullptr };
};
using QuantumTerminalPtr = Ptr<QuantumTerminal>;
using QuantumTerminalPtr = std::unique_ptr<QuantumTerminal>;

View file

@ -38,7 +38,7 @@ public:
Type getType() const override;
WireType getWireType() const override;
};
using QuantumWirePtr = Ptr<QuantumWire>;
using QuantumWirePtr = std::unique_ptr<QuantumWire>;
class ClassicalWire : public AbstractQuantumWire
{

View file

@ -41,7 +41,7 @@ void BlochSphereNode::update(SceneInfo*)
mOuterCircle = std::make_unique<CircleNode>(loc, mSize/2.0);
const auto end_point_x = Point2(loc.getX() + 1.2 * mSize / 2.0, loc.getY());
const Vector<Point2> points{end_point_x };
const std::vector<Point2> points{end_point_x };
mXAxis = std::make_unique<LineNode>(loc, points);
mCentreCircle = std::make_unique<CircleNode>(loc, mSize / 50.0);

View file

@ -2,7 +2,7 @@
#include "AbstractVisualNode.h"
#include "Pointer.h"
#include <memory>
class BlochSphere;
class CircleNode;
@ -23,12 +23,12 @@ private:
bool mContentDirty{ true };
BlochSphere* mContent{ nullptr };
Ptr<CircleNode> mOuterCircle;
Ptr<CircleNode> mInnerCircle;
Ptr<CircleNode> mCentreCircle;
Ptr<CircleNode> mStateMarkerCircle;
Ptr<LineNode> mXAxis;
Ptr<LineNode> mYAxis;
Ptr<LineNode> mZAxis;
Ptr<LineNode> mStateVector;
std::unique_ptr<CircleNode> mOuterCircle;
std::unique_ptr<CircleNode> mInnerCircle;
std::unique_ptr<CircleNode> mCentreCircle;
std::unique_ptr<CircleNode> mStateMarkerCircle;
std::unique_ptr<LineNode> mXAxis;
std::unique_ptr<LineNode> mYAxis;
std::unique_ptr<LineNode> mZAxis;
std::unique_ptr<LineNode> mStateVector;
};

View file

@ -45,12 +45,12 @@ void QuantumCircuitNode::buildWireConnections()
for (auto gate : mContent->getLogicGates())
{
for (size_t idx = 0; idx < gate->getNumInputs(); idx++)
for (std::size_t idx = 0; idx < gate->getNumInputs(); idx++)
{
mWireInputConnections[gate->getInput(idx)] = gate;
}
for (size_t idx = 0; idx < gate->getNumOutputs(); idx++)
for (std::size_t idx = 0; idx < gate->getNumOutputs(); idx++)
{
mWireOutputConnections[gate->getOutput(idx)] = gate;
}

View file

@ -2,7 +2,7 @@
#include "AbstractVisualNode.h"
#include Map.h
#include <unordered_map>
class QuantumCircuit;
class QuantumCircuitElement;
@ -29,13 +29,13 @@ private:
bool mContentDirty{ true };
QuantumCircuit* mContent{ nullptr };
Vector<Ptr<QuantumTerminalNode> > mInputTerminalNodes;
Vector<Ptr<QuantumTerminalNode> > mOutputTerminalNodes;
Vector<Ptr<QuantumGateNode> > mGateNodes;
Vector<Ptr<QuantumWireNode> > mWireNodes;
std::vector<std::unique_ptr<QuantumTerminalNode> > mInputTerminalNodes;
std::vector<std::unique_ptr<QuantumTerminalNode> > mOutputTerminalNodes;
std::vector<std::unique_ptr<QuantumGateNode> > mGateNodes;
std::vector<std::unique_ptr<QuantumWireNode> > mWireNodes;
Map<AbstractQuantumWire*, QuantumCircuitElement*> mWireInputConnections;
Map<AbstractQuantumWire*, QuantumCircuitElement*> mWireOutputConnections;
std::unordered_map<AbstractQuantumWire*, QuantumCircuitElement*> mWireInputConnections;
std::unordered_map<AbstractQuantumWire*, QuantumCircuitElement*> mWireOutputConnections;
Map<QuantumCircuitElement*, QuantumCircuitElementNode*> mNodesForContent;
std::unordered_map<QuantumCircuitElement*, QuantumCircuitElementNode*> mNodesForContent;
};

View file

@ -44,7 +44,7 @@ void QuantumGateNode::createOrUpdateGeometry(SceneInfo*)
{
mLabel = std::make_unique<EquationNode>(Point(mBodyWidth /3.0, mBodyHeight / 3.0));
String label_content;
std::string label_content;
if (mContent->getGateType() == QuantumGate::GateType::X)
{
label_content = "X";
@ -75,9 +75,9 @@ void QuantumGateNode::createOrUpdateGeometry(SceneInfo*)
Point2 QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
{
bool is_input{ false };
//size_t connection_id{ 0 };
//std::size_t connection_id{ 0 };
for (size_t idx = 0; idx < mContent->getNumInputs(); idx++)
for (std::size_t idx = 0; idx < mContent->getNumInputs(); idx++)
{
if (mContent->getInput(idx) == wire)
{
@ -87,7 +87,7 @@ Point2 QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
}
}
for (size_t idx = 0; idx < mContent->getNumOutputs(); idx++)
for (std::size_t idx = 0; idx < mContent->getNumOutputs(); idx++)
{
if (mContent->getOutput(idx) == wire)
{

View file

@ -25,10 +25,10 @@ private:
QuantumGate* mContent{ nullptr };
bool mContentDirty{ true };
Ptr<RectangleNode> mBody;
std::unique_ptr<RectangleNode> mBody;
double mBodyWidth = 30;
double mBodyHeight = 24;
Ptr<LatexMathExpression> mLabelExpression;
Ptr<EquationNode> mLabel;
std::unique_ptr<LatexMathExpression> mLabelExpression;
std::unique_ptr<EquationNode> mLabel;
};

View file

@ -30,7 +30,7 @@ void QuantumTerminalNode::createOrUpdateGeometry(SceneInfo*)
if (!mLabel && mContent->getTerminalType() != QuantumTerminal::TerminalType::OUTPUT)
{
const auto value = mContent->getValue();
String label;
std::string label;
if (value.isIn0State())
{
label = "\\ket{0}";

View file

@ -25,6 +25,6 @@ private:
double mWidth = 20.0;
double mHeight = 10.0;
Ptr<LatexMathExpression> mLabelExpression;
Ptr<EquationNode> mLabel;
std::unique_ptr<LatexMathExpression> mLabelExpression;
std::unique_ptr<EquationNode> mLabel;
};

View file

@ -54,7 +54,7 @@ void QuantumWireNode::createOrUpdateGeometry(SceneInfo*)
auto loc = mOutputLocation;
loc.moveBy(-mInputLocation.getX(), -mInputLocation.getY(), -mInputLocation.getZ());
Vector<Point2> points;
std::vector<Point2> points;
if (loc.getY() == 0.0)
{

View file

@ -29,5 +29,5 @@ private:
Point2 mInputLocation;
Point2 mOutputLocation;
Ptr<LineNode> mLine;
std::unique_ptr<LineNode> mLine;
};

7
src/CMakeLists.txt Normal file
View file

@ -0,0 +1,7 @@
add_subdirectory(base)
add_subdirectory(console)
add_subdirectory(media)
add_subdirectory(publishing)
add_subdirectory(rendering)
add_subdirectory(ui)
add_subdirectory(web)

6
src/base/CMakeLists.txt Normal file
View file

@ -0,0 +1,6 @@
add_subdirectory(compiler)
add_subdirectory(compression)
add_subdirectory(core)
add_subdirectory(database)
add_subdirectory(geometry)
add_subdirectory(network)

View file

@ -0,0 +1,28 @@
set(MODULE_NAME compiler)
list(APPEND HEADERS
Lexer.h
template_engine/TemplatingEngine.h
template_engine/TemplateFile.h
template_engine/TemplateNode.h
template_engine/TemplateElements.h
)
list(APPEND SOURCES
Lexer.cpp
template_engine/TemplatingEngine.cpp
template_engine/TemplateFile.cpp
template_engine/TemplateNode.cpp
template_engine/TemplateElements.cpp
)
add_library(${MODULE_NAME} SHARED ${HEADERS} ${SOURCES})
target_include_directories(${MODULE_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/template_engine
)
target_link_libraries( ${MODULE_NAME} PUBLIC core)
set_target_properties( ${MODULE_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src/base)

View file

@ -1,78 +0,0 @@
#include "KScope.h"
#include <stdio.h>
void KScopeLexer::run(const FileSystemPath& path)
{
printf("Before read");
File f(path);
const auto content = f<.readText();
printf("Content is: %s\n", content);
fflush(stdout);
Vector<Token> tokens;
for(const auto c : content.data())
{
printf("Char is: %c\n", c);
if (CharUtils::is_space(c))
{
if (m_working_token.is_identifier() || m_working_token.is_number())
{
on_token_finished(tokens);
}
}
else if (CharUtils::is_alpha(c))
{
if (m_working_token.is_number())
{
on_token_finished(tokens);
m_working_token = Token();
m_working_token.set_is_identifier();
}
else if (!m_working_token.is_identifier())
{
m_working_token = Token();
m_working_token.set_is_identifier();
}
m_working_token.m_value += c;
}
else if (CharUtils::is_digit(c))
{
if (m_working_token.is_number() || m_working_token.is_identifier())
{
m_working_token.m_value += c;
}
else
{
m_working_token = Token();
m_working_token.set_is_number();
m_working_token.m_value += c;
}
}
else
{
if (m_working_token.is_identifier() || m_working_token.is_number())
{
on_token_finished(tokens);
}
m_working_token.set_is_literal();
m_working_token.m_value += c;
on_token_finished(tokens);
}
}
on_token_finished(tokens);
}
void KScopeLexer::on_token_finished(Vector<Token>& tokens)
{
if (m_working_token.m_type == TokenT::NONE)
{
return;
}
m_working_token.on_finished();
tokens.push_back(m_working_token);
m_working_token = Token();
}

View file

@ -1,86 +0,0 @@
#pragma once
#include "String.h"
#include "File.h"
#include "Vector.h"
#include "CharUtils.h"
class KScopeLexer
{
public:
enum class TokenT
{
NONE,
DEF, // LANG COMMANDS
EXTERN,
IDENTIFIER ,// GENERAL
LITERAL,
NUMBER
};
struct Token
{
bool is_identifier() const
{
return m_type == TokenT::IDENTIFIER;
}
bool is_number() const
{
return m_type == TokenT::NUMBER;
}
void set_is_identifier()
{
m_type = TokenT::IDENTIFIER;
}
void set_is_number()
{
m_type = TokenT::NUMBER;
}
void set_is_literal()
{
m_type = TokenT::LITERAL;
}
void on_identifier_finished()
{
if (m_value == "def")
{
m_type = TokenT::DEF;
}
else if (m_value == "extern")
{
m_type = TokenT::EXTERN;
}
}
void on_number_finished()
{
}
void on_finished()
{
if (is_identifier())
{
on_identifier_finished();
}
else if(is_number())
{
on_number_finished();
}
}
TokenT m_type{TokenT::NONE};
String m_value;
};
void run(const FileSystemPath& path);
void on_token_finished(Vector<Token>& tokens);
Token m_working_token;
};

View file

@ -1,6 +1,6 @@
#include "Lexer.h"
bool Lexer::matchPattern(const String& pattern, const String& checkString, char delimiter, Vector<String>& hitSequence)
bool Lexer::matchPattern(const std::string& pattern, const std::string& checkString, char delimiter, std::vector<std::string>& hitSequence)
{
if (checkString.empty())
{
@ -16,8 +16,8 @@ bool Lexer::matchPattern(const String& pattern, const String& checkString, char
unsigned check_idx = 0;
unsigned pattern_idx = 0;
Vector<String> hits;
String working_hit;
std::vector<std::string> hits;
std::string working_hit;
while(check_idx < checkString.size())
{
if (pattern_idx == pattern.size())

View file

@ -1,11 +1,11 @@
#pragma once
#include "String.h"
#include "Vector.h"
#include <string>
#include <vector>
class Lexer
{
public:
// e.g. Pattern [@](@) returns <source, tag> for input: [source](tag) and delimiter @
static bool matchPattern(const String& pattern, const String& checkString, char delimiter, Vector<String>& hitSequence);
static bool matchPattern(const std::string& pattern, const std::string& checkString, char delimiter, std::vector<std::string>& hitSequence);
};

Some files were not shown because too many files have changed in this diff Show more