KeyedI.H
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "IOstreams.H"
00028
00029
00030
00031
00032
00033 template<class T>
00034 inline Foam::Keyed<T>::Keyed()
00035 :
00036 key_(-1)
00037 {}
00038
00039
00040 template<class T>
00041 inline Foam::Keyed<T>::Keyed(const T& item, const label key)
00042 :
00043 T(item),
00044 key_(key)
00045 {}
00046
00047
00048 template<class T>
00049 inline Foam::Keyed<T>::Keyed(const Xfer<T>& item, const label key)
00050 :
00051 T(item),
00052 key_(key)
00053 {}
00054
00055
00056 template<class T>
00057 inline Foam::Keyed<T>::Keyed(Istream& is)
00058 {
00059 is >> *this;
00060 }
00061
00062
00063
00064
00065 template<class T>
00066 inline Foam::label Foam::Keyed<T>::key() const
00067 {
00068 return key_;
00069 }
00070
00071 template<class T>
00072 inline Foam::label& Foam::Keyed<T>::key()
00073 {
00074 return key_;
00075 }
00076
00077
00078 template<class T>
00079 inline Foam::List<Foam::Keyed<T> >
00080 Foam::Keyed<T>::createList(const List<T>& lst, const label key)
00081 {
00082 List<Keyed<T> > newList(lst.size());
00083
00084 forAll (lst, elemI)
00085 {
00086 newList[elemI] = Keyed(lst[elemI], key);
00087 }
00088 return newList;
00089 }
00090
00091
00092 template<class T>
00093 inline Foam::List<Foam::Keyed<T> >
00094 Foam::Keyed<T>::createList(const List<T>& lst, const List<label>& keys)
00095 {
00096 if (lst.size() != keys.size())
00097 {
00098 FatalErrorIn
00099 (
00100 "Foam::Keyed<T>::createList(const List<T>&, const List<label>&)"
00101 )
00102 << "size mismatch adding keys to a list:" << nl
00103 << "List has size " << lst.size()
00104 << " and keys has size " << keys.size() << nl
00105 << abort(FatalError);
00106 }
00107
00108 List<Keyed<T> > newList(lst.size());
00109
00110 forAll (lst, elemI)
00111 {
00112 newList[elemI] = Keyed(lst[elemI], keys[elemI]);
00113 }
00114 return newList;
00115 }
00116
00117
00118
00119
00120 template<class T>
00121 inline Foam::Istream& Foam::operator>>(Istream& is, Keyed<T>& item)
00122 {
00123
00124 is.readBegin("Keyed<T>");
00125
00126 is >> static_cast<T&>(item);
00127 is >> item.key_;
00128
00129
00130 is.readEnd("Keyed<T>");
00131
00132
00133 is.check("Istream& operator>>(Istream&, Keyed&)");
00134
00135 return is;
00136 }
00137
00138
00139 template<class T>
00140 inline Foam::Ostream& Foam::operator<<(Ostream& os, const Keyed<T>& item)
00141 {
00142 os << token::BEGIN_LIST
00143 << static_cast<const T&>(item)
00144 << token::SPACE << item.key_
00145 << token::END_LIST;
00146
00147 return os;
00148 }
00149
00150
00151
00152
Copyright © 2000-2009 OpenCFD Ltd