Reference documentation for deal.II version 8.5.1
named_selection.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2000 - 2016 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__named_selection_h
17 #define dealii__named_selection_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/algorithms/any_data.h>
21 
22 #include <string>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
35 {
36 
37 public:
38 
44  void add (const std::string &name);
45 
46 
50  void initialize(const AnyData &data);
51 
52 
57  unsigned int size() const;
58 
59 
66  unsigned int operator() (unsigned int i) const;
67 
68 
69 private:
70 
74  std::vector<std::string> names;
75 
79  std::vector<unsigned int> indices;
80 
81 };
82 
83 
84 inline
85 unsigned int
87 {
88 
89  return names.size();
90 
91 }
92 
93 
94 inline
95 void
96 NamedSelection::add(const std::string &s)
97 {
98 
99  names.push_back(s);
100 
101 }
102 
103 
104 inline
105 unsigned int
106 NamedSelection::operator() (unsigned int i) const
107 {
108 
109  Assert (indices.size() == names.size(), ExcNotInitialized());
110 
111  AssertIndexRange(i, size());
112 
113  return indices[i];
114 
115 }
116 
117 DEAL_II_NAMESPACE_CLOSE
118 
119 #endif
void add(const std::string &name)
std::vector< unsigned int > indices
#define AssertIndexRange(index, range)
Definition: exceptions.h:1170
static ::ExceptionBase & ExcNotInitialized()
#define Assert(cond, exc)
Definition: exceptions.h:313
void initialize(const AnyData &data)
std::vector< std::string > names
unsigned int size() const
unsigned int operator()(unsigned int i) const