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 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