qgprog.h

00001 /***************************************************************************
00002  *   QGame++                                                               *
00003  *   =======                                                               *
00004  *   A Quantum Gate And Measurement Emulator.                              *
00005  *                                                                         *
00006  *   Copyright (C) 2003/04 by Manuel Nickschas                             *
00007  *   <qgame-devel@nickschas.de>                                            *
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  *   This program is distributed in the hope that it will be useful,       *
00015  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017  *   GNU General Public License for more details.                          *
00018  *                                                                         *
00019  *   You should have received a copy of the GNU General Public License     *
00020  *   along with this program; if not, write to the                         *
00021  *   Free Software Foundation, Inc.,                                       *
00022  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00023  ***************************************************************************/
00024 
00025 #ifndef _QGPROG_H_
00026 #define _QGPROG_H_
00027 
00028 #include "qgerror.h"
00029 #include "qgtypes.h"
00030 #include "qggates.h"
00031 //#include "qgame++.h"
00032 
00033 #include <string>
00034 #include <vector>
00035 #include <iostream>
00036 #include <sstream>
00037 
00038 /******************************************************************************
00039  * This file contains data related to quantum programs.
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

Generated on Sat Apr 3 18:42:28 2004 for QGame++ by doxygen 1.3.5