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 _IFID_H_ 00012 #define _IFID_H_ 00013 00014 #include "Vector.H" 00015 #include <string> 00016 #include "CH_assert.H" 00017 #include "SPMD.H" 00018 #include "NamespaceHeader.H" 00019 00020 //! \class IFid 00021 //! This class uniquely identifies a boundary represented by a primitive 00022 //! implicit function. We don't envision this being subclassed. 00023 class IFid 00024 { 00025 public: 00026 00027 //! Constructs an empty ID. This is needed for serialization. 00028 IFid() 00029 : 00030 m_names() 00031 { 00032 } 00033 00034 //! Constructs an ID from the given string. 00035 explicit IFid(const std::string& a_name) 00036 : 00037 m_names(1, a_name) 00038 { 00039 } 00040 00041 //! Copy constructor. 00042 IFid(const IFid& a_rhs) 00043 : 00044 m_names(a_rhs.m_names) 00045 { 00046 } 00047 00048 //! This factory method creates an ID by aggregating the given list of IDs. 00049 static IFid aggregate(const Vector<IFid>& a_IDs) 00050 { 00051 CH_assert(a_IDs.size() > 0); 00052 IFid agg(a_IDs[0]); 00053 for (int i = 1; i < a_IDs.size(); ++i) 00054 { 00055 agg.append(a_IDs[i]); 00056 } 00057 return agg; 00058 } 00059 00060 //! Destructor (not virtual). 00061 ~IFid() 00062 { 00063 } 00064 00065 //! Assignment operator. 00066 IFid& operator=(const IFid& a_rhs) 00067 { 00068 if (this != &a_rhs) 00069 { 00070 m_names = a_rhs.m_names; 00071 } 00072 return *this; 00073 } 00074 00075 //! Sets the names associated with this identifier. 00076 void setNames(const Vector<std::string>& a_names) 00077 { 00078 m_names = a_names; 00079 } 00080 00081 //! Returns the list of names identifying all functions associated with this 00082 //! IFid. 00083 const Vector<std::string>& names() const 00084 { 00085 return m_names; 00086 } 00087 00088 //! Returns true if the given IFid is the same as this one, false otherwise. 00089 bool operator==(const IFid& a_rhs) const 00090 { 00091 if (a_rhs.m_names.size() != m_names.size()) return false; 00092 for (int i = 0; i < m_names.size(); ++i) 00093 { 00094 if (m_names[i] != a_rhs.m_names[i]) 00095 return false; 00096 } 00097 return true; 00098 } 00099 00100 //! Returns true if the given IFid differs from this one, false otherwise. 00101 bool operator!=(const IFid& a_rhs) const 00102 { 00103 return !(*this == a_rhs); 00104 } 00105 00106 private: 00107 00108 void append(const IFid& a_rhs) 00109 { 00110 for (int i = 0; i < a_rhs.m_names.size(); ++i) 00111 m_names.push_back(a_rhs.m_names[i]); 00112 } 00113 00114 // List of names. 00115 Vector<std::string> m_names; 00116 00117 }; 00118 00119 //----------------------------------------------------------------------- 00120 // Template specializations of serialization functions. 00121 //----------------------------------------------------------------------- 00122 template <> 00123 inline int 00124 linearSize(const IFid& a_id) 00125 { 00126 // An IFid is basically a list of strings. 00127 return linearSize(a_id.names()); 00128 } 00129 //----------------------------------------------------------------------- 00130 00131 //----------------------------------------------------------------------- 00132 template <> 00133 inline void 00134 linearIn(IFid& a_id, 00135 const void* const inBuf) 00136 { 00137 Vector<std::string> names; 00138 linearIn(names, inBuf); 00139 a_id.setNames(names); 00140 } 00141 //----------------------------------------------------------------------- 00142 00143 00144 //----------------------------------------------------------------------- 00145 template <> 00146 inline void 00147 linearOut(void* const a_outBuf, 00148 const IFid& a_id) 00149 { 00150 linearOut(a_outBuf, a_id.names()); 00151 } 00152 //----------------------------------------------------------------------- 00153 00154 #include "NamespaceFooter.H" 00155 00156 #endif