lookup function in OpenFOAM

The lookup function in OpenFOAM

The lookup function is defined in dictionary.H and dictionary.C:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ITstream& lookup
(
const word&,
bool recursive=false,
bool patternMatch=true
) const;

Foam::ITstream& Foam::dictionary::lookup
(
const word& keyword,
bool recursive,
bool patternMatch
) const
{
return lookupEntry(keyword, recursive, patternMatch).stream();
}

The return of this function will call:

1
2
3
4
5
6
7
8
9
10
11
12
13
const Foam::entry& Foam::dictionary::lookupEntry
(
const word& keyword,
bool recursive,
bool patternMatch
) const
{
const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);

......

return *entryPtr;
}

The looupEntry function will call:

1
2
3
4
5
6
7
8
9
10
11
12
13
Foam::entry* Foam::dictionary::lookupEntryPtr
(
const word& keyword,
bool recursive, // false
bool patternMatch // true
)
{
HashTable<entry*>::iterator iter = hashedEntries_.find(keyword);

......

return iter();
}

The hashedEntries_ is defined as:

1
2
//- HashTable of the entries held on the DL-list for quick lookup
HashTable<entry*> hashedEntries_;

Here the find function defined in the HashTable is used:

1
2
3
//- Find and return an iterator set at the hashedEntry
// If not found iterator = end()
iterator find(const Key&);

The returned iter() call the operator() of class iterator which is a class defined in HashTable class.

1
2
3
4
5
6
template<class T, class Key, class Hash>
inline T&
Foam::HashTable<T, Key, Hash>::iterator::operator()()
{
return this->object();
}

The object function is defined inside the iterator class in HashTableI.H:

1
2
3
4
5
6
template<class T, class Key, class Hash>
inline T&
Foam::HashTable<T, Key, Hash>::iteratorBase::object()
{
return entryPtr_->obj_;
}

The entryPtr_ is an object with a type of hashedEntry*:

1
2
//- Current element
hashedEntry* entryPtr_;

The hashedEntry is a struct defined in HashTable class:

1
2
3
4
5
6
7
8
9
struct hashedEntry
{
......

//- The data object
T obj_;

......
};