Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
named_selection.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2000 - 2018 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_named_selection_h
17 #define dealii_named_selection_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/algorithms/any_data.h>
22 
23 #include <string>
24 
25 DEAL_II_NAMESPACE_OPEN
26 
36 {
37 public:
43  void
44  add(const std::string &name);
45 
46 
50  void
51  initialize(const AnyData &data);
52 
53 
58  unsigned int
59  size() const;
60 
61 
68  unsigned int
69  operator()(unsigned int i) const;
70 
71 
72 private:
76  std::vector<std::string> names;
77 
81  std::vector<unsigned int> indices;
82 };
83 
84 
85 inline unsigned int
87 {
88  return names.size();
89 }
90 
91 
92 inline void
93 NamedSelection::add(const std::string &s)
94 {
95  names.push_back(s);
96 }
97 
98 
99 inline unsigned int
100 NamedSelection::operator()(unsigned int i) const
101 {
102  Assert(indices.size() == names.size(), ExcNotInitialized());
103 
104  AssertIndexRange(i, size());
105 
106  return indices[i];
107 }
108 
109 DEAL_II_NAMESPACE_CLOSE
110 
111 #endif
void add(const std::string &name)
std::vector< unsigned int > indices
#define AssertIndexRange(index, range)
Definition: exceptions.h:1637
static ::ExceptionBase & ExcNotInitialized()
#define Assert(cond, exc)
Definition: exceptions.h:1407
void initialize(const AnyData &data)
std::vector< std::string > names
unsigned int size() const
unsigned int operator()(unsigned int i) const