NuTo
Numerics Tool
DofType.h
Go to the documentation of this file.
1 #pragma once
2 #include <string>
3 #include "nuto/base/Exception.h"
4 #include "nuto/base/UniqueId.h"
5 
6 namespace NuTo
7 {
8 class DofType : public NuTo::UniqueId<DofType>
9 {
10 public:
11  DofType(std::string name, int num)
12  : mName(name)
13  , mNum(num)
14  {
15  if (mName.empty())
16  throw Exception(__PRETTY_FUNCTION__, "Provide a name!");
17  if (mNum <= 0)
18  throw Exception(__PRETTY_FUNCTION__, "Number of dofs must be greater than zero.");
19  }
20 
21  const std::string& GetName() const
22  {
23  return mName;
24  }
25 
26  int GetNum() const
27  {
28  return mNum;
29  }
30 
31 private:
32  std::string mName;
33  int mNum;
34 };
35 
37 {
38  bool operator()(const DofType& a, const DofType& b) const
39  {
40  return a.Id() < b.Id();
41  }
42 };
43 
45 {
46  ScalarDofType(std::string name)
47  : DofType(name, 1)
48  {
49  }
50 };
51 } /* NuTo */
Base class for all exceptions thrown in NuTo.
Definition: Exception.h:9
Definition: DofType.h:8
This class provides a unique id (beginning at 0 and incrementing for each object).
Definition: UniqueId.h:10
Definition: DofType.h:36
bool operator()(const DofType &a, const DofType &b) const
Definition: DofType.h:38
int Id() const
Definition: UniqueId.h:18
int GetNum() const
Definition: DofType.h:26
const std::string & GetName() const
Definition: DofType.h:21
ScalarDofType(std::string name)
Definition: DofType.h:46
Definition: DofType.h:44
DofType(std::string name, int num)
Definition: DofType.h:11
Definition: Exception.h:6