Files
poco/Foundation/include/Poco/SingletonHolder.h
Matej Kenda 8a4a2955d5 Use nullptr in C++ code (solves #4348) (#5043)
* chore(CppParser): 0, NULL --> nullptr

* chore(Crypto): 0, NULL --> nullptr

* chore(DNSSD): 0, NULL --> nullptr

* chore(Encodings): 0, NULL --> nullptr

* chore(CppUnit): Correct indentation.

* chore(Foundation): 0, NULL --> nullptr

* chore(CMake): Always warn about wrong nullptr usage when compiling with GCC or CLang

* chore(Net): 0, NULL --> nullptr

* chore(Foundation): 0, NULL --> nullptr

* chore(Data): 0, NULL --> nullptr

* chore(macOS): 0, NULL --> nullptr

* chore(XML): 0, NULL --> nullptr

* chore(Zip): 0, NULL --> nullptr

* chore(Util): 0, NULL --> nullptr

* chore(Net/NetSSL): 0, NULL --> nullptr

* chore(Bonjour): 0, NULL --> nullptr

* chore(MongoDB, Redis): 0, NULL --> nullptr

* chore(Poco): 0, NULL --> nullptr

* chore(Win32): 0, NULL --> nullptr

* chore(CMake): Only warn about nullptr when verbose warnings are enabled.

* Potential fix for code scanning alert no. 1634: Guarded Free

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* chore(Net): Fix warning reported by gitlab.

* chore(gitlab CI): attempt to clean to gain disk space on the runner.

* chore(gitlab CI): Run build with  --parallel 4, correct docker cleanup.

---------

Co-authored-by: Aleksandar Fabijanic <aleks-f@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2025-10-30 15:20:53 +01:00

78 lines
1.4 KiB
C++

//
// SingletonHolder.h
//
// Library: Foundation
// Package: Core
// Module: SingletonHolder
//
// Definition of the SingletonHolder template.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Foundation_SingletonHolder_INCLUDED
#define Foundation_SingletonHolder_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/Mutex.h"
namespace Poco {
template <class S>
class SingletonHolder
/// This is a helper template class for managing
/// singleton objects allocated on the heap.
/// The class ensures proper deletion (including
/// calling of the destructor) of singleton objects
/// when the application that created them terminates.
{
public:
SingletonHolder():
_pS(nullptr)
/// Creates the SingletonHolder.
{
}
~SingletonHolder()
/// Destroys the SingletonHolder and the singleton
/// object that it holds.
{
delete _pS;
}
S* get()
/// Returns a pointer to the singleton object
/// hold by the SingletonHolder. The first call
/// to get will create the singleton.
{
FastMutex::ScopedLock lock(_m);
if (!_pS) _pS = new S;
return _pS;
}
void reset()
/// Deletes the singleton object.
{
FastMutex::ScopedLock lock(_m);
delete _pS;
_pS = 0;
}
private:
S* _pS;
FastMutex _m;
};
} // namespace Poco
#endif // Foundation_SingletonHolder_INCLUDED