ug4
section_container.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __UTIL__SECTION_CONTAINER__
34 #define __UTIL__SECTION_CONTAINER__
35 
36 #include <vector>
37 #include "../types.h"
38 
39 namespace ug
40 {
41 
44 
46 // SectionContainer
48 
57 template <class TValue, class TContainer>
59 {
60  public:
61  typedef TValue value_type;
62  typedef TContainer Container;
63  typedef typename Container::iterator iterator;
64  typedef typename Container::const_iterator const_iterator;
65  //typedef typename Container::reverse_iterator reverse_iterator;
66  //typedef typename Container::const_reverse_iterator const_reverse_iterator;
67 
68  public:
70 
71  void clear();
72  void clear_section(int sectionIndex);
73 
74  iterator insert(const TValue& val, int sectionIndex);
75  void erase(const iterator& iter, int sectionIndex);
76 
77  inline iterator begin() {return m_container.begin();}
78  inline iterator end() {return m_container.end();}
79 
80  inline const_iterator begin() const {return m_container.begin();}
81  inline const_iterator end() const {return m_container.end();}
82 
85  iterator section_begin(int sectionIndex);
86 
87  const_iterator section_begin(int sectionIndex) const;
88 
91  iterator section_end(int sectionIndex);
92 
93  const_iterator section_end(int sectionIndex) const;
94 
96 
99  value_type& front(int secIndex = -1);
100 
102 
105  value_type& back(int secIndex = -1);
106 
107  uint num_elements(int sectionIndex) const;
108  inline uint num_elements() const {return m_numElements;}
109  inline int num_sections() const {return (int)m_vSections.size();}
110 
112 
116  inline Container& get_container() {return m_container;}
117 
119 
123  void append(const SectionContainer& c);
124 
127 
128  protected:
129  void add_sections(int num);
130 
131  protected:
132  struct Section
133  {
134  Section() {}
135  Section(const iterator& elemsBegin, const iterator& elemsEnd,
136  //const reverse_iterator& elemsRBegin,
137  //const reverse_iterator& elemsREnd,
138  int numElems) :
139  m_elemsBegin(elemsBegin), m_elemsEnd(elemsEnd),
140  //m_elemsRBegin(elemsRBegin), m_elemsREnd(elemsREnd),
141  m_numElements(numElems)
142  {}
143 
146  //reverse_iterator m_elemsRBegin;
147  //reverse_iterator m_elemsREnd;
149  };
150 
151  typedef std::vector<Section> SectionVec;
152 
153  protected:
157 };
158 
159 // end group ugbase_common_util
161 
162 }// end of namespace
163 
164 // include implementation
165 #include "section_container.hpp"
166 
167 #endif
A container that is divided into different sections.
Definition: section_container.h:59
Container m_container
Definition: section_container.h:154
std::vector< Section > SectionVec
Definition: section_container.h:151
Container::const_iterator const_iterator
Definition: section_container.h:64
Container & get_container()
returns the container for raw access.
Definition: section_container.h:116
uint m_numElements
Definition: section_container.h:156
void erase(const iterator &iter, int sectionIndex)
Definition: section_container.hpp:296
const_iterator end() const
Definition: section_container.h:81
iterator section_begin(int sectionIndex)
Definition: section_container.hpp:117
value_type & front(int secIndex=-1)
returns the first entry in the given section.
Definition: section_container.hpp:165
iterator begin()
Definition: section_container.h:77
int num_sections() const
Definition: section_container.h:109
void add_sections(int num)
Definition: section_container.hpp:200
const_iterator begin() const
Definition: section_container.h:80
void clear_section(int sectionIndex)
Definition: section_container.hpp:81
uint num_elements() const
Definition: section_container.h:108
iterator section_end(int sectionIndex)
Definition: section_container.hpp:143
SectionVec m_vSections
Definition: section_container.h:155
TValue value_type
Definition: section_container.h:61
value_type & back(int secIndex=-1)
returns the last entry in the given section.
Definition: section_container.hpp:176
void transfer_elements(SectionContainer &c)
takes all elements from the given section container and transfers them to this one.
Definition: section_container.hpp:361
TContainer Container
Definition: section_container.h:62
Container::iterator iterator
Definition: section_container.h:63
iterator end()
Definition: section_container.h:78
void append(const SectionContainer &c)
appends the elements of the given container to the current one
Definition: section_container.hpp:347
void clear()
Definition: section_container.hpp:63
iterator insert(const TValue &val, int sectionIndex)
Definition: section_container.hpp:224
SectionContainer()
Definition: section_container.hpp:56
unsigned int uint
Definition: types.h:114
the ug namespace
T value_type
Definition: sparsematrix_interface.h:2
Definition: section_container.h:133
Section()
Definition: section_container.h:134
Section(const iterator &elemsBegin, const iterator &elemsEnd, int numElems)
Definition: section_container.h:135
iterator m_elemsEnd
Definition: section_container.h:145
uint m_numElements
Definition: section_container.h:148
iterator m_elemsBegin
Definition: section_container.h:144