ENH: Added HashPtrTable construct INew from dictionary

This commit is contained in:
andy
2010-10-11 17:28:56 +01:00
parent ae2815e75b
commit 9de20a6654
2 changed files with 32 additions and 0 deletions

View File

@ -72,6 +72,11 @@ class HashPtrTable
template<class INew> template<class INew>
void read(Istream&, const INew& inewt); void read(Istream&, const INew& inewt);
//- Read from dictionary using given dictionary constructor class
template<class INew>
void read(const dictionary& dict, const INew& inewt);
public: public:
@ -91,6 +96,10 @@ public:
//- Construct from Istream using default Istream constructor class //- Construct from Istream using default Istream constructor class
HashPtrTable(Istream&); HashPtrTable(Istream&);
//- Construct from dictionary using default dictionary constructor
// class
HashPtrTable(const dictionary& dict);
//- Construct as copy //- Construct as copy
HashPtrTable(const HashPtrTable<T, Key, Hash>&); HashPtrTable(const HashPtrTable<T, Key, Hash>&);

View File

@ -27,6 +27,7 @@ License
#include "Istream.H" #include "Istream.H"
#include "Ostream.H" #include "Ostream.H"
#include "INew.H" #include "INew.H"
#include "dictionary.H"
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
@ -137,6 +138,21 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt)
} }
template<class T, class Key, class Hash>
template<class INew>
void Foam::HashPtrTable<T, Key, Hash>::read
(
const dictionary& dict,
const INew& inewt
)
{
forAllConstIter(dictionary, dict, iter)
{
insert(iter().keyword(), inewt(dict.subDict(iter().keyword())).ptr());
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
@ -154,6 +170,13 @@ Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(Istream& is)
} }
template<class T, class Key, class Hash>
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(const dictionary& dict)
{
read(dict, INew<T>());
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>