• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kalzium/libscience

  • sources
  • kde-4.12
  • kdeedu
  • kalzium
  • libscience
moleculeparser.h
Go to the documentation of this file.
1 /***************************************************************************
2  copyright : (C) 2005 by Inge Wallin
3  email : inge@lysator.liu.se
4  ***************************************************************************/
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 #ifndef MOLECULEPARSER_H
15 #define MOLECULEPARSER_H
16 
17 #include "libkdeedu_science_export.h"
18 
19 #include "element.h"
20 #include "parser.h"
21 
22 #include <QtCore/QMap>
23 #include <QtCore/QList>
24 
25 
30 class SCIENCE_EXPORT ElementCount
31 {
32  public:
36  ElementCount(Element *_element, int _count)
37  {
38  m_element = _element;
39  m_count = _count;
40  }
41 
45  ElementCount(Element *_element)
46  {
47  m_element = _element;
48  m_count = 0;
49  }
53  ~ElementCount();
54 
58  Element *element() const { return m_element; }
59 
63  int count() const { return m_count; }
64 
69  void add(int _count) { m_count += _count; }
70  void multiply(int _factor) { m_count *= _factor; }
71 
75  Element *m_element;
79  int m_count;
80 };
81 
82 
90 class SCIENCE_EXPORT ElementCountMap
91 {
92  public:
96  ElementCountMap();
97 
101  ~ElementCountMap();
102 
106  void clear(){
107  m_map.clear();
108  }
109 
114  ElementCount *search(Element *_element);
115 
119  void add(ElementCountMap &_map);
120 
126  QList<Element*> elements();
127 
132  void add(Element *_element, int _count);
133 
137  void multiply(int _factor);
138 
139  QList<ElementCount*> map(){
140  return m_map;
141  }
142 
143  private:
144  QList<ElementCount*> m_map;
145 };
146 
147 
148 
182 class SCIENCE_EXPORT MoleculeParser : public Parser {
183 
184 public:
190  MoleculeParser( const QList<Element*>& list );
191 
197  MoleculeParser( const QString& _str);
198 
202  virtual ~MoleculeParser();
203 
214  bool weight(const QString& _moleculeString,
215  double *_resultMass,
216  ElementCountMap *_resultMap);
217 
218  QSet<QString> aliasList();
219  private:
220  // Helper functions
221  bool parseSubmolecule(double *_resultMass,
222  ElementCountMap *_resultMap);
223  bool parseTerm(double *_resultMass,
224  ElementCountMap *_resultMap);
225  // This function expands the molecule string
226  // eg expandFormula(EtOH) returns (C2H5)OH
227  QString expandFormula(const QString& _shortMolecularMass);
228  // This function expands a term
229  // eg expandTerm(Et) returns (C2H5)
230  QString expandTerm(const QString& _group);
231 
232  QList<Element*> m_elementList;
233 
234  static const int ELEMENT_TOKEN = 300;
235 
236  Element *lookupElement( const QString& _name );
237 
238  QMap<Element*, int> m_elementMap;
239 
240  // Contains the list of aliases eg, { "Et - C2H5", "Me - CH3"}
241  QSet<QString> *m_aliasList;
242  //if this booloean is "true" the parser found an error
243  bool m_error;
244 
245 protected:
246 
250  virtual int getNextToken();
251 
252 private:
253  Element *m_elementVal; // Valid if m_nextToken == ELEMENT_TOKEN
254 };
255 
256 #endif
libkdeedu_science_export.h
element.h
ElementCountMap::clear
void clear()
Clear the map of ElementCount pointers.
Definition: moleculeparser.h:106
ElementCount::element
Element * element() const
Definition: moleculeparser.h:58
MoleculeParser
Parse molecule formulas.
Definition: moleculeparser.h:182
ElementCount::add
void add(int _count)
Add _count occurrences of the Element.
Definition: moleculeparser.h:69
parser.h
ElementCount::m_element
Element * m_element
The Element of the object.
Definition: moleculeparser.h:75
ElementCount::m_count
int m_count
The number of occurrences.
Definition: moleculeparser.h:79
ElementCount
Definition: moleculeparser.h:30
ElementCount::multiply
void multiply(int _factor)
Definition: moleculeparser.h:70
Element
In this class all information about an element are stored.
Definition: element.h:41
ElementCountMap::map
QList< ElementCount * > map()
Definition: moleculeparser.h:139
SCIENCE_EXPORT
#define SCIENCE_EXPORT
Definition: libkdeedu_science_export.h:32
ElementCount::ElementCount
ElementCount(Element *_element, int _count)
Constructor.
Definition: moleculeparser.h:36
ElementCount::count
int count() const
Definition: moleculeparser.h:63
ElementCountMap
This class is used to count the elements in the molecule which is being calculated.
Definition: moleculeparser.h:90
Parser::getNextToken
virtual int getNextToken()
Fetches the next token.
Definition: parser.cpp:184
ElementCount::ElementCount
ElementCount(Element *_element)
Constructor.
Definition: moleculeparser.h:45
Parser
This is a general purpose parser originally written by Inge Wallin.
Definition: parser.h:30
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:31 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalzium/libscience

Skip menu "kalzium/libscience"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal