formula.h

00001 // -*- C++ -*-
00002 
00003 /* 
00004  * Gnome Chemistry Utils
00005  * formula.h 
00006  *
00007  * Copyright (C) 2005-2008 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (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 Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
00023  */
00024 
00025 #ifndef GCU_FORMULA_H
00026 #define GCU_FORMULA_H
00027 
00028 #include <string>
00029 #include <map>
00030 #include <list>
00031 #include <stdexcept>
00032 #include "isotope.h"
00033 #include "value.h"
00034 
00035 namespace gcu
00036 {
00037 
00038 typedef enum {
00039         GCU_FORMULA_PARSE_GUESS,
00040         GCU_FORMULA_PARSE_ATOM,
00041         GCU_FORMULA_PARSE_RESIDUE,
00042         GCU_FORMULA_PARSE_ASK,
00043 } FormulaParseMode;
00044 
00050 class parse_error: public std::exception
00051 {
00052 public:
00056     explicit 
00057     parse_error (const std::string&  __arg, int start, int length);
00058 
00059     virtual 
00060     ~parse_error () throw ();
00061 
00065     virtual const char* 
00066     what () const throw ();
00070     const char* 
00071     what (int& start, int& length) const throw ();
00072 
00076         void add_offset (int offset) {m_start += offset;}
00077 
00078 private:
00079         std::string m_msg;
00080         int m_start, m_length;
00081 
00082 };
00083 
00084 class FormulaElt;
00085 
00091 class Formula
00092 {
00093 public:
00099         Formula (std::string entry) throw (parse_error);
00100         virtual ~Formula ();
00101 
00105         char const *GetMarkup ();
00109         std::map<int,int> &GetRawFormula ();
00113         char const *GetRawMarkup ();
00120         void SetFormula (std::string entry) throw (parse_error);
00124         void Clear ();
00130         DimensionalValue GetMolecularWeight (bool &artificial);
00136         void CalculateIsotopicPattern (IsotopicPattern &pattern);
00137 
00138         bool BuildConnectivity ();
00139 
00140 private:
00141         void Parse (std::string &formula, std::list<FormulaElt *>&result) throw (parse_error);
00142 
00143 private:
00144         std::string Entry, Markup, RawMarkup;
00145         std::map<int,int> Raw;
00146         std::list<FormulaElt *> Details;
00147         DimensionalValue m_Weight;
00148         bool m_WeightCached;
00149         bool m_Artificial;
00150         bool m_ConnectivityCached;
00151 };
00152         
00153 }
00154 
00155 #endif // GCU_FORMULA_H

Generated on Tue Mar 18 16:06:03 2008 for The Gnome Chemistry Utils by  doxygen 1.5.5