ENH: dlLibraryTable InfoProxy output (#1735)

This commit is contained in:
Mark Olesen
2020-06-22 09:53:51 +02:00
parent 5b6969fce3
commit 8526e44884
3 changed files with 87 additions and 23 deletions

View File

@ -40,6 +40,9 @@ Usage
Success if any of the libraries can be loaded. Success if any of the libraries can be loaded.
Does not short-circuit. Does not short-circuit.
- \par -detail
Additional detail (meaning may change).
- \par -verbose - \par -verbose
Additional verbosity Additional verbosity
@ -71,6 +74,11 @@ int main(int argc, char *argv[])
"(does not short-circuit)" "(does not short-circuit)"
); );
argList::addBoolOption argList::addBoolOption
(
"detail",
"Additional detail"
);
argList::addBoolOption
( (
"verbose", "verbose",
"Additional verbosity" "Additional verbosity"
@ -85,6 +93,7 @@ int main(int argc, char *argv[])
#include "foamDlOpenLibs.H" #include "foamDlOpenLibs.H"
const bool testOr = args.found("or"); const bool testOr = args.found("or");
const bool detail = args.found("detail");
const bool verbose = args.found("verbose"); const bool verbose = args.found("verbose");
label ngood = 0; label ngood = 0;
@ -134,14 +143,12 @@ int main(int argc, char *argv[])
} }
} }
const bool okay if (detail)
( {
testOr InfoErr << libs.info();
? (ngood > 0 || nbad == 0) }
: nbad == 0
);
return okay ? 0 : 1; return (nbad == 0 || (testOr && ngood > 0)) ? 0 : 1;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2019 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -312,11 +312,13 @@ bool Foam::dlLibraryTable::close
return false; return false;
} }
void* ptr = libPtrs_[index];
DebugInFunction DebugInFunction
<< "Closing " << libName << "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; libPtrs_[index] = nullptr;
libNames_[index].clear(); 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;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2019 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -32,6 +32,7 @@ Description
SourceFiles SourceFiles
dlLibraryTable.C dlLibraryTable.C
dlLibraryTableTemplates.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -39,6 +40,7 @@ SourceFiles
#define dlLibraryTable_H #define dlLibraryTable_H
#include "DynamicList.H" #include "DynamicList.H"
#include "InfoProxy.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -64,26 +66,32 @@ class dlLibraryTable
// Warning messages, but no additional side-effects. // Warning messages, but no additional side-effects.
void* openLibrary(const fileName& libName, bool verbose); void* openLibrary(const fileName& libName, bool verbose);
//- No copy construct
dlLibraryTable(const dlLibraryTable&) = delete;
//- No copy assignment
void operator=(const dlLibraryTable&) = delete;
public: public:
// Declare name of the class and its debug switch // Declare name of the class and its debug switch
ClassName("dlLibraryTable"); ClassName("dlLibraryTable");
// Constructors // Generated Methods
//- Construct null //- Default construct
dlLibraryTable() = default; dlLibraryTable() = default;
//- No copy construct
dlLibraryTable(const dlLibraryTable&) = delete;
//- Move construct //- Move construct
dlLibraryTable(dlLibraryTable&&) = default; dlLibraryTable(dlLibraryTable&&) = default;
//- No copy assignment
void operator=(const dlLibraryTable&) = delete;
//- Move assignment
dlLibraryTable& operator=(dlLibraryTable&&) = default;
// Constructors
//- Open specified libraries. Ignores duplicate names. //- Open specified libraries. Ignores duplicate names.
explicit dlLibraryTable explicit dlLibraryTable
( (
@ -102,12 +110,24 @@ public:
// Member Functions // 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; bool empty() const;
//- The number of libraries loaded by the table //- The number of libraries loaded by the table
label size() const; 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. //- Clearing closes all libraries loaded by the table.
void clear(bool verbose = true); void clear(bool verbose = true);
@ -152,10 +172,14 @@ public:
); );
// Member Operators // Info
//- Move assignment //- Return info proxy.
dlLibraryTable& operator=(dlLibraryTable&&) = default; // Used to print library table information to a stream
InfoProxy<dlLibraryTable> info() const
{
return *this;
}
}; };