Reference documentation for deal.II version Git 497f915867 2021-09-17 22:46:48 +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 &
63  operator[](const unsigned int index) const;
64 
68  unsigned int
69  size() const;
70 
75  std::size_t
76  memory_consumption() const;
77 
78  private:
82  std::vector<std::shared_ptr<const T>> entries;
83  };
84 
85 
86  /* --------------- inline functions ------------------- */
87 
88 
89 
90  template <typename T>
91  std::size_t
93  {
94  return (sizeof(*this) + MemoryConsumption::memory_consumption(entries));
95  }
96 
97 
98 
99  template <typename T>
100  void
101  Collection<T>::push_back(const std::shared_ptr<const T> &new_entry)
102  {
103  entries.push_back(new_entry);
104  }
105 
106 
107 
108  template <typename T>
109  inline unsigned int
111  {
112  return entries.size();
113  }
114 
115 
116 
117  template <typename T>
118  inline const T &
119  Collection<T>::operator[](const unsigned int index) const
120  {
121  AssertIndexRange(index, entries.size());
122  return *entries[index];
123  }
124 
125 } // namespace hp
126 
127 
129 
130 #endif
unsigned int size() const
Definition: collection.h:110
void push_back(const std::shared_ptr< const T > &new_entry)
Definition: collection.h:101
#define AssertIndexRange(index, range)
Definition: exceptions.h:1718
const T & operator[](const unsigned int index) const
Definition: collection.h:119
std::vector< std::shared_ptr< const T > > entries
Definition: collection.h:82
std::size_t memory_consumption() const
Definition: collection.h:92
static const char T
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:401
Definition: hp.h:117
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:400
Collection()=default
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)