00001
00002
00014
00015
00016 #ifndef polybori_groebner_PolyEntryVector_h_
00017 #define polybori_groebner_PolyEntryVector_h_
00018
00019 #include "PolyEntryReference.h"
00020 #include "PolyEntryIndices.h"
00021 #include "PolyEntry.h"
00022
00023
00024 #include "groebner_defs.h"
00025
00026 BEGIN_NAMESPACE_PBORIGB
00027
00028 class PolyEntryVector {
00029 typedef std::vector<PolyEntry> data_type;
00030
00031 public:
00033
00034 typedef data_type::value_type value_type;
00035 typedef data_type::size_type size_type;
00036 typedef data_type::const_iterator const_iterator;
00037 typedef data_type::const_reference const_reference;
00038 typedef PolyEntryReference reference;
00039
00040 bool empty() const { return m_data.empty(); }
00041 size_type size() const { return m_data.size(); }
00042 const_iterator begin() const { return m_data.begin(); }
00043 const_iterator end() const { return m_data.end(); }
00044 const_reference front() const { return m_data.front(); }
00045 const_reference back() const { return m_data.back(); }
00046
00048 template <class KeyType>
00049 const_reference operator[](const KeyType& rhs) const {
00050 return operator()(rhs);
00051 }
00053
00055 reference first() { return reference(m_data.front(), m_indices); }
00056
00058 const_reference first() const { return front(); }
00059
00061 reference last() { return reference(m_data.back(), m_indices); }
00062
00064 const_reference last() const { return back(); }
00065
00067 PolyEntryVector():
00068 m_data(), m_indices() {}
00069
00071 virtual void append(const PolyEntry& element) {
00072 m_data.push_back(element);
00073
00074 #ifndef PBORI_NDEBUG
00075 if(m_indices.checked(back().lead) != (size_type)-1)
00076 throw std::runtime_error("leading terms not unique when appending to PolyEntryVector");
00077 #endif
00078 m_indices.insert(back(), size() - 1);
00079 }
00080
00082 template <class KeyType>
00083 const_reference operator()(const KeyType& key) const {
00084 return m_data[index(key)];
00085 }
00086
00088 template <class KeyType>
00089 reference operator()(const KeyType& rhs) {
00090 return reference(m_data[index(rhs)], m_indices);
00091 }
00092
00094 template <class KeyType, class Type>
00095 void exchange(const KeyType& key, const Type& rhs) { operator()(key) = rhs; }
00096
00098 template <class KeyType>
00099 size_type index(const KeyType& key) const { return m_indices(key); }
00100
00102 template <class KeyType>
00103 size_type checked_index(const KeyType& key) const {
00104 return m_indices.checked(key);
00105 }
00107 template <class KeyType>
00108 const Polynomial& polynomial(const KeyType& key) const {
00109 return operator[](key).p;
00110 }
00111
00112 private:
00113 data_type m_data;
00114 PolyEntryIndices m_indices;
00115 };
00116
00117 END_NAMESPACE_PBORIGB
00118
00119 #endif