Reference documentation for deal.II version Git c4822b6378 2021-05-16 08:02:52 +0200
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
collection.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_hp_collection_h
17 #define dealii_hp_collection_h
18 
19 #include <deal.II/base/config.h>
20 
23 
24 #include <memory>
25 #include <vector>
26 
28 
29 namespace hp
30 {
39  template <typename T>
40  class Collection : public Subscriptor
41  {
42  public:
47  Collection() = default;
48 
52  void
53  push_back(const std::shared_ptr<const T> &new_entry);
54 
62  const T &operator[](const unsigned int index) const;
63 
67  unsigned int
68  size() const;
69 
74  std::size_t
75  memory_consumption() const;
76 
77  private:
81  std::vector<std::shared_ptr<const T>> entries;
82  };
83 
84 
85  /* --------------- inline functions ------------------- */
86 
87 
88 
89  template <typename T>
90  std::size_t
92  {
93  return (sizeof(*this) + MemoryConsumption::memory_consumption(entries));
94  }
95 
96 
97 
98  template <typename T>
99  void
100  Collection<T>::push_back(const std::shared_ptr<const T> &new_entry)
101  {
102  entries.push_back(new_entry);
103  }
104 
105 
106 
107  template <typename T>
108  inline unsigned int
110  {
111  return entries.size();
112  }
113 
114 
115 
116  template <typename T>
117  inline const T &Collection<T>::operator[](const unsigned int index) const
118  {
119  AssertIndexRange(index, entries.size());
120  return *entries[index];
121  }
122 
123 } // namespace hp
124 
125 
127 
128 #endif
unsigned int size() const
Definition: collection.h:109
void push_back(const std::shared_ptr< const T > &new_entry)
Definition: collection.h:100
#define AssertIndexRange(index, range)
Definition: exceptions.h:1690
const T & operator[](const unsigned int index) const
Definition: collection.h:117
std::vector< std::shared_ptr< const T > > entries
Definition: collection.h:81
std::size_t memory_consumption() const
Definition: collection.h:91
static const char T
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:396
Definition: hp.h:117
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:395
Collection()=default
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)