| 1 | /*
|
|---|
| 2 | * Formula.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Jul 21, 2010
|
|---|
| 5 | * Author: crueger
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef FORMULA_HPP_
|
|---|
| 9 | #define FORMULA_HPP_
|
|---|
| 10 |
|
|---|
| 11 | #include <vector>
|
|---|
| 12 | #include <iosfwd>
|
|---|
| 13 | #include <iterator>
|
|---|
| 14 |
|
|---|
| 15 | #include "types.hpp"
|
|---|
| 16 |
|
|---|
| 17 | class element;
|
|---|
| 18 |
|
|---|
| 19 | class Formula
|
|---|
| 20 | {
|
|---|
| 21 | public:
|
|---|
| 22 | typedef element* key_type;
|
|---|
| 23 | typedef unsigned int mapped_type;
|
|---|
| 24 | typedef std::pair<key_type, mapped_type> value_type;
|
|---|
| 25 | typedef std::vector<unsigned int> set_t;
|
|---|
| 26 |
|
|---|
| 27 | template <class result_type>
|
|---|
| 28 | class _iterator : public std::iterator <std::bidirectional_iterator_tag,
|
|---|
| 29 | result_type>
|
|---|
| 30 | {
|
|---|
| 31 | public:
|
|---|
| 32 | _iterator(set_t&);
|
|---|
| 33 | _iterator(set_t&,size_t);
|
|---|
| 34 | ~_iterator();
|
|---|
| 35 | _iterator &operator=(const _iterator &);
|
|---|
| 36 | bool operator==(const _iterator&);
|
|---|
| 37 | bool operator!=(const _iterator&);
|
|---|
| 38 | _iterator operator++();
|
|---|
| 39 | _iterator operator++(int);
|
|---|
| 40 | _iterator operator--();
|
|---|
| 41 | _iterator operator--(int);
|
|---|
| 42 | result_type operator*();
|
|---|
| 43 | result_type *operator->();
|
|---|
| 44 | private:
|
|---|
| 45 | set_t *set;
|
|---|
| 46 | size_t pos; // cannot use an iterator, because we need a position to access the element
|
|---|
| 47 | };
|
|---|
| 48 |
|
|---|
| 49 | typedef _iterator<value_type> iterator;
|
|---|
| 50 | typedef _iterator<const value_type> const_iterator;
|
|---|
| 51 | typedef std::reverse_iterator<iterator> reverse_iterator;
|
|---|
| 52 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|---|
| 53 |
|
|---|
| 54 | Formula();
|
|---|
| 55 | Formula(const Formula&);
|
|---|
| 56 | virtual ~Formula();
|
|---|
| 57 |
|
|---|
| 58 | Formula &operator=(const Formula&);
|
|---|
| 59 |
|
|---|
| 60 | std::string toString() const;
|
|---|
| 61 | bool checkOut(std::ostream*) const;
|
|---|
| 62 |
|
|---|
| 63 | unsigned int getElementCount();
|
|---|
| 64 | bool hasElement(const element*) const;
|
|---|
| 65 | bool hasElement(atomicNumber_t) const;
|
|---|
| 66 | bool hasElement(const std::string&) const;
|
|---|
| 67 |
|
|---|
| 68 | void operator+=(const element*);
|
|---|
| 69 | void operator+=(atomicNumber_t);
|
|---|
| 70 | void operator+=(const std::string&);
|
|---|
| 71 |
|
|---|
| 72 | void operator-=(const element*);
|
|---|
| 73 | void operator-=(atomicNumber_t);
|
|---|
| 74 | void operator-=(const std::string&);
|
|---|
| 75 |
|
|---|
| 76 | // only const versions, because someone might try to increment a previously
|
|---|
| 77 | // not set element
|
|---|
| 78 | const unsigned int &operator[](const element*) const;
|
|---|
| 79 | const unsigned int &operator[](atomicNumber_t) const;
|
|---|
| 80 | const unsigned int &operator[](std::string) const;
|
|---|
| 81 |
|
|---|
| 82 | bool operator==(const Formula&) const;
|
|---|
| 83 | bool operator!=(const Formula&) const;
|
|---|
| 84 |
|
|---|
| 85 | iterator begin();
|
|---|
| 86 | const_iterator begin() const;
|
|---|
| 87 | iterator end();
|
|---|
| 88 | const_iterator end() const;
|
|---|
| 89 |
|
|---|
| 90 | reverse_iterator rbegin();
|
|---|
| 91 | const_reverse_iterator rbegin() const;
|
|---|
| 92 | reverse_iterator rend();
|
|---|
| 93 | const_reverse_iterator rend() const;
|
|---|
| 94 |
|
|---|
| 95 | private:
|
|---|
| 96 | mutable set_t elementCounts; // we might need to resize even at const places
|
|---|
| 97 | unsigned int numElements;
|
|---|
| 98 | };
|
|---|
| 99 |
|
|---|
| 100 | std::ostream &operator<<(std::ostream&,const Formula&);
|
|---|
| 101 |
|
|---|
| 102 | #endif /* FORMULA_HPP_ */
|
|---|