Compare commits
No commits in common. "849d8d8ca2ff8cd6acc5e0bc176e1da8e7dab58d" and "bb222fd84d7d0dd6bd75d12ccd2f6adf179c42c0" have entirely different histories.
849d8d8ca2
...
bb222fd84d
706 changed files with 5203 additions and 9262 deletions
8
LICENSE
8
LICENSE
|
@ -1,8 +1,10 @@
|
||||||
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)
|
||||||
|
|
||||||
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
|
||||||
|
|
63
README.md
63
README.md
|
@ -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
|
* Cross-platform
|
||||||
* Audio and Video
|
* Low third-party dependencies
|
||||||
* 3D modelling
|
* Permissive licensing
|
||||||
* Desktop window management and UIs
|
* 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.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "DesktopManager.h"
|
#include "DesktopManager.h"
|
||||||
#include "MainApplication.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))
|
: GuiApplication(std::move(args), std::move(mainApp))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
class NotesTk : public GuiApplication
|
class NotesTk : public GuiApplication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NotesTk(Ptr<CommandLineArgs> args = nullptr, Ptr<MainApplication> mainApp = nullptr);
|
NotesTk(std::unique_ptr<CommandLineArgs> args = nullptr, std::unique_ptr<MainApplication> mainApp = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initializeViews() override;
|
void initializeViews() override;
|
||||||
|
|
|
@ -12,7 +12,7 @@ AudioEditorView::AudioEditorView()
|
||||||
addWidget(std::move(label));
|
addWidget(std::move(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<AudioEditorView> AudioEditorView::Create()
|
std::unique_ptr<AudioEditorView> AudioEditorView::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<AudioEditorView>();
|
return std::make_unique<AudioEditorView>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ public:
|
||||||
|
|
||||||
AudioEditorView();
|
AudioEditorView();
|
||||||
|
|
||||||
static Ptr<AudioEditorView> Create();
|
static std::unique_ptr<AudioEditorView> Create();
|
||||||
};
|
};
|
||||||
|
|
||||||
using AudioEditorViewUPtr = Ptr<AudioEditorView>;
|
using AudioEditorViewUPtr = std::unique_ptr<AudioEditorView>;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "CanvasController.h"
|
#include "CanvasController.h"
|
||||||
|
|
||||||
Ptr<CanvasController> CanvasController::Create()
|
std::unique_ptr<CanvasController> CanvasController::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<CanvasController>();
|
return std::make_unique<CanvasController>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
|
|
||||||
class CanvasController
|
class CanvasController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Ptr<CanvasController> Create();
|
static std::unique_ptr<CanvasController> Create();
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,6 +24,6 @@ private:
|
||||||
|
|
||||||
CanvasDrawCommand mActiveDrawingCommand{CanvasDrawCommand::LINE};
|
CanvasDrawCommand mActiveDrawingCommand{CanvasDrawCommand::LINE};
|
||||||
|
|
||||||
Vector<Ptr<GeometryNode> > mSceneNodes;
|
std::vector<std::unique_ptr<GeometryNode> > mSceneNodes;
|
||||||
bool mContentDirty{false};
|
bool mContentDirty{false};
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,7 @@ CanvasView::~CanvasView()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<CanvasView> CanvasView::Create()
|
std::unique_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<Widget> CanvasView::initializeCacheButtons()
|
std::unique_ptr<Widget> CanvasView::initializeCacheButtons()
|
||||||
{
|
{
|
||||||
auto saveButton = Button::Create();
|
auto saveButton = Button::Create();
|
||||||
saveButton->setLabel("Save");
|
saveButton->setLabel("Save");
|
||||||
|
|
|
@ -13,17 +13,17 @@ public:
|
||||||
|
|
||||||
~CanvasView();
|
~CanvasView();
|
||||||
|
|
||||||
static Ptr<CanvasView> Create();
|
static std::unique_ptr<CanvasView> Create();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onDrawCommandChanged(CanvasDrawCommand command);
|
void onDrawCommandChanged(CanvasDrawCommand command);
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
Ptr<Widget> initializeCacheButtons();
|
std::unique_ptr<Widget> initializeCacheButtons();
|
||||||
|
|
||||||
Ptr<CanvasController> mController;
|
std::unique_ptr<CanvasController> mController;
|
||||||
|
|
||||||
CanvasDrawingArea* mDrawingArea{nullptr};
|
CanvasDrawingArea* mDrawingArea{nullptr};
|
||||||
};
|
};
|
||||||
using CanvasViewPtr = Ptr<CanvasView>;
|
using CanvasViewPtr = std::unique_ptr<CanvasView>;
|
||||||
|
|
|
@ -28,7 +28,7 @@ ImageEditorView::~ImageEditorView()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<ImageEditorView> ImageEditorView::Create()
|
std::unique_ptr<ImageEditorView> ImageEditorView::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<ImageEditorView>();
|
return std::make_unique<ImageEditorView>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ public:
|
||||||
|
|
||||||
virtual ~ImageEditorView();
|
virtual ~ImageEditorView();
|
||||||
|
|
||||||
static Ptr<ImageEditorView> Create();
|
static std::unique_ptr<ImageEditorView> Create();
|
||||||
};
|
};
|
||||||
|
|
||||||
using ImageEditorViewUPtr = Ptr<ImageEditorView>;
|
using ImageEditorViewUPtr = std::unique_ptr<ImageEditorView>;
|
||||||
|
|
|
@ -16,5 +16,5 @@ private:
|
||||||
unsigned mNumX{5};
|
unsigned mNumX{5};
|
||||||
unsigned mNumY{5};
|
unsigned mNumY{5};
|
||||||
|
|
||||||
Ptr<GridNode> mGridNode;
|
std::unique_ptr<GridNode> mGridNode;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
|
|
||||||
#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::WAYLAND_RASTER);
|
//app.setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER);
|
||||||
app.run();
|
app.run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Ptr<MeshViewerView> MeshViewerView::Create()
|
std::unique_ptr<MeshViewerView> MeshViewerView::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<MeshViewerView>();
|
return std::make_unique<MeshViewerView>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,10 @@ class MeshViewerView : public Widget
|
||||||
public:
|
public:
|
||||||
MeshViewerView();
|
MeshViewerView();
|
||||||
~MeshViewerView();
|
~MeshViewerView();
|
||||||
static Ptr<MeshViewerView> Create();
|
static std::unique_ptr<MeshViewerView> Create();
|
||||||
void doPaint(const PaintEvent* event) override;
|
void doPaint(const PaintEvent* event) override;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Ptr<AbstractMesh> mMesh;
|
std::unique_ptr<AbstractMesh> mMesh;
|
||||||
Ptr<MeshNode> mMeshNode;
|
std::unique_ptr<MeshNode> mMeshNode;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,17 +6,17 @@ PlainTextDocument::PlainTextDocument()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<PlainTextDocument> PlainTextDocument::Create()
|
std::unique_ptr<PlainTextDocument> PlainTextDocument::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<PlainTextDocument>();
|
return std::make_unique<PlainTextDocument>();
|
||||||
}
|
}
|
||||||
|
|
||||||
String PlainTextDocument::GetContent() const
|
std::string PlainTextDocument::GetContent() const
|
||||||
{
|
{
|
||||||
return mContent;
|
return mContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlainTextDocument::SetContent(const String& content)
|
void PlainTextDocument::SetContent(const std::string& content)
|
||||||
{
|
{
|
||||||
mContent = content;
|
mContent = content;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
|
|
||||||
class PlainTextDocument
|
class PlainTextDocument
|
||||||
{
|
{
|
||||||
String mContent;
|
std::string mContent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PlainTextDocument();
|
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();
|
void Clear();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using PlainTextDocumentUPtr = Ptr<PlainTextDocument>;
|
using PlainTextDocumentUPtr = std::unique_ptr<PlainTextDocument>;
|
||||||
|
|
|
@ -9,17 +9,17 @@ TextEditorController::TextEditorController()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<TextEditorController> TextEditorController::Create()
|
std::unique_ptr<TextEditorController> TextEditorController::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<TextEditorController>();
|
return std::make_unique<TextEditorController>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorController::SetContent(const String& content)
|
void TextEditorController::SetContent(const std::string& content)
|
||||||
{
|
{
|
||||||
mModel->GetDocument()->SetContent(content);
|
mModel->GetDocument()->SetContent(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
String TextEditorController::GetContent() const
|
std::string TextEditorController::GetContent() const
|
||||||
{
|
{
|
||||||
return mModel->GetDocument()->GetContent();
|
return mModel->GetDocument()->GetContent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "TextEditorModel.h"
|
#include "TextEditorModel.h"
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ public:
|
||||||
|
|
||||||
TextEditorController();
|
TextEditorController();
|
||||||
|
|
||||||
static Ptr<TextEditorController> Create();
|
static std::unique_ptr<TextEditorController> Create();
|
||||||
|
|
||||||
void OnSave();
|
void OnSave();
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ public:
|
||||||
|
|
||||||
void OnLoad();
|
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);
|
void SetSavePath(const std::filesystem::path& path);
|
||||||
|
|
||||||
|
@ -31,4 +31,4 @@ private:
|
||||||
std::filesystem::path mLoadPath;
|
std::filesystem::path mLoadPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
using TextEditorControllerUPtr = Ptr<TextEditorController>;
|
using TextEditorControllerUPtr = std::unique_ptr<TextEditorController>;
|
||||||
|
|
|
@ -6,7 +6,7 @@ TextEditorModel::TextEditorModel()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<TextEditorModel> TextEditorModel::Create()
|
std::unique_ptr<TextEditorModel> TextEditorModel::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<TextEditorModel>();
|
return std::make_unique<TextEditorModel>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "PlainTextDocument.h"
|
#include "PlainTextDocument.h"
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
|
|
||||||
class TextEditorModel
|
class TextEditorModel
|
||||||
{
|
{
|
||||||
|
@ -11,9 +11,9 @@ public:
|
||||||
|
|
||||||
TextEditorModel();
|
TextEditorModel();
|
||||||
|
|
||||||
static Ptr<TextEditorModel> Create();
|
static std::unique_ptr<TextEditorModel> Create();
|
||||||
|
|
||||||
PlainTextDocument* GetDocument() const;
|
PlainTextDocument* GetDocument() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
using TextEditorModelUPtr = Ptr<TextEditorModel>;
|
using TextEditorModelUPtr = std::unique_ptr<TextEditorModel>;
|
||||||
|
|
|
@ -81,7 +81,7 @@ void TextEditorView::initialize()
|
||||||
addWidget(std::move(hSpacer));
|
addWidget(std::move(hSpacer));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<TextEditorView> TextEditorView::Create()
|
std::unique_ptr<TextEditorView> TextEditorView::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<TextEditorView>();
|
return std::make_unique<TextEditorView>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ class TextEditorView : public Widget
|
||||||
public:
|
public:
|
||||||
TextEditorView();
|
TextEditorView();
|
||||||
|
|
||||||
static Ptr<TextEditorView> Create();
|
static std::unique_ptr<TextEditorView> Create();
|
||||||
|
|
||||||
TextEditorController* getController();
|
TextEditorController* getController();
|
||||||
|
|
||||||
|
@ -23,4 +23,4 @@ private:
|
||||||
TextBox* mTextBox;
|
TextBox* mTextBox;
|
||||||
TextEditorControllerUPtr mController;
|
TextEditorControllerUPtr mController;
|
||||||
};
|
};
|
||||||
using TextEditorViewUPtr = Ptr<TextEditorView>;
|
using TextEditorViewUPtr = std::unique_ptr<TextEditorView>;
|
||||||
|
|
|
@ -14,7 +14,7 @@ WebClientView::WebClientView()
|
||||||
addWidget(std::move(label));
|
addWidget(std::move(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<WebClientView> WebClientView::Create()
|
std::unique_ptr<WebClientView> WebClientView::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<WebClientView>();
|
return std::make_unique<WebClientView>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ public:
|
||||||
|
|
||||||
WebClientView();
|
WebClientView();
|
||||||
|
|
||||||
static Ptr<WebClientView> Create();
|
static std::unique_ptr<WebClientView> Create();
|
||||||
};
|
};
|
||||||
|
|
||||||
using WebClientViewUPtr = Ptr<WebClientView>;
|
using WebClientViewUPtr = std::unique_ptr<WebClientView>;
|
||||||
|
|
|
@ -23,7 +23,7 @@ Path ContentFile::getFilename() const
|
||||||
return mFilename;
|
return mFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ContentFile::getOutputLocation() const
|
std::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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String ContentFile::getMetadataItem(const String& key) const
|
std::string ContentFile::getMetadataItem(const std::string& key) const
|
||||||
{
|
{
|
||||||
const auto check = mMetadata.find(key);
|
const auto check = mMetadata.find(key);
|
||||||
if (check == mMetadata.end())
|
if (check == mMetadata.end())
|
||||||
|
|
|
@ -3,17 +3,17 @@
|
||||||
#include "MarkdownContentParser.h"
|
#include "MarkdownContentParser.h"
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include Map.h
|
#include <unordered_map>
|
||||||
|
|
||||||
class MarkdownDocument;
|
class MarkdownDocument;
|
||||||
|
|
||||||
class ContentFile
|
class ContentFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using FileMetadata = Map<String, String>;
|
using FileMetadata = std::unordered_map<std::string, std::string>;
|
||||||
using FileContentBody = Vector<String>;
|
using FileContentBody = std::vector<std::string>;
|
||||||
|
|
||||||
ContentFile(const Path& filename);
|
ContentFile(const Path& filename);
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ public:
|
||||||
|
|
||||||
virtual void load();
|
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
|
MarkdownDocument* getContentBody() const
|
||||||
{
|
{
|
||||||
|
@ -36,15 +36,15 @@ public:
|
||||||
|
|
||||||
void write(const Path& path);
|
void write(const Path& path);
|
||||||
|
|
||||||
void setProcessedOutput(const String& output)
|
void setProcessedOutput(const std::string& output)
|
||||||
{
|
{
|
||||||
mProcessedOutput = output;
|
mProcessedOutput = output;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
Path mFilename;
|
Path mFilename;
|
||||||
FileMetadata mMetadata;
|
FileMetadata mMetadata;
|
||||||
Ptr<MarkdownDocument> mContentBody;
|
std::unique_ptr<MarkdownDocument> mContentBody;
|
||||||
String mProcessedOutput;
|
std::string mProcessedOutput;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ContentArticle : public ContentFile
|
class ContentArticle : public ContentFile
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "File.h"
|
#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 metadata;
|
||||||
FileMetadata output_metadata;
|
FileMetadata output_metadata;
|
||||||
|
@ -15,7 +15,7 @@ std::pair<MarkdownContentParser::FileMetadata, Ptr<MarkdownDocument>> MarkdownCo
|
||||||
const auto lines = File(path).readLines();
|
const auto lines = File(path).readLines();
|
||||||
bool metadata_finished = false;
|
bool metadata_finished = false;
|
||||||
|
|
||||||
String content_body;
|
std::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, Ptr<MarkdownDocument>> MarkdownCo
|
||||||
return {output_metadata, std::move(document)};
|
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;
|
unsigned char_count = 0;
|
||||||
String prefix;
|
std::string prefix;
|
||||||
String suffix;
|
std::string suffix;
|
||||||
bool building_prefix = true;
|
bool building_prefix = true;
|
||||||
for (const auto c : line)
|
for (const auto c : line)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include Map.h
|
#include <unordered_map>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
|
|
||||||
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<String, String>;
|
using FileMetadataItem = std::pair<std::string, std::string>;
|
||||||
using FileMetadata = Map<String, 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:
|
private:
|
||||||
Optional<FileMetadataItem> checkForMetadataItem(const String& line) const;
|
std::optional<FileMetadataItem> checkForMetadataItem(const std::string& line) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@ Path SiteGeneratorConfig::getThemePath() const
|
||||||
return mThemesPath;
|
return mThemesPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
String SiteGeneratorConfig::getActiveTheme() const
|
std::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 String& theme)
|
void SiteGeneratorConfig::setActiveTheme(const std::string& theme)
|
||||||
{
|
{
|
||||||
mActiveTheme = theme;
|
mActiveTheme = theme;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
#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;
|
||||||
|
|
||||||
String getActiveTheme() const;
|
std::string getActiveTheme() const;
|
||||||
|
|
||||||
void setThemePath(const Path& path);
|
void setThemePath(const Path& path);
|
||||||
|
|
||||||
void setActiveTheme(const String& theme);
|
void setActiveTheme(const std::string& theme);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Path mThemesPath;
|
Path mThemesPath;
|
||||||
String mActiveTheme;
|
std::string mActiveTheme;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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";
|
const auto config_path = std::filesystem::path(searchPath) / "config.toml";
|
||||||
if (std::filesystem::exists(config_path))
|
if (std::filesystem::exists(config_path))
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include Map.h
|
#include <unordered_map>
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
|
|
||||||
using Path = std::filesystem::path;
|
using Path = std::filesystem::path;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
void doSubstitutions();
|
void doSubstitutions();
|
||||||
|
|
||||||
void findProject(const String& searchPath);
|
void findProject(const std::string& searchPath);
|
||||||
|
|
||||||
void parseContentFiles();
|
void parseContentFiles();
|
||||||
|
|
||||||
|
@ -47,9 +47,9 @@ private:
|
||||||
|
|
||||||
std::filesystem::path mProjectPath;
|
std::filesystem::path mProjectPath;
|
||||||
|
|
||||||
Ptr<SiteGeneratorConfig> mConfig;
|
std::unique_ptr<SiteGeneratorConfig> mConfig;
|
||||||
Ptr<TemplatingEngine> mTemplateEngine;
|
std::unique_ptr<TemplatingEngine> mTemplateEngine;
|
||||||
|
|
||||||
Vector<Ptr<ContentPage> > mPages;
|
std::vector<std::unique_ptr<ContentPage> > mPages;
|
||||||
Vector<Ptr<ContentArticle> > mArticles;
|
std::vector<std::unique_ptr<ContentArticle> > mArticles;
|
||||||
};
|
};
|
||||||
|
|
46
bootstrap.sh
46
bootstrap.sh
|
@ -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
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
class CircuitElement
|
class CircuitElement
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
|
|
||||||
#include "CircuitElement.h"
|
#include "CircuitElement.h"
|
||||||
#include "LogicGate.h"
|
#include "LogicGate.h"
|
||||||
#include "Terminal.h"
|
#include "Terminal.h"
|
||||||
|
|
||||||
using LogicGatePtr = Ptr<LogicGate>;
|
using LogicGatePtr = std::unique_ptr<LogicGate>;
|
||||||
|
|
||||||
class ElectronicCircuit
|
class ElectronicCircuit
|
||||||
{
|
{
|
||||||
|
@ -20,33 +20,33 @@ public:
|
||||||
|
|
||||||
void addLogicGate(LogicGatePtr gate);
|
void addLogicGate(LogicGatePtr gate);
|
||||||
|
|
||||||
const Vector<Terminal*>& getInputTerminals() const
|
const std::vector<Terminal*>& getInputTerminals() const
|
||||||
{
|
{
|
||||||
return mInputTerminals;
|
return mInputTerminals;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<Terminal*>& getOutputTerminals() const
|
const std::vector<Terminal*>& getOutputTerminals() const
|
||||||
{
|
{
|
||||||
return mOutputTerminals;
|
return mOutputTerminals;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<LogicGate*>& getLogicGates() const
|
const std::vector<LogicGate*>& getLogicGates() const
|
||||||
{
|
{
|
||||||
return mLogicGates;
|
return mLogicGates;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<Wire*>& getWires() const
|
const std::vector<Wire*>& getWires() const
|
||||||
{
|
{
|
||||||
return mWires;
|
return mWires;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Terminal*> mInputTerminals;
|
std::vector<Terminal*> mInputTerminals;
|
||||||
Vector<Terminal*> mOutputTerminals;
|
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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "Terminal.h"
|
#include "Terminal.h"
|
||||||
|
|
||||||
Terminal::Terminal(TerminalType type, const String& label)
|
Terminal::Terminal(TerminalType type, const std::string& label)
|
||||||
: mLabel(label),
|
: mLabel(label),
|
||||||
mType(type)
|
mType(type)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "CircuitElement.h"
|
#include "CircuitElement.h"
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
class Wire;
|
class Wire;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ public:
|
||||||
OUTPUT
|
OUTPUT
|
||||||
};
|
};
|
||||||
|
|
||||||
Terminal(TerminalType type, const String& label = {});
|
Terminal(TerminalType type, const std::string& label = {});
|
||||||
|
|
||||||
Wire* getConnection() const;
|
Wire* getConnection() const;
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ public:
|
||||||
void setConnection(Wire* connection);
|
void setConnection(Wire* connection);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String mLabel;
|
std::string mLabel;
|
||||||
TerminalType mType;
|
TerminalType mType;
|
||||||
Wire* mConnection{ nullptr };
|
Wire* mConnection{ nullptr };
|
||||||
};
|
};
|
||||||
using TerminalPtr = Ptr<Terminal>;
|
using TerminalPtr = std::unique_ptr<Terminal>;
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
|
|
||||||
class TruthTable
|
class TruthTable
|
||||||
{
|
{
|
||||||
public:
|
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),
|
//: 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:
|
||||||
//size_t mNumInputColumns{ 0 };
|
//std::size_t mNumInputColumns{ 0 };
|
||||||
//size_t mNumOutputColumns{ 0 };
|
//std::size_t mNumOutputColumns{ 0 };
|
||||||
|
|
||||||
TableData mTable;
|
TableData mTable;
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,7 @@ private:
|
||||||
CircuitElement* mInput{ nullptr };
|
CircuitElement* mInput{ nullptr };
|
||||||
CircuitElement* mOutput{ nullptr };
|
CircuitElement* mOutput{ nullptr };
|
||||||
};
|
};
|
||||||
using WirePtr = Ptr<Wire>;
|
using WirePtr = std::unique_ptr<Wire>;
|
||||||
|
|
||||||
class Fanout : public CircuitElement
|
class Fanout : public CircuitElement
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "LogicGate.h"
|
#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(),
|
: LogicGate(),
|
||||||
mNumIn(numIn),
|
mNumIn(numIn),
|
||||||
mNumOut(numOut)
|
mNumOut(numOut)
|
||||||
|
@ -11,7 +11,7 @@ NInMOutLogicGate::NInMOutLogicGate(size_t numIn, size_t numOut, Vector<Wire*> in
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mInputs = Vector<Wire*>(numIn, nullptr);
|
mInputs = std::vector<Wire*>(numIn, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputs.size() == mNumOut)
|
if (outputs.size() == mNumOut)
|
||||||
|
@ -20,21 +20,21 @@ NInMOutLogicGate::NInMOutLogicGate(size_t numIn, size_t numOut, Vector<Wire*> in
|
||||||
}
|
}
|
||||||
else
|
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;
|
return mNumIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t NInMOutLogicGate::getNumOutputs() const
|
std::size_t NInMOutLogicGate::getNumOutputs() const
|
||||||
{
|
{
|
||||||
return mNumOut;
|
return mNumOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
Wire* NInMOutLogicGate::getInput(size_t idx) const
|
Wire* NInMOutLogicGate::getInput(std::size_t idx) const
|
||||||
{
|
{
|
||||||
if (idx < mNumIn)
|
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)
|
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())
|
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())
|
if (idx < mOutputs.size())
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
#include "TruthTable.h"
|
#include "TruthTable.h"
|
||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
|
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
|
|
||||||
class LogicGate : public CircuitElement
|
class LogicGate : public CircuitElement
|
||||||
{
|
{
|
||||||
|
@ -20,13 +20,13 @@ public:
|
||||||
};
|
};
|
||||||
virtual ~LogicGate() = default;
|
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;
|
virtual const TruthTable& getTruthTable() = 0;
|
||||||
|
|
||||||
|
@ -41,28 +41,28 @@ public:
|
||||||
class NInMOutLogicGate : public LogicGate
|
class NInMOutLogicGate : public LogicGate
|
||||||
{
|
{
|
||||||
public:
|
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;
|
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:
|
private:
|
||||||
size_t mNumIn{ 1 };
|
std::size_t mNumIn{ 1 };
|
||||||
size_t mNumOut{ 1 };
|
std::size_t mNumOut{ 1 };
|
||||||
|
|
||||||
Vector<Wire*> mInputs;
|
std::vector<Wire*> mInputs;
|
||||||
Vector<Wire*> mOutputs;
|
std::vector<Wire*> mOutputs;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TwoInOneOutLogicGate : public NInMOutLogicGate
|
class TwoInOneOutLogicGate : public NInMOutLogicGate
|
||||||
|
|
|
@ -37,12 +37,12 @@ void ElectronicCircuitNode::buildWireConnections()
|
||||||
|
|
||||||
for (auto gate : mContent->getLogicGates())
|
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;
|
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;
|
mWireOutputConnections[gate->getOutput(idx)] = gate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "ElectronicCircuit.h"
|
#include "ElectronicCircuit.h"
|
||||||
|
|
||||||
#include Map.h
|
#include <unordered_map>
|
||||||
|
|
||||||
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 };
|
||||||
|
|
||||||
Vector<Ptr<TerminalNode> > mInputTerminalNodes;
|
std::vector<std::unique_ptr<TerminalNode> > mInputTerminalNodes;
|
||||||
Vector<Ptr<TerminalNode> > mOutputTerminalNodes;
|
std::vector<std::unique_ptr<TerminalNode> > mOutputTerminalNodes;
|
||||||
Vector<Ptr<WireNode> > mWireNodes;
|
std::vector<std::unique_ptr<WireNode> > mWireNodes;
|
||||||
Vector<Ptr<LogicGateNode> > mLogicGateNodes;
|
std::vector<std::unique_ptr<LogicGateNode> > mLogicGateNodes;
|
||||||
|
|
||||||
Map<Wire*, CircuitElement*> mWireInputConnections;
|
std::unordered_map<Wire*, CircuitElement*> mWireInputConnections;
|
||||||
Map<Wire*, CircuitElement*> mWireOutputConnections;
|
std::unordered_map<Wire*, CircuitElement*> mWireOutputConnections;
|
||||||
|
|
||||||
Map<CircuitElement*, CircuitElementNode*> mNodesForContent;
|
std::unordered_map<CircuitElement*, CircuitElementNode*> mNodesForContent;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 };
|
||||||
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)
|
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)
|
if (mContent->getOutput(idx) == wire)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,6 @@ private:
|
||||||
LogicGate* mContent{ nullptr };
|
LogicGate* mContent{ nullptr };
|
||||||
bool mContentDirty{ true };
|
bool mContentDirty{ true };
|
||||||
|
|
||||||
Ptr<PathNode> mPrimaryPath;
|
std::unique_ptr<PathNode> mPrimaryPath;
|
||||||
Ptr<CircleNode> mNegationGlyph;
|
std::unique_ptr<CircleNode> mNegationGlyph;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "LogicGatePrimitiveShapes.h"
|
#include "LogicGatePrimitiveShapes.h"
|
||||||
|
|
||||||
String LogicGatePrimitiveShapes::getAndGateShape()
|
std::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, size_t idx)
|
Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, std::size_t idx)
|
||||||
{
|
{
|
||||||
if (isInput)
|
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";
|
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)
|
if (isInput)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
class LogicGatePrimitiveShapes
|
class LogicGatePrimitiveShapes
|
||||||
{
|
{
|
||||||
public:
|
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();
|
||||||
};
|
};
|
|
@ -19,7 +19,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createOrUpdateGeometry(SceneInfo* sceneInfo);
|
void createOrUpdateGeometry(SceneInfo* sceneInfo);
|
||||||
Ptr<CircleNode> mMarker;
|
std::unique_ptr<CircleNode> mMarker;
|
||||||
|
|
||||||
Terminal* mContent{ nullptr };
|
Terminal* mContent{ nullptr };
|
||||||
bool mContentDirty{ true };
|
bool mContentDirty{ true };
|
||||||
|
|
|
@ -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());
|
||||||
|
|
||||||
Vector<Point2> points;
|
std::vector<Point2> points;
|
||||||
|
|
||||||
if (loc.getY() == 0.0)
|
if (loc.getY() == 0.0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,5 +26,5 @@ private:
|
||||||
Point2 mInputLocation;
|
Point2 mInputLocation;
|
||||||
Point2 mOutputLocation;
|
Point2 mOutputLocation;
|
||||||
|
|
||||||
Ptr<LineNode> mLine;
|
std::unique_ptr<LineNode> mLine;
|
||||||
};
|
};
|
|
@ -9,7 +9,7 @@ MetaMidiEvent::MetaMidiEvent()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<MetaMidiEvent> MetaMidiEvent::Create()
|
std::unique_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 String& label)
|
void MetaMidiEvent::SetLabel(const std::string& label)
|
||||||
{
|
{
|
||||||
mLabel = label;
|
mLabel = label;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include "MidiEvent.h"
|
#include "MidiEvent.h"
|
||||||
#include "MidiElements.h"
|
#include "MidiElements.h"
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
class MetaMidiEvent : public MidiEvent
|
class MetaMidiEvent : public MidiEvent
|
||||||
{
|
{
|
||||||
|
@ -51,13 +51,13 @@ private:
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MetaMidiEvent();
|
MetaMidiEvent();
|
||||||
static Ptr<MetaMidiEvent> Create();
|
static std::unique_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 String& label);
|
void SetLabel(const std::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};
|
||||||
String mLabel;
|
std::string mLabel;
|
||||||
int mValue { 0 };
|
int mValue { 0 };
|
||||||
MidiTimeSignature mTimeSig;
|
MidiTimeSignature mTimeSig;
|
||||||
MidiSmtpeTimecode mTimecode;
|
MidiSmtpeTimecode mTimecode;
|
||||||
MidiKeySignature mKeySig;
|
MidiKeySignature mKeySig;
|
||||||
};
|
};
|
||||||
|
|
||||||
using MetaMidiEventPtr = Ptr<MetaMidiEvent>;
|
using MetaMidiEventPtr = std::unique_ptr<MetaMidiEvent>;
|
||||||
|
|
|
@ -9,7 +9,7 @@ MidiChannelEvent::MidiChannelEvent()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<MidiChannelEvent> MidiChannelEvent::Create()
|
std::unique_ptr<MidiChannelEvent> MidiChannelEvent::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<MidiChannelEvent>();
|
return std::make_unique<MidiChannelEvent>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "MidiEvent.h"
|
#include "MidiEvent.h"
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
class MidiChannelEvent : public MidiEvent
|
class MidiChannelEvent : public MidiEvent
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MidiChannelEvent();
|
MidiChannelEvent();
|
||||||
static Ptr<MidiChannelEvent> Create();
|
static std::unique_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 = Ptr<MidiChannelEvent>;
|
using MidiChannelEventPtr = std::unique_ptr<MidiChannelEvent>;
|
||||||
|
|
|
@ -7,7 +7,7 @@ MidiDocument::MidiDocument()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<MidiDocument> MidiDocument::Create()
|
std::unique_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 += "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";
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
#include "MidiElements.h"
|
#include "MidiElements.h"
|
||||||
|
|
||||||
class MidiTrack;
|
class MidiTrack;
|
||||||
using MidiTrackPtr = Ptr<MidiTrack>;
|
using MidiTrackPtr = std::unique_ptr<MidiTrack>;
|
||||||
|
|
||||||
class MidiDocument
|
class MidiDocument
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MidiDocument();
|
MidiDocument();
|
||||||
|
|
||||||
static Ptr<MidiDocument> Create();
|
static std::unique_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);
|
||||||
|
|
||||||
String Serialize() const;
|
std::string Serialize() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mFormatType = 0;
|
int mFormatType = 0;
|
||||||
int mExpectedTracks = 0;
|
int mExpectedTracks = 0;
|
||||||
MidiTimeDivision mTimeDivision;
|
MidiTimeDivision mTimeDivision;
|
||||||
Vector<MidiTrackPtr> mTracks;
|
std::vector<MidiTrackPtr> mTracks;
|
||||||
};
|
};
|
||||||
|
|
||||||
using MidiDocumentPtr = Ptr<MidiDocument>;
|
using MidiDocumentPtr = std::unique_ptr<MidiDocument>;
|
||||||
|
|
|
@ -6,7 +6,7 @@ MidiEvent::MidiEvent()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<MidiEvent> MidiEvent::Create()
|
std::unique_ptr<MidiEvent> MidiEvent::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<MidiEvent>();
|
return std::make_unique<MidiEvent>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
|
|
||||||
class MidiEvent
|
class MidiEvent
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ public:
|
||||||
MidiEvent();
|
MidiEvent();
|
||||||
virtual ~MidiEvent() = default;
|
virtual ~MidiEvent() = default;
|
||||||
|
|
||||||
static Ptr<MidiEvent> Create();
|
static std::unique_ptr<MidiEvent> Create();
|
||||||
|
|
||||||
void SetTimeDelta(int delta);
|
void SetTimeDelta(int delta);
|
||||||
|
|
||||||
|
@ -26,4 +26,4 @@ private:
|
||||||
int mTimeDelta{0};
|
int mTimeDelta{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
using MidiEventPtr = Ptr<MidiEvent>;
|
using MidiEventPtr = std::unique_ptr<MidiEvent>;
|
||||||
|
|
|
@ -17,19 +17,19 @@ void MidiTrack::AddEvent(MidiEventPtr event)
|
||||||
mEvents.push_back(std::move(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();
|
return mEvents[idx].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MidiTrack::GetNumEvents()
|
std::size_t MidiTrack::GetNumEvents()
|
||||||
{
|
{
|
||||||
return mEvents.size();
|
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";
|
output += "Num Events: " + std::to_string(mEvents.size()) + "\n";
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
#include "String.h"
|
#include <string>
|
||||||
#include "MidiEvent.h"
|
#include "MidiEvent.h"
|
||||||
|
|
||||||
class MidiEvent;
|
class MidiEvent;
|
||||||
using MidiEventPtr = Ptr<MidiEvent>;
|
using MidiEventPtr = std::unique_ptr<MidiEvent>;
|
||||||
|
|
||||||
class MidiTrack
|
class MidiTrack
|
||||||
{
|
{
|
||||||
|
@ -18,13 +18,13 @@ public:
|
||||||
|
|
||||||
void AddEvent(MidiEventPtr event);
|
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:
|
private:
|
||||||
|
|
||||||
Vector<MidiEventPtr> mEvents;
|
std::vector<MidiEventPtr> mEvents;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "MidiChannelEventAdapter.h"
|
#include "MidiChannelEventAdapter.h"
|
||||||
|
|
||||||
#include "BinaryStream.h"
|
#include "BinaryStream.h"
|
||||||
#include "Bits.h"
|
#include "ByteUtils.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 = Bits::MostSignificantBitIsOne(firstByte);
|
const bool isStatusByte = ByteUtils::MostSignificantBitIsOne(firstByte);
|
||||||
if(isStatusByte)
|
if(isStatusByte)
|
||||||
{
|
{
|
||||||
event->SetTypeAndChannel(firstByte);
|
event->SetTypeAndChannel(firstByte);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "MidiMetaEventAdapter.h"
|
#include "MidiMetaEventAdapter.h"
|
||||||
|
|
||||||
#include "BinaryStream.h"
|
#include "BinaryStream.h"
|
||||||
#include "Bits.h"
|
#include "ByteUtils.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++;
|
||||||
|
|
||||||
String name;
|
std::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 ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
String buffer;
|
std::string buffer;
|
||||||
BinaryStream::getNextNBytes(file, buffer.data(), length);
|
BinaryStream::getNextNBytes(file, buffer.data(), length);
|
||||||
byteCount += 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);
|
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 ++;
|
||||||
|
|
||||||
String buffer;
|
std::string buffer;
|
||||||
BinaryStream::getNextNBytes(file, buffer.data(), length);
|
BinaryStream::getNextNBytes(file, buffer.data(), length);
|
||||||
byteCount += 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);
|
event->SetValue(value);
|
||||||
lastMidiChannel = value;
|
lastMidiChannel = value;
|
||||||
return byteCount;
|
return byteCount;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "MidiReader.h"
|
#include "MidiReader.h"
|
||||||
|
|
||||||
#include "MidiDocument.h"
|
#include "MidiDocument.h"
|
||||||
#include "Bits.h"
|
#include "ByteUtils.h"
|
||||||
#include "MidiTrack.h"
|
#include "MidiTrack.h"
|
||||||
#include "BinaryStream.h"
|
#include "BinaryStream.h"
|
||||||
#include "FileLogger.h"
|
#include "FileLogger.h"
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
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:
|
||||||
Ptr<File> mFile;
|
std::unique_ptr<File> mFile;
|
||||||
MidiDocumentPtr mDocument;
|
MidiDocumentPtr mDocument;
|
||||||
int mLastMidiChannel {0};
|
int mLastMidiChannel {0};
|
||||||
MidiChannelEvent::Type mLastChannelEventType;
|
MidiChannelEvent::Type mLastChannelEventType;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "MidiTimeAdapter.h"
|
#include "MidiTimeAdapter.h"
|
||||||
|
|
||||||
#include "BinaryStream.h"
|
#include "BinaryStream.h"
|
||||||
#include "Bits.h"
|
#include "ByteUtils.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(!Bits::MostSignificantBitIsOne(c))
|
if(!ByteUtils::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 = Bits::GetWordFirstBit(*time_division);
|
division.mUseFps = ByteUtils::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 = Bits::GetWordLastByte(*time_division);
|
division.mTicks = ByteUtils::GetWordLastByte(*time_division);
|
||||||
return 2; // Bytes advanced
|
return 2; // Bytes advanced
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,22 +28,22 @@ void QuantumCircuit::addLogicGate(QuantumGatePtr gate)
|
||||||
mElements.push_back(std::move(gate));
|
mElements.push_back(std::move(gate));
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<QuantumTerminal*>& QuantumCircuit::getInputTerminals() const
|
const std::vector<QuantumTerminal*>& QuantumCircuit::getInputTerminals() const
|
||||||
{
|
{
|
||||||
return mInputTerminals;
|
return mInputTerminals;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<QuantumTerminal*>& QuantumCircuit::getOutputTerminals() const
|
const std::vector<QuantumTerminal*>& QuantumCircuit::getOutputTerminals() const
|
||||||
{
|
{
|
||||||
return mOutputTerminals;
|
return mOutputTerminals;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<QuantumGate*>& QuantumCircuit::getLogicGates() const
|
const std::vector<QuantumGate*>& QuantumCircuit::getLogicGates() const
|
||||||
{
|
{
|
||||||
return mGates;
|
return mGates;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<QuantumWire*>& QuantumCircuit::getQuantumWires() const
|
const std::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 (size_t idx = 0; idx < gate->getNumInputs(); idx++)
|
for (std::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 (size_t idx = 0; idx < gate->getNumOutputs(); idx++)
|
for (std::size_t idx = 0; idx < gate->getNumOutputs(); idx++)
|
||||||
{
|
{
|
||||||
if (gate->getOutput(idx) == nullptr)
|
if (gate->getOutput(idx) == nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "QuantumWire.h"
|
#include "QuantumWire.h"
|
||||||
#include "QuantumState.h"
|
#include "QuantumState.h"
|
||||||
|
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
|
|
||||||
class QuantumCircuit
|
class QuantumCircuit
|
||||||
{
|
{
|
||||||
|
@ -21,24 +21,24 @@ public:
|
||||||
|
|
||||||
void buildWireConnections();
|
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;
|
QuantumState getInputState() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool connectivityIsValid() const;
|
bool connectivityIsValid() const;
|
||||||
|
|
||||||
Vector<QuantumTerminal*> mInputTerminals;
|
std::vector<QuantumTerminal*> mInputTerminals;
|
||||||
Vector<QuantumTerminal*> mOutputTerminals;
|
std::vector<QuantumTerminal*> mOutputTerminals;
|
||||||
|
|
||||||
Vector<QuantumWire*> mWires;
|
std::vector<QuantumWire*> mWires;
|
||||||
Vector<QuantumGate*> mGates;
|
std::vector<QuantumGate*> mGates;
|
||||||
|
|
||||||
Vector<Ptr<QuantumCircuitElement> > mElements;
|
std::vector<std::unique_ptr<QuantumCircuitElement> > mElements;
|
||||||
};
|
};
|
|
@ -10,18 +10,18 @@
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "FileLogger.h"
|
#include "FileLogger.h"
|
||||||
|
|
||||||
Ptr<QuantumCircuit> QuantumCircuitReader::read(const Path& path)
|
std::unique_ptr<QuantumCircuit> QuantumCircuitReader::read(const Path& path)
|
||||||
{
|
{
|
||||||
File file(path);
|
File file(path);
|
||||||
return read(file.readText());
|
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>();
|
auto circuit = std::make_unique<QuantumCircuit>();
|
||||||
mWorkingCircuit = circuit.get();
|
mWorkingCircuit = circuit.get();
|
||||||
|
|
||||||
size_t cursor = 0;
|
std::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 @@ Ptr<QuantumCircuit> QuantumCircuitReader::read(const String& content)
|
||||||
return circuit;
|
return circuit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuantumCircuitReader::onLine(const String& line, size_t jdx)
|
void QuantumCircuitReader::onLine(const std::string& line, std::size_t jdx)
|
||||||
{
|
{
|
||||||
mWorkingString.clear();
|
mWorkingString.clear();
|
||||||
size_t cursor = 0;
|
std::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: " << String(1, c));
|
MLOG_INFO("Working char: " << std::string(1, c));
|
||||||
|
|
||||||
if (c == '|')
|
if (c == '|')
|
||||||
{
|
{
|
||||||
|
@ -103,7 +103,7 @@ void QuantumCircuitReader::onLineEnd()
|
||||||
mWorkingElement = nullptr;
|
mWorkingElement = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuantumCircuitReader::onGate(Location, const String value)
|
void QuantumCircuitReader::onGate(Location, const std::string value)
|
||||||
{
|
{
|
||||||
MLOG_INFO("Got gate: " << 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)
|
for (const auto c : segment)
|
||||||
{
|
{
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
|
@ -142,7 +142,7 @@ String QuantumCircuitReader::checkForGate(const String& segment)
|
||||||
return working_string;
|
return working_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuantumCircuitReader::onKet(Location, const String value)
|
void QuantumCircuitReader::onKet(Location, const std::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 String value)
|
||||||
mWorkingCircuit->addInputTerminal(std::move(input_terminal));
|
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)
|
for (const auto c : segment)
|
||||||
{
|
{
|
||||||
if (c != '-')
|
if (c != '-')
|
||||||
|
@ -171,9 +171,9 @@ size_t QuantumCircuitReader::getWireEnd(const String& segment)
|
||||||
return idx;
|
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 };
|
bool found{ false };
|
||||||
|
|
||||||
for (const auto c : segment)
|
for (const auto c : segment)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
using Path = std::filesystem::path;
|
using Path = std::filesystem::path;
|
||||||
|
|
||||||
|
@ -11,30 +11,30 @@ class QuantumCircuitElement;
|
||||||
class QuantumCircuitReader
|
class QuantumCircuitReader
|
||||||
{
|
{
|
||||||
public:
|
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:
|
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 onLineEnd();
|
||||||
|
|
||||||
void onVertialQuantumWire(Location loc);
|
void onVertialQuantumWire(Location loc);
|
||||||
|
|
||||||
String mWorkingString;
|
std::string mWorkingString;
|
||||||
QuantumCircuitElement* mWorkingElement{ nullptr };
|
QuantumCircuitElement* mWorkingElement{ nullptr };
|
||||||
QuantumCircuit* mWorkingCircuit{ nullptr };
|
QuantumCircuit* mWorkingCircuit{ nullptr };
|
||||||
};
|
};
|
|
@ -1,13 +1,13 @@
|
||||||
#include "QuantumState.h"
|
#include "QuantumState.h"
|
||||||
|
|
||||||
const Vector<Qubit>& QuantumState::getData() const
|
const std::vector<Qubit>& QuantumState::getData() const
|
||||||
{
|
{
|
||||||
return mState;
|
return mState;
|
||||||
}
|
}
|
||||||
|
|
||||||
String QuantumState::toString() const
|
std::string QuantumState::toString() const
|
||||||
{
|
{
|
||||||
String out;
|
std::string out;
|
||||||
for (const auto& qubit : mState)
|
for (const auto& qubit : mState)
|
||||||
{
|
{
|
||||||
out += "|" + qubit.toString() + "\n";
|
out += "|" + qubit.toString() + "\n";
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include "Qubit.h"
|
#include "Qubit.h"
|
||||||
|
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
class QuantumState
|
class QuantumState
|
||||||
{
|
{
|
||||||
|
@ -13,10 +13,10 @@ public:
|
||||||
mState.push_back(data);
|
mState.push_back(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<Qubit>& getData() const;
|
const std::vector<Qubit>& getData() const;
|
||||||
|
|
||||||
String toString() const;
|
std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Qubit> mState;
|
std::vector<Qubit> mState;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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.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();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "ComplexNumber.h"
|
#include "ComplexNumber.h"
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
|
|
||||||
class Qubit
|
class Qubit
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ public:
|
||||||
|
|
||||||
bool isIn1State() const;
|
bool isIn1State() const;
|
||||||
|
|
||||||
String toString(size_t precision=3) const;
|
std::string toString(std::size_t precision=3) const;
|
||||||
private:
|
private:
|
||||||
ComplexNumber mAlpha;
|
ComplexNumber mAlpha;
|
||||||
ComplexNumber mBeta;
|
ComplexNumber mBeta;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
|
|
||||||
class QuantumCircuitElement
|
class QuantumCircuitElement
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "QuantumGate.h"
|
#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(),
|
: QuantumGate(),
|
||||||
mNumIn(numIn),
|
mNumIn(numIn),
|
||||||
mNumOut(numOut)
|
mNumOut(numOut)
|
||||||
|
@ -11,7 +11,7 @@ NInMOutQuantumGate::NInMOutQuantumGate(size_t numIn, size_t numOut, Vector<Abstr
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mInputs = Vector<AbstractQuantumWire*>(numIn, nullptr);
|
mInputs = std::vector<AbstractQuantumWire*>(numIn, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputs.size() == mNumOut)
|
if (outputs.size() == mNumOut)
|
||||||
|
@ -20,21 +20,21 @@ NInMOutQuantumGate::NInMOutQuantumGate(size_t numIn, size_t numOut, Vector<Abstr
|
||||||
}
|
}
|
||||||
else
|
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;
|
return mNumIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t NInMOutQuantumGate::getNumOutputs() const
|
std::size_t NInMOutQuantumGate::getNumOutputs() const
|
||||||
{
|
{
|
||||||
return mNumOut;
|
return mNumOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractQuantumWire* NInMOutQuantumGate::getInput(size_t idx) const
|
AbstractQuantumWire* NInMOutQuantumGate::getInput(std::size_t idx) const
|
||||||
{
|
{
|
||||||
if (idx < mNumIn)
|
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)
|
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())
|
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())
|
if (idx < mOutputs.size())
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "QuantumWire.h"
|
#include "QuantumWire.h"
|
||||||
|
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
|
|
||||||
class QuantumGate : public QuantumCircuitElement
|
class QuantumGate : public QuantumCircuitElement
|
||||||
{
|
{
|
||||||
|
@ -20,17 +20,17 @@ public:
|
||||||
};
|
};
|
||||||
virtual ~QuantumGate() = default;
|
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;
|
virtual GateType getGateType() const = 0;
|
||||||
|
|
||||||
|
@ -39,27 +39,27 @@ public:
|
||||||
return Type::GATE;
|
return Type::GATE;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
using QuantumGatePtr = Ptr<QuantumGate>;
|
using QuantumGatePtr = std::unique_ptr<QuantumGate>;
|
||||||
|
|
||||||
|
|
||||||
class NInMOutQuantumGate : public QuantumGate
|
class NInMOutQuantumGate : public QuantumGate
|
||||||
{
|
{
|
||||||
public:
|
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;
|
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
|
bool isFullyConnected() const override
|
||||||
{
|
{
|
||||||
|
@ -82,11 +82,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t mNumIn{ 1 };
|
std::size_t mNumIn{ 1 };
|
||||||
size_t mNumOut{ 1 };
|
std::size_t mNumOut{ 1 };
|
||||||
|
|
||||||
Vector<AbstractQuantumWire*> mInputs;
|
std::vector<AbstractQuantumWire*> mInputs;
|
||||||
Vector<AbstractQuantumWire*> mOutputs;
|
std::vector<AbstractQuantumWire*> mOutputs;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TwoInOneOutQuantumGate : public NInMOutQuantumGate
|
class TwoInOneOutQuantumGate : public NInMOutQuantumGate
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "QuantumTerminal.h"
|
#include "QuantumTerminal.h"
|
||||||
|
|
||||||
QuantumTerminal::QuantumTerminal(TerminalType type, const String& label)
|
QuantumTerminal::QuantumTerminal(TerminalType type, const std::string& label)
|
||||||
: mLabel(label),
|
: mLabel(label),
|
||||||
mType(type)
|
mType(type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
#include "QuantumCircuitElement.h"
|
#include "QuantumCircuitElement.h"
|
||||||
#include "Qubit.h"
|
#include "Qubit.h"
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
|
|
||||||
class QuantumWire;
|
class QuantumWire;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public:
|
||||||
OUTPUT
|
OUTPUT
|
||||||
};
|
};
|
||||||
|
|
||||||
QuantumTerminal(TerminalType type, const String& label = {});
|
QuantumTerminal(TerminalType type, const std::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:
|
||||||
String mLabel;
|
std::string mLabel;
|
||||||
TerminalType mType;
|
TerminalType mType;
|
||||||
Qubit mValue;
|
Qubit mValue;
|
||||||
QuantumWire* mConnection{ nullptr };
|
QuantumWire* mConnection{ nullptr };
|
||||||
};
|
};
|
||||||
using QuantumTerminalPtr = Ptr<QuantumTerminal>;
|
using QuantumTerminalPtr = std::unique_ptr<QuantumTerminal>;
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
Type getType() const override;
|
Type getType() const override;
|
||||||
WireType getWireType() const override;
|
WireType getWireType() const override;
|
||||||
};
|
};
|
||||||
using QuantumWirePtr = Ptr<QuantumWire>;
|
using QuantumWirePtr = std::unique_ptr<QuantumWire>;
|
||||||
|
|
||||||
class ClassicalWire : public AbstractQuantumWire
|
class ClassicalWire : public AbstractQuantumWire
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 Vector<Point2> points{end_point_x };
|
const std::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);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "AbstractVisualNode.h"
|
#include "AbstractVisualNode.h"
|
||||||
|
|
||||||
#include "Pointer.h"
|
#include <memory>
|
||||||
|
|
||||||
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 };
|
||||||
|
|
||||||
Ptr<CircleNode> mOuterCircle;
|
std::unique_ptr<CircleNode> mOuterCircle;
|
||||||
Ptr<CircleNode> mInnerCircle;
|
std::unique_ptr<CircleNode> mInnerCircle;
|
||||||
Ptr<CircleNode> mCentreCircle;
|
std::unique_ptr<CircleNode> mCentreCircle;
|
||||||
Ptr<CircleNode> mStateMarkerCircle;
|
std::unique_ptr<CircleNode> mStateMarkerCircle;
|
||||||
Ptr<LineNode> mXAxis;
|
std::unique_ptr<LineNode> mXAxis;
|
||||||
Ptr<LineNode> mYAxis;
|
std::unique_ptr<LineNode> mYAxis;
|
||||||
Ptr<LineNode> mZAxis;
|
std::unique_ptr<LineNode> mZAxis;
|
||||||
Ptr<LineNode> mStateVector;
|
std::unique_ptr<LineNode> mStateVector;
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,12 +45,12 @@ void QuantumCircuitNode::buildWireConnections()
|
||||||
|
|
||||||
for (auto gate : mContent->getLogicGates())
|
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;
|
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;
|
mWireOutputConnections[gate->getOutput(idx)] = gate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "AbstractVisualNode.h"
|
#include "AbstractVisualNode.h"
|
||||||
|
|
||||||
#include Map.h
|
#include <unordered_map>
|
||||||
|
|
||||||
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 };
|
||||||
|
|
||||||
Vector<Ptr<QuantumTerminalNode> > mInputTerminalNodes;
|
std::vector<std::unique_ptr<QuantumTerminalNode> > mInputTerminalNodes;
|
||||||
Vector<Ptr<QuantumTerminalNode> > mOutputTerminalNodes;
|
std::vector<std::unique_ptr<QuantumTerminalNode> > mOutputTerminalNodes;
|
||||||
Vector<Ptr<QuantumGateNode> > mGateNodes;
|
std::vector<std::unique_ptr<QuantumGateNode> > mGateNodes;
|
||||||
Vector<Ptr<QuantumWireNode> > mWireNodes;
|
std::vector<std::unique_ptr<QuantumWireNode> > mWireNodes;
|
||||||
|
|
||||||
Map<AbstractQuantumWire*, QuantumCircuitElement*> mWireInputConnections;
|
std::unordered_map<AbstractQuantumWire*, QuantumCircuitElement*> mWireInputConnections;
|
||||||
Map<AbstractQuantumWire*, QuantumCircuitElement*> mWireOutputConnections;
|
std::unordered_map<AbstractQuantumWire*, QuantumCircuitElement*> mWireOutputConnections;
|
||||||
|
|
||||||
Map<QuantumCircuitElement*, QuantumCircuitElementNode*> mNodesForContent;
|
std::unordered_map<QuantumCircuitElement*, QuantumCircuitElementNode*> mNodesForContent;
|
||||||
};
|
};
|
|
@ -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));
|
||||||
|
|
||||||
String label_content;
|
std::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 };
|
||||||
//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)
|
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)
|
if (mContent->getOutput(idx) == wire)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,10 +25,10 @@ private:
|
||||||
QuantumGate* mContent{ nullptr };
|
QuantumGate* mContent{ nullptr };
|
||||||
bool mContentDirty{ true };
|
bool mContentDirty{ true };
|
||||||
|
|
||||||
Ptr<RectangleNode> mBody;
|
std::unique_ptr<RectangleNode> mBody;
|
||||||
|
|
||||||
double mBodyWidth = 30;
|
double mBodyWidth = 30;
|
||||||
double mBodyHeight = 24;
|
double mBodyHeight = 24;
|
||||||
Ptr<LatexMathExpression> mLabelExpression;
|
std::unique_ptr<LatexMathExpression> mLabelExpression;
|
||||||
Ptr<EquationNode> mLabel;
|
std::unique_ptr<EquationNode> mLabel;
|
||||||
};
|
};
|
|
@ -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();
|
||||||
String label;
|
std::string label;
|
||||||
if (value.isIn0State())
|
if (value.isIn0State())
|
||||||
{
|
{
|
||||||
label = "\\ket{0}";
|
label = "\\ket{0}";
|
||||||
|
|
|
@ -25,6 +25,6 @@ private:
|
||||||
double mWidth = 20.0;
|
double mWidth = 20.0;
|
||||||
double mHeight = 10.0;
|
double mHeight = 10.0;
|
||||||
|
|
||||||
Ptr<LatexMathExpression> mLabelExpression;
|
std::unique_ptr<LatexMathExpression> mLabelExpression;
|
||||||
Ptr<EquationNode> mLabel;
|
std::unique_ptr<EquationNode> mLabel;
|
||||||
};
|
};
|
|
@ -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());
|
||||||
|
|
||||||
Vector<Point2> points;
|
std::vector<Point2> points;
|
||||||
|
|
||||||
if (loc.getY() == 0.0)
|
if (loc.getY() == 0.0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,5 +29,5 @@ private:
|
||||||
Point2 mInputLocation;
|
Point2 mInputLocation;
|
||||||
Point2 mOutputLocation;
|
Point2 mOutputLocation;
|
||||||
|
|
||||||
Ptr<LineNode> mLine;
|
std::unique_ptr<LineNode> mLine;
|
||||||
};
|
};
|
7
src/CMakeLists.txt
Normal file
7
src/CMakeLists.txt
Normal 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
6
src/base/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
add_subdirectory(compiler)
|
||||||
|
add_subdirectory(compression)
|
||||||
|
add_subdirectory(core)
|
||||||
|
add_subdirectory(database)
|
||||||
|
add_subdirectory(geometry)
|
||||||
|
add_subdirectory(network)
|
28
src/base/compiler/CMakeLists.txt
Normal file
28
src/base/compiler/CMakeLists.txt
Normal 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)
|
|
@ -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();
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
};
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "Lexer.h"
|
#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())
|
if (checkString.empty())
|
||||||
{
|
{
|
||||||
|
@ -16,8 +16,8 @@ bool Lexer::matchPattern(const String& pattern, const String& checkString, char
|
||||||
unsigned check_idx = 0;
|
unsigned check_idx = 0;
|
||||||
unsigned pattern_idx = 0;
|
unsigned pattern_idx = 0;
|
||||||
|
|
||||||
Vector<String> hits;
|
std::vector<std::string> hits;
|
||||||
String working_hit;
|
std::string working_hit;
|
||||||
while(check_idx < checkString.size())
|
while(check_idx < checkString.size())
|
||||||
{
|
{
|
||||||
if (pattern_idx == pattern.size())
|
if (pattern_idx == pattern.size())
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "String.h"
|
#include <string>
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
|
|
||||||
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 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
Loading…
Reference in a new issue