Commit f2d8f636 authored by mattijs's avatar mattijs
Browse files

ENH: dictionary: added topDict() function

parent 28035714
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -222,6 +222,21 @@ Foam::dictionary::~dictionary()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::dictionary& Foam::dictionary::topDict() const
{
const dictionary& p = parent();
if (&p != this && !p.name().empty())
{
return p.topDict();
}
else
{
return p;
}
}
Foam::label Foam::dictionary::startLineNumber() const
{
if (size())
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -250,6 +250,9 @@ public:
return parent_;
}
//- Return the top of the tree
const dictionary& topDict() const;
//- Return line number of first token in dictionary
label startLineNumber() const;
......
......@@ -65,30 +65,12 @@ const Foam::word Foam::functionEntries::codeStream::codeTemplateC
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
const Foam::dictionary& Foam::functionEntries::codeStream::topDict
(
const dictionary& dict
)
{
const dictionary& p = dict.parent();
if (&p != &dict && !p.name().empty())
{
return topDict(p);
}
else
{
return dict;
}
}
Foam::dlLibraryTable& Foam::functionEntries::codeStream::libs
(
const dictionary& dict
)
{
const IOdictionary& d = static_cast<const IOdictionary&>(topDict(dict));
const IOdictionary& d = static_cast<const IOdictionary&>(dict.topDict());
return const_cast<Time&>(d.time()).libs();
}
......@@ -114,7 +96,7 @@ Foam::functionEntries::codeStream::getFunction
// see if library is loaded
void* lib = NULL;
if (isA<IOdictionary>(topDict(parentDict)))
if (isA<IOdictionary>(parentDict.topDict()))
{
lib = libs(parentDict).findLibrary(libPath);
}
......@@ -129,7 +111,7 @@ Foam::functionEntries::codeStream::getFunction
// avoid compilation if possible by loading an existing library
if (!lib)
{
if (isA<IOdictionary>(topDict(parentDict)))
if (isA<IOdictionary>(parentDict.topDict()))
{
// Cached access to dl libs. Guarantees clean up upon destruction
// of Time.
......@@ -267,7 +249,7 @@ Foam::functionEntries::codeStream::getFunction
}
}
if (isA<IOdictionary>(topDict(parentDict)))
if (isA<IOdictionary>(parentDict.topDict()))
{
// Cached access to dl libs. Guarantees clean up upon destruction
// of Time.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment