Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

formula.h

00001 // -*- C++ -*-
00002 
00003 /* 
00004  * Gnome Chemistry Utils
00005  * formula.h 
00006  *
00007  * Copyright (C) 2005
00008  *
00009  * Developed by Jean Bréfort <jean.brefort@normalesup.org>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2.1 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this library; if not, write to the 
00023  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00024  * Boston, MA  02111-1307, USA.
00025  */
00026 
00027 #ifndef GCU_FORMULA_H
00028 #define GCU_FORMULA_H
00029 
00030 #include <string>
00031 #include <map>
00032 #include <list>
00033 #include <stdexcept>
00034 
00035 using namespace std;
00036 
00037 namespace gcu
00038 {
00039 
00040 class parse_error: public exception
00041 {
00042         string m_msg;
00043         int m_start, m_length;
00044 
00045 public:
00048     explicit 
00049     parse_error (const string&  __arg, int start, int length);
00050 
00051     virtual 
00052     ~parse_error () throw ();
00053 
00056     virtual const char* 
00057     what () const throw ();
00060     const char* 
00061     what (int& start, int& length) const throw ();
00062 
00063         void add_offset (int offset) {m_start += offset;}
00064 
00065 };
00066 
00067 class FormulaElt;
00068 
00069 class Formula
00070 {
00071 public:
00072         Formula (string entry) throw (parse_error);
00073         virtual ~Formula ();
00074 
00075         char const *GetMarkup ();
00076         map<int,int> &GetRawFormula ();
00077         char const *GetRawMarkup ();
00078         void SetFormula (string entry) throw (parse_error);
00079         void Clear ();
00080         double GetMolecularWeight (int &prec, bool &artificial);
00081 
00082 private:
00083         void Parse (string &formula, list<FormulaElt *>&result) throw (parse_error);
00084 
00085 private:
00086         string Entry, Markup, RawMarkup;
00087         map<int,int> Raw;
00088         list<FormulaElt *> Details;
00089         double m_Weight;
00090         int m_WeightPrec;
00091         bool m_WeightCached;
00092         bool m_Artificial;
00093 };
00094         
00095 }
00096 
00097 #endif // GCU_FORMULA_H

Generated on Mon Jun 27 16:44:12 2005 for The Gnome Chemistry Utils by  doxygen 1.4.1