diff --git a/applications/test/HashPtrTable/Test-HashPtrTable.cxx b/applications/test/HashPtrTable/Test-HashPtrTable.cxx index cd4b81184f..c2bb47012e 100644 --- a/applications/test/HashPtrTable/Test-HashPtrTable.cxx +++ b/applications/test/HashPtrTable/Test-HashPtrTable.cxx @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,33 +42,55 @@ Description using namespace Foam; -class Scalar +bool verbosity = true; + +// Gratuitous class inheritance +template +class BoxedType { - scalar data_; + T data_; public: static bool verbose; - constexpr Scalar() noexcept : data_(0) {} - Scalar(scalar val) noexcept : data_(val) {} + constexpr BoxedType() noexcept : data_(0) {} + BoxedType(T val) noexcept : data_(val) {} + + ~BoxedType() + { + if (verbosity) Info<< " [delete BoxedType: " << value() << ']' << nl; + } + + T value() const noexcept { return data_; } + T& value() noexcept { return data_; } + + auto clone() const { return autoPtr>::New(*this); } +}; + +template Ostream& operator<<(Ostream& os, const BoxedType& item) +{ + return (os << " -> " << item.value()); +} + + +class Scalar : public BoxedType +{ +public: + + using BoxedType::BoxedType; ~Scalar() { - if (verbose) Info<< "delete Scalar: " << data_ << endl; - } - - const scalar& value() const noexcept { return data_; } - scalar& value() noexcept { return data_; } - - friend Ostream& operator<<(Ostream& os, const Scalar& item) - { - os << item.value(); - return os; + if (verbosity) Info<< "delete Scalar: " << value() << nl; } + auto clone() const { return autoPtr::New(*this); } }; -bool Scalar::verbose = true; +Ostream& operator<<(Ostream& os, const Scalar& item) +{ + return (os << item.value()); +} template diff --git a/applications/test/ISLList/Make/files b/applications/test/ISLList/Make/files index ceb5fc148f..26f3e12d5f 100644 --- a/applications/test/ISLList/Make/files +++ b/applications/test/ISLList/Make/files @@ -1,3 +1,3 @@ -Test-ISLList.C +Test-ISLList.cxx EXE = $(FOAM_USER_APPBIN)/Test-ISLList diff --git a/applications/test/ISLList/Test-ISLList.C b/applications/test/ISLList/Test-ISLList.cxx similarity index 100% rename from applications/test/ISLList/Test-ISLList.C rename to applications/test/ISLList/Test-ISLList.cxx diff --git a/applications/test/PtrDictionary1/Make/files b/applications/test/PtrDictionary1/Make/files index 9ced445619..c21cc1053a 100644 --- a/applications/test/PtrDictionary1/Make/files +++ b/applications/test/PtrDictionary1/Make/files @@ -1,3 +1,3 @@ -Test-PtrDictionary1.C +Test-PtrDictionary1.cxx EXE = $(FOAM_USER_APPBIN)/Test-PtrDictionary1 diff --git a/applications/test/PtrDictionary1/Test-PtrDictionary1.C b/applications/test/PtrDictionary1/Test-PtrDictionary1.cxx similarity index 97% rename from applications/test/PtrDictionary1/Test-PtrDictionary1.C rename to applications/test/PtrDictionary1/Test-PtrDictionary1.cxx index 3f407568bc..c9bedb58e9 100644 --- a/applications/test/PtrDictionary1/Test-PtrDictionary1.C +++ b/applications/test/PtrDictionary1/Test-PtrDictionary1.cxx @@ -42,6 +42,8 @@ Description using namespace Foam; +bool verbosity = true; + class ent : public Dictionary::link @@ -73,14 +75,12 @@ class Scalar public: - static bool verbose; - constexpr Scalar() noexcept : data_(0) {} Scalar(scalar val) noexcept : data_(val) {} ~Scalar() { - if (verbose) Info<< "delete Scalar: " << data_ << endl; + if (verbosity) Info<< "delete Scalar: " << data_ << endl; } scalar value() const noexcept { return data_; } @@ -93,8 +93,6 @@ public: } }; -bool Scalar::verbose = true; - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: diff --git a/applications/test/PtrList/Test-PtrList.cxx b/applications/test/PtrList/Test-PtrList.cxx index 88c8cfbffe..17f72460c7 100644 --- a/applications/test/PtrList/Test-PtrList.cxx +++ b/applications/test/PtrList/Test-PtrList.cxx @@ -41,35 +41,85 @@ Description using namespace Foam; -class Scalar +bool verbosity = true; + +// Gratuitous class inheritance +template +class BoxedType { - scalar data_; + T data_; public: static bool verbose; - constexpr Scalar() noexcept : data_(0) {} - Scalar(scalar val) noexcept : data_(val) {} + constexpr BoxedType() noexcept : data_(0) {} + BoxedType(T val) noexcept : data_(val) {} + + ~BoxedType() + { + if (verbosity) Info<< " [delete BoxedType: " << value() << ']' << nl; + } + + T value() const noexcept { return data_; } + T& value() noexcept { return data_; } + + auto clone() const { return autoPtr>::New(*this); } +}; + +template Ostream& operator<<(Ostream& os, const BoxedType& item) +{ + return (os << " -> " << item.value()); +} + + +class Scalar : public BoxedType +{ +public: + + using BoxedType::BoxedType; ~Scalar() { - if (verbose) Info<< "delete Scalar: " << data_ << endl; - } - - scalar value() const noexcept { return data_; } - scalar& value() noexcept { return data_; } - - autoPtr clone() const { return autoPtr::New(data_); } - - friend Ostream& operator<<(Ostream& os, const Scalar& item) - { - os << item.value(); - return os; + if (verbosity) Info<< "delete Scalar: " << value() << nl; } + auto clone() const { return autoPtr::New(*this); } }; -bool Scalar::verbose = true; +Ostream& operator<<(Ostream& os, const Scalar& item) +{ + return (os << item.value()); +} + + +class Integer : public BoxedType