Chombo + EB  3.2
IFidTable.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 _IFIDTABLE_H_
12 #define _IFIDTABLE_H_
13 
14 #include "IFid.H"
15 #include <algorithm>
16 #include "NamespaceHeader.H"
17 
18 //! \class IFidTable
19 //! This class maintains a mapping between integer indices and
20 //! IFids for a given EB index space.
21 class IFidTable
22 {
23  public:
24 
25  //! Creates an empty table.
27  {
28  }
29 
30  //! Destructor (not virtual).
32  {
33  }
34 
35  //! Adds the given IFid to the table, returning the index at which
36  //! it may be subsequently retrieved. If the IFid already exists in
37  //! the table, the table is unaltered and the index of the existing
38  //! entry is returned.
39  int add(const IFid& a_id)
40  {
41  std::vector<IFid>::const_iterator iter =
42  find(m_ids.stdVector().begin(), m_ids.stdVector().end(), a_id);
43  if (iter == m_ids.stdVector().end()) // Not found!
44  {
45  int index = m_ids.size();
46  m_ids.push_back(a_id);
47  return index;
48  }
49  else
50  return iter - m_ids.stdVector().begin(); // Return the existing index.
51  }
52 
53  //! Retrieves the identifier corresponding to the given index.
54  const IFid& operator[](int a_index) const
55  {
56  CH_assert(a_index >= 0);
57  CH_assert(a_index < m_ids.size());
58  return m_ids[a_index];
59  }
60 
61  //! Returns the number of IDs in the table.
62  int size() const
63  {
64  return m_ids.size();
65  }
66 
67  // Serialization helpers.
68  int linearSize() const
69  {
70  return linearListSize(m_ids);
71  }
72  void linearIn(const void* const inBuf)
73  {
74  linearListIn(m_ids, inBuf);
75  }
76  void linearOut(void* const a_outBuf) const
77  {
78  linearListOut(a_outBuf, m_ids);
79  }
80 
81  private:
82 
83  // List of IDs.
85 
86  // Forbidden.
87  IFidTable(const IFidTable&);
88  IFidTable& operator=(const IFidTable&);
89 };
90 
91 //-----------------------------------------------------------------------
92 // Template specializations of serialization functions.
93 //-----------------------------------------------------------------------
94 template <>
95 inline int
96 linearSize(const IFidTable& a_table)
97 {
98  return a_table.linearSize();
99 }
100 //-----------------------------------------------------------------------
101 
102 //-----------------------------------------------------------------------
103 template <>
104 inline void
106  const void* const inBuf)
107 {
108  a_table.linearIn(inBuf);
109 }
110 //-----------------------------------------------------------------------
111 
112 
113 //-----------------------------------------------------------------------
114 template <>
115 inline void
116 linearOut(void* const a_outBuf,
117  const IFidTable& a_table)
118 {
119  a_table.linearOut(a_outBuf);
120 }
121 //-----------------------------------------------------------------------
122 
123 #include "NamespaceFooter.H"
124 
125 #endif
int add(const IFid &a_id)
Definition: IFidTable.H:39
std::vector< T > & stdVector()
Returns std::vector under the hood.
Definition: Vector.H:396
IFidTable()
Creates an empty table.
Definition: IFidTable.H:26
void linearOut(void *const a_outBuf) const
Definition: IFidTable.H:76
Definition: IFidTable.H:21
#define CH_assert(cond)
Definition: CHArray.H:37
const IFid & operator[](int a_index) const
Retrieves the identifier corresponding to the given index.
Definition: IFidTable.H:54
void linearListOut(void *const a_outBuf, const Vector< T > &a_inputT)
Definition: SPMDI.H:258
Definition: IFid.H:23
void push_back(const T &in)
Definition: Vector.H:295
size_t size() const
Definition: Vector.H:192
int size() const
Returns the number of IDs in the table.
Definition: IFidTable.H:62
void linearListIn(Vector< T > &a_outputT, const void *const a_inBuf)
Definition: SPMDI.H:229
int linearListSize(const Vector< T > &a_input)
Definition: SPMDI.H:290
int linearSize() const
Definition: IFidTable.H:68
void linearIn(const void *const inBuf)
Definition: IFidTable.H:72
~IFidTable()
Destructor (not virtual).
Definition: IFidTable.H:31
IFidTable & operator=(const IFidTable &)
Vector< IFid > m_ids
Definition: IFidTable.H:84