Commit 8526e448 authored by Mark Olesen's avatar Mark Olesen

ENH: dlLibraryTable InfoProxy output (#1735)

parent 5b6969fc
......@@ -40,6 +40,9 @@ Usage
Success if any of the libraries can be loaded.
Does not short-circuit.
- \par -detail
Additional detail (meaning may change).
- \par -verbose
Additional verbosity
......@@ -71,6 +74,11 @@ int main(int argc, char *argv[])
"(does not short-circuit)"
);
argList::addBoolOption
(
"detail",
"Additional detail"
);
argList::addBoolOption
(
"verbose",
"Additional verbosity"
......@@ -85,6 +93,7 @@ int main(int argc, char *argv[])
#include "foamDlOpenLibs.H"
const bool testOr = args.found("or");
const bool detail = args.found("detail");
const bool verbose = args.found("verbose");
label ngood = 0;
......@@ -134,14 +143,12 @@ int main(int argc, char *argv[])
}
}
const bool okay
(
testOr
? (ngood > 0 || nbad == 0)
: nbad == 0
);
if (detail)
{
InfoErr << libs.info();
}
return okay ? 0 : 1;
return (nbad == 0 || (testOr && ngood > 0)) ? 0 : 1;
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -312,11 +312,13 @@ bool Foam::dlLibraryTable::close
return false;
}
void* ptr = libPtrs_[index];
DebugInFunction
<< "Closing " << libName
<< " with handle " << Foam::name(libPtrs_[index]) << nl;
<< " with handle " << Foam::name(ptr) << nl;
const bool ok = Foam::dlClose(libPtrs_[index]);
const bool ok = Foam::dlClose(ptr);
libPtrs_[index] = nullptr;
libNames_[index].clear();
......@@ -367,4 +369,35 @@ bool Foam::dlLibraryTable::open
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const InfoProxy<dlLibraryTable>& ip
)
{
const dlLibraryTable& tbl = ip.t_;
os << token::BEGIN_LIST << nl;
// Lengths of pointers/names are guaranteed interally to be identical
forAll(tbl.pointers(), i)
{
const void* ptr = tbl.pointers()[i];
const fileName& libName = tbl.names()[i];
// Also write out empty filenames
// (specified with '-lib' but did not load)
os << Foam::name(ptr) << token::SPACE << libName << nl;
}
os << token::END_LIST << nl;
return os;
}
// ************************************************************************* //
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -32,6 +32,7 @@ Description
SourceFiles
dlLibraryTable.C
dlLibraryTableTemplates.C
\*---------------------------------------------------------------------------*/
......@@ -39,6 +40,7 @@ SourceFiles
#define dlLibraryTable_H
#include "DynamicList.H"
#include "InfoProxy.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -64,26 +66,32 @@ class dlLibraryTable
// Warning messages, but no additional side-effects.
void* openLibrary(const fileName& libName, bool verbose);
//- No copy construct
dlLibraryTable(const dlLibraryTable&) = delete;
//- No copy assignment
void operator=(const dlLibraryTable&) = delete;
public:
// Declare name of the class and its debug switch
ClassName("dlLibraryTable");
// Constructors
// Generated Methods
//- Construct null
//- Default construct
dlLibraryTable() = default;
//- No copy construct
dlLibraryTable(const dlLibraryTable&) = delete;
//- Move construct
dlLibraryTable(dlLibraryTable&&) = default;
//- No copy assignment
void operator=(const dlLibraryTable&) = delete;
//- Move assignment
dlLibraryTable& operator=(dlLibraryTable&&) = default;
// Constructors
//- Open specified libraries. Ignores duplicate names.
explicit dlLibraryTable
(
......@@ -102,12 +110,24 @@ public:
// Member Functions
//- True if no there are no libraries loaded by the table
//- True if there are no libraries loaded by the table
bool empty() const;
//- The number of libraries loaded by the table
label size() const;
//- Names of the libraries in use, or requested
const UList<fileName>& names() const
{
return libNames_;
}
//- Pointers to the libraries in use. Access with caution.
const UList<void*>& pointers() const
{
return libPtrs_;
}
//- Clearing closes all libraries loaded by the table.
void clear(bool verbose = true);
......@@ -152,10 +172,14 @@ public:
);
// Member Operators
// Info
//- Move assignment
dlLibraryTable& operator=(dlLibraryTable&&) = default;
//- Return info proxy.
// Used to print library table information to a stream
InfoProxy<dlLibraryTable> info() const
{
return *this;
}
};
......
Markdown is supported
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