stuff-from-scratch/plugins/quantum_computing/src/QuantumCircuitReader.h

40 lines
892 B
C
Raw Normal View History

2023-01-26 11:27:35 +00:00
#pragma once
#include <filesystem>
#include <string>
using Path = std::filesystem::path;
class QuantumCircuit;
class QuantumCircuitElement;
class QuantumCircuitReader
{
public:
std::unique_ptr<QuantumCircuit> read(const Path& path);
std::unique_ptr<QuantumCircuit> read(const std::string& content);
private:
using Location = std::pair<std::size_t, std::size_t>;
void onLine(const std::string& line, std::size_t jdx);
std::string checkForKet(const std::string& segment);
std::string checkForGate(const std::string& segment);
std::size_t getWireEnd(const std::string& segment);
void onGate(Location loc, const std::string value);
void onKet(Location loc, const std::string value);
void onLineEnd();
void onVertialQuantumWire(Location loc);
std::string mWorkingString;
QuantumCircuitElement* mWorkingElement{ nullptr };
QuantumCircuit* mWorkingCircuit{ nullptr };
};