Compare commits

..

10 commits

Author SHA1 Message Date
James Grogan
849d8d8ca2
Update README.md 2024-02-02 10:29:59 +00:00
jmsgrogan
3dce256213 Start support for multiple build targets. 2024-01-28 16:28:16 +00:00
jmsgrogan
e3e03dc31f Start proper stream support. 2024-01-21 16:27:30 +00:00
jmsgrogan
5183aa821a Start supporting dict and json types. 2024-01-03 09:13:23 +00:00
jmsgrogan
94fcc42aed Core lib building 2024-01-02 16:14:23 +00:00
jmsgrogan
3ed195d7dd Toward core module compiling. 2023-12-27 12:20:02 +00:00
jmsgrogan
c25a56ee19 Do bulk replace of stl types. 2023-12-21 09:18:44 +00:00
jmsgrogan
521486be62 Start working on build system. 2023-12-20 16:58:22 +00:00
jmsgrogan
4b308f6c32 Initial test bootstrap. 2023-12-18 10:16:31 +00:00
jmsgrogan
6c618749f1 Switch to GPL V3. 2023-10-02 16:34:33 +01:00
706 changed files with 9260 additions and 5201 deletions

View file

@ -1,10 +1,8 @@
Notes Toolkit (NotesTK) is a set of tools for building applications focused on taking and organising notes. 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) Copyright (C) 2023 James Grogan (grogan.ox@gmail.com)
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 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.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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 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. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
See https://opensource.org/licenses/MIT

View file

@ -1,61 +1,14 @@
# NotesTK # 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. This is a hobby-repo I use for learning about different software technologies by trying to build stuff from scratch.
## Project Goals It covers a bunch of areas:
* Cross-platform * Build tooling
* Low third-party dependencies * Audio and Video
* Permissive licensing * 3D modelling
* Simplicity over performance * Desktop window management and UIs
## Project Status Nothing here should be used in a real project :)
🚨🚨🚨 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 "DesktopManager.h"
#include "MainApplication.h" #include "MainApplication.h"
NotesTk::NotesTk(std::unique_ptr<CommandLineArgs> args, std::unique_ptr<MainApplication> mainApp) NotesTk::NotesTk(Ptr<CommandLineArgs> args, Ptr<MainApplication> mainApp)
: GuiApplication(std::move(args), std::move(mainApp)) : GuiApplication(std::move(args), std::move(mainApp))
{ {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

46
bootstrap.sh Executable file
View file

@ -0,0 +1,46 @@
#!/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 #pragma once
#include <string> #include "String.h"
#include <memory> #include "Pointer.h"
class CircuitElement class CircuitElement

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,11 +1,11 @@
#include "LogicGatePrimitiveShapes.h" #include "LogicGatePrimitiveShapes.h"
std::string LogicGatePrimitiveShapes::getAndGateShape() String LogicGatePrimitiveShapes::getAndGateShape()
{ {
return "M4 8 h24 a16 16 0 0 1 0 32 h-24Z"; return "M4 8 h24 a16 16 0 0 1 0 32 h-24Z";
} }
Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, std::size_t idx) Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, size_t idx)
{ {
if (isInput) if (isInput)
{ {
@ -24,12 +24,12 @@ Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, std:
} }
} }
std::string LogicGatePrimitiveShapes::getOrGateShape() String LogicGatePrimitiveShapes::getOrGateShape()
{ {
return "M4 8 h16 q16 2 24 16 q-12 16 -24 16 h-16 q12 -16 0 -32Z"; return "M4 8 h16 q16 2 24 16 q-12 16 -24 16 h-16 q12 -16 0 -32Z";
} }
Point2 LogicGatePrimitiveShapes::getOrGateConnectionLocation(bool isInput, std::size_t idx) Point2 LogicGatePrimitiveShapes::getOrGateConnectionLocation(bool isInput, size_t idx)
{ {
if (isInput) if (isInput)
{ {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@
#include "AbstractVisualNode.h" #include "AbstractVisualNode.h"
#include <unordered_map> #include Map.h
class QuantumCircuit; class QuantumCircuit;
class QuantumCircuitElement; class QuantumCircuitElement;
@ -29,13 +29,13 @@ private:
bool mContentDirty{ true }; bool mContentDirty{ true };
QuantumCircuit* mContent{ nullptr }; QuantumCircuit* mContent{ nullptr };
std::vector<std::unique_ptr<QuantumTerminalNode> > mInputTerminalNodes; Vector<Ptr<QuantumTerminalNode> > mInputTerminalNodes;
std::vector<std::unique_ptr<QuantumTerminalNode> > mOutputTerminalNodes; Vector<Ptr<QuantumTerminalNode> > mOutputTerminalNodes;
std::vector<std::unique_ptr<QuantumGateNode> > mGateNodes; Vector<Ptr<QuantumGateNode> > mGateNodes;
std::vector<std::unique_ptr<QuantumWireNode> > mWireNodes; Vector<Ptr<QuantumWireNode> > mWireNodes;
std::unordered_map<AbstractQuantumWire*, QuantumCircuitElement*> mWireInputConnections; Map<AbstractQuantumWire*, QuantumCircuitElement*> mWireInputConnections;
std::unordered_map<AbstractQuantumWire*, QuantumCircuitElement*> mWireOutputConnections; Map<AbstractQuantumWire*, QuantumCircuitElement*> mWireOutputConnections;
std::unordered_map<QuantumCircuitElement*, QuantumCircuitElementNode*> mNodesForContent; 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)); mLabel = std::make_unique<EquationNode>(Point(mBodyWidth /3.0, mBodyHeight / 3.0));
std::string label_content; String label_content;
if (mContent->getGateType() == QuantumGate::GateType::X) if (mContent->getGateType() == QuantumGate::GateType::X)
{ {
label_content = "X"; label_content = "X";
@ -75,9 +75,9 @@ void QuantumGateNode::createOrUpdateGeometry(SceneInfo*)
Point2 QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const Point2 QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
{ {
bool is_input{ false }; bool is_input{ false };
//std::size_t connection_id{ 0 }; //size_t connection_id{ 0 };
for (std::size_t idx = 0; idx < mContent->getNumInputs(); idx++) for (size_t idx = 0; idx < mContent->getNumInputs(); idx++)
{ {
if (mContent->getInput(idx) == wire) if (mContent->getInput(idx) == wire)
{ {
@ -87,7 +87,7 @@ Point2 QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
} }
} }
for (std::size_t idx = 0; idx < mContent->getNumOutputs(); idx++) for (size_t idx = 0; idx < mContent->getNumOutputs(); idx++)
{ {
if (mContent->getOutput(idx) == wire) if (mContent->getOutput(idx) == wire)
{ {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,78 @@
#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

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

View file

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

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