00001 #ifdef CH_LANG_CC 00002 /* 00003 * _______ __ 00004 * / ___/ / ___ __ _ / / ___ 00005 * / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00006 * \___/_//_/\___/_/_/_/_.__/\___/ 00007 * Please refer to Copyright.txt, in Chombo's root directory. 00008 */ 00009 #endif 00010 00011 #ifndef _IFIDTABLE_H_ 00012 #define _IFIDTABLE_H_ 00013 00014 #include "IFid.H" 00015 #include <algorithm> 00016 #include "NamespaceHeader.H" 00017 00018 //! \class IFidTable 00019 //! This class maintains a mapping between integer indices and 00020 //! IFids for a given EB index space. 00021 class IFidTable 00022 { 00023 public: 00024 00025 //! Creates an empty table. 00026 IFidTable() 00027 { 00028 } 00029 00030 //! Destructor (not virtual). 00031 ~IFidTable() 00032 { 00033 } 00034 00035 //! Adds the given IFid to the table, returning the index at which 00036 //! it may be subsequently retrieved. If the IFid already exists in 00037 //! the table, the table is unaltered and the index of the existing 00038 //! entry is returned. 00039 int add(const IFid& a_id) 00040 { 00041 std::vector<IFid>::const_iterator iter = 00042 find(m_ids.stdVector().begin(), m_ids.stdVector().end(), a_id); 00043 if (iter == m_ids.stdVector().end()) // Not found! 00044 { 00045 int index = m_ids.size(); 00046 m_ids.push_back(a_id); 00047 return index; 00048 } 00049 else 00050 return iter - m_ids.stdVector().begin(); // Return the existing index. 00051 } 00052 00053 //! Retrieves the identifier corresponding to the given index. 00054 const IFid& operator[](int a_index) const 00055 { 00056 CH_assert(a_index >= 0); 00057 CH_assert(a_index < m_ids.size()); 00058 return m_ids[a_index]; 00059 } 00060 00061 //! Returns the number of IDs in the table. 00062 int size() const 00063 { 00064 return m_ids.size(); 00065 } 00066 00067 // Serialization helpers. 00068 int linearSize() const 00069 { 00070 return linearListSize(m_ids); 00071 } 00072 void linearIn(const void* const inBuf) 00073 { 00074 linearListIn(m_ids, inBuf); 00075 } 00076 void linearOut(void* const a_outBuf) const 00077 { 00078 linearListOut(a_outBuf, m_ids); 00079 } 00080 00081 private: 00082 00083 // List of IDs. 00084 Vector<IFid> m_ids; 00085 00086 // Forbidden. 00087 IFidTable(const IFidTable&); 00088 IFidTable& operator=(const IFidTable&); 00089 }; 00090 00091 //----------------------------------------------------------------------- 00092 // Template specializations of serialization functions. 00093 //----------------------------------------------------------------------- 00094 template <> 00095 inline int 00096 linearSize(const IFidTable& a_table) 00097 { 00098 return a_table.linearSize(); 00099 } 00100 //----------------------------------------------------------------------- 00101 00102 //----------------------------------------------------------------------- 00103 template <> 00104 inline void 00105 linearIn(IFidTable& a_table, 00106 const void* const inBuf) 00107 { 00108 a_table.linearIn(inBuf); 00109 } 00110 //----------------------------------------------------------------------- 00111 00112 00113 //----------------------------------------------------------------------- 00114 template <> 00115 inline void 00116 linearOut(void* const a_outBuf, 00117 const IFidTable& a_table) 00118 { 00119 a_table.linearOut(a_outBuf); 00120 } 00121 //----------------------------------------------------------------------- 00122 00123 #include "NamespaceFooter.H" 00124 00125 #endif