00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _QGPROG_H_
00026 #define _QGPROG_H_
00027
00028 #include "qgerror.h"
00029 #include "qgtypes.h"
00030 #include "qggates.h"
00031
00032
00033 #include <string>
00034 #include <vector>
00035 #include <iostream>
00036 #include <sstream>
00037
00038
00039
00040
00041 namespace qgame {
00042
00047 enum { INVALID, COMMENT, NOOP, QNOT, CNOT, SRN, NAND, HADAMARD, U_THETA, CPHASE_OLD, CPHASE,
00048 U2, SWAP, ORACLE, LIMITED_ORACLE, MATRIX_GATE, MEASURE, END, HALT, PRINTAMPS, USER };
00049
00054 struct QProgramSettings {
00055 int numQb;
00056 std::vector<qgame::TestCase> cases;
00057 qgame::QubitList finalQb;
00058 double threshold;
00059 QProgramSettings() { numQb = -1; threshold = -1; }
00060 };
00061
00064 struct QInstr {
00065 int type;
00066 QubitList qubits;
00067 QGate *gate;
00068 int extra;
00069 bool flag;
00071 QInstr() { type = INVALID; gate = NULL; }
00072 ~QInstr() { delete gate; }
00073 };
00074 std::ostream & operator<<(std::ostream &, const QInstr &);
00075
00080 class QProgram {
00081 std::vector<QInstr*> instr;
00082 int instrPnt;
00083
00084 QInstr *parseLine(const std::string &line) throw(Error);
00085 void parseSetting(QProgramSettings &set, const std::string &line) throw(Error);
00086 QubitList getQubits(int num, std::istringstream &) throw(Error);
00087
00088 friend std::ostream & operator<<(std::ostream &, const QProgram &);
00089 public:
00090 QProgram();
00091 ~QProgram();
00092
00093 unsigned int length() const;
00095 QProgramSettings read(std::istream &stream) throw(Error);
00097 bool addInstruction(const std::string &line) throw(Error);
00098 bool addInstruction(QInstr*) throw(Error);
00100 void installOracle(const std::string &oracleTT);
00102 QInstr * operator[](unsigned int) throw(Error);
00103 };
00104 std::ostream & operator<<(std::ostream &, const QProgram &);
00105
00107 };
00108
00109 #endif