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

40 lines
800 B
C
Raw Normal View History

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