Chombo + EB  3.2
IFid.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _IFID_H_
12 #define _IFID_H_
13 
14 #include "Vector.H"
15 #include <string>
16 #include "CH_assert.H"
17 #include "SPMD.H"
18 #include "NamespaceHeader.H"
19 
20 //! \class IFid
21 //! This class uniquely identifies a boundary represented by a primitive
22 //! implicit function. We don't envision this being subclassed.
23 class IFid
24 {
25  public:
26 
27  //! Constructs an empty ID. This is needed for serialization.
28  IFid()
29  :
30  m_names()
31  {
32  }
33 
34  //! Constructs an ID from the given string.
35  explicit IFid(const std::string& a_name)
36  :
37  m_names(1, a_name)
38  {
39  }
40 
41  //! Copy constructor.
42  IFid(const IFid& a_rhs)
43  :
44  m_names(a_rhs.m_names)
45  {
46  }
47 
48  //! This factory method creates an ID by aggregating the given list of IDs.
49  static IFid aggregate(const Vector<IFid>& a_IDs)
50  {
51  CH_assert(a_IDs.size() > 0);
52  IFid agg(a_IDs[0]);
53  for (int i = 1; i < a_IDs.size(); ++i)
54  {
55  agg.append(a_IDs[i]);
56  }
57  return agg;
58  }
59 
60  //! Destructor (not virtual).
62  {
63  }
64 
65  //! Assignment operator.
66  IFid& operator=(const IFid& a_rhs)
67  {
68  if (this != &a_rhs)
69  {
70  m_names = a_rhs.m_names;
71  }
72  return *this;
73  }
74 
75  //! Sets the names associated with this identifier.
76  void setNames(const Vector<std::string>& a_names)
77  {
78  m_names = a_names;
79  }
80 
81  //! Returns the list of names identifying all functions associated with this
82  //! IFid.
83  const Vector<std::string>& names() const
84  {
85  return m_names;
86  }
87 
88  //! Returns true if the given IFid is the same as this one, false otherwise.
89  bool operator==(const IFid& a_rhs) const
90  {
91  if (a_rhs.m_names.size() != m_names.size()) return false;
92  for (int i = 0; i < m_names.size(); ++i)
93  {
94  if (m_names[i] != a_rhs.m_names[i])
95  return false;
96  }
97  return true;
98  }
99 
100  //! Returns true if the given IFid differs from this one, false otherwise.
101  bool operator!=(const IFid& a_rhs) const
102  {
103  return !(*this == a_rhs);
104  }
105 
106  private:
107 
108  void append(const IFid& a_rhs)
109  {
110  for (int i = 0; i < a_rhs.m_names.size(); ++i)
111  m_names.push_back(a_rhs.m_names[i]);
112  }
113 
114  // List of names.
116 
117 };
118 
119 //-----------------------------------------------------------------------
120 // Template specializations of serialization functions.
121 //-----------------------------------------------------------------------
122 template <>
123 inline int
124 linearSize(const IFid& a_id)
125 {
126  // An IFid is basically a list of strings.
127  return linearSize(a_id.names());
128 }
129 //-----------------------------------------------------------------------
130 
131 //-----------------------------------------------------------------------
132 template <>
133 inline void
135  const void* const inBuf)
136 {
138  linearIn(names, inBuf);
139  a_id.setNames(names);
140 }
141 //-----------------------------------------------------------------------
142 
143 
144 //-----------------------------------------------------------------------
145 template <>
146 inline void
147 linearOut(void* const a_outBuf,
148  const IFid& a_id)
149 {
150  linearOut(a_outBuf, a_id.names());
151 }
152 //-----------------------------------------------------------------------
153 
154 #include "NamespaceFooter.H"
155 
156 #endif
~IFid()
Destructor (not virtual).
Definition: IFid.H:61
Vector< std::string > m_names
Definition: IFid.H:115
#define CH_assert(cond)
Definition: CHArray.H:37
IFid(const IFid &a_rhs)
Copy constructor.
Definition: IFid.H:42
bool operator==(const IFid &a_rhs) const
Returns true if the given IFid is the same as this one, false otherwise.
Definition: IFid.H:89
void setNames(const Vector< std::string > &a_names)
Sets the names associated with this identifier.
Definition: IFid.H:76
void append(const IFid &a_rhs)
Definition: IFid.H:108
Definition: IFid.H:23
IFid(const std::string &a_name)
Constructs an ID from the given string.
Definition: IFid.H:35
int linearSize(const IFid &a_id)
Definition: IFid.H:124
IFid & operator=(const IFid &a_rhs)
Assignment operator.
Definition: IFid.H:66
void push_back(const T &in)
Definition: Vector.H:295
void linearOut(void *const a_outBuf, const IFid &a_id)
Definition: IFid.H:147
size_t size() const
Definition: Vector.H:192
static IFid aggregate(const Vector< IFid > &a_IDs)
This factory method creates an ID by aggregating the given list of IDs.
Definition: IFid.H:49
const Vector< std::string > & names() const
Definition: IFid.H:83
bool operator!=(const IFid &a_rhs) const
Returns true if the given IFid differs from this one, false otherwise.
Definition: IFid.H:101
void linearIn(IFid &a_id, const void *const inBuf)
Definition: IFid.H:134
IFid()
Constructs an empty ID. This is needed for serialization.
Definition: IFid.H:28