/***************************************************************************
 *   Copyright (C) 2004 by Armando Navarro                                 *
 *   qoajnv@usc.es                                                         *
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef QUANTUMPARSER_H
#define QUANTUMPARSER_H

#include <fstream>
#include <istream>
#include <vector>

#include "kryoparsers_export.h"
/**
@author Armando Navarro
*/

namespace Quantum
{
  const double angstromtobohr=1.889725989;
  enum level { MNDO, HF, SCRF, MP2, QCISD, CCSD, CCSDT };
  enum jobtype {opt, freq, dens, uv, nmr, dyn };
  struct  jobheader { jobheader (jobtype t, std::streampos p) : type(t) , pos(p) {};
                                  jobtype type;
                                  std::streampos pos; };
}

class CMolecule;
class KRYOPARSERS_EXPORT QuantumParser
{
public:
  QuantumParser(const char* inputfile) : m_bcreated(true) { m_file= new std::ifstream(inputfile,std::ios::binary); }
  QuantumParser(std::istream* stream) : m_file(stream) , m_bcreated(false) {};

  virtual ~QuantumParser() { if (m_bcreated) delete m_file; }
  void SetMolecule(std::vector<CMolecule>* molecule) { m_molecule=molecule; }
  virtual bool ParseFile(std::streampos pos=0 )=0;
  virtual std::vector<Quantum::jobheader>& GetJobs(); 
  virtual bool ParseFrequencies( std::streampos =0) { return false; }
  
protected:
  std::istream* m_file;
  std::vector<CMolecule>* m_molecule;
  Quantum::level m_level;
  int  m_natoms;
  std::vector<Quantum::jobheader> m_jobpos;
private:
 bool m_bcreated;
 public:
class Exception : public std::exception
{
  public:
  Exception(const std::string& e) throw() : _error(e) {};
  virtual ~Exception() throw() {};
  const char* what() const throw() { return _error.c_str(); }
  private:
  std::string _error;

};

};

#endif
