mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-16 00:46:03 +08:00
Removed singleton pattern
This commit is contained in:
parent
2ea9f69288
commit
bdcf26cde9
65
singleton.h
65
singleton.h
@ -1,65 +0,0 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_SINGLETON__
|
||||
#define __ETL_SINGLETON__
|
||||
|
||||
///\defgroup singleton singleton
|
||||
/// Templated version of the singleton pattern.
|
||||
///\ingroup etl
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//*************************************************************************
|
||||
/// Singleton pattern base class.
|
||||
/// \ingroup singleton
|
||||
//*************************************************************************
|
||||
template<typename T>
|
||||
class singleton
|
||||
{
|
||||
public:
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the instance.
|
||||
///\return A reference to the instance.
|
||||
//*************************************************************************
|
||||
static T &instance()
|
||||
{
|
||||
static T the_instance;
|
||||
return the_instance;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// Disabled.
|
||||
singleton(const singleton&);
|
||||
singleton& operator =(const singleton&);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,76 +0,0 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include "../singleton.h"
|
||||
|
||||
class Test_Class
|
||||
{
|
||||
public:
|
||||
|
||||
Test_Class()
|
||||
: i(0)
|
||||
{}
|
||||
|
||||
void Increment()
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
int i;
|
||||
};
|
||||
|
||||
typedef etl::singleton<Test_Class> Test_Singleton;
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_singleton)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test1)
|
||||
{
|
||||
Test_Class& ts = Test_Singleton::instance();
|
||||
|
||||
CHECK_EQUAL(0, ts.i);
|
||||
|
||||
ts.Increment();
|
||||
|
||||
CHECK_EQUAL(1, ts.i);
|
||||
|
||||
Test_Class* pts = &Test_Singleton::instance();
|
||||
|
||||
CHECK_EQUAL(1, ts.i);
|
||||
CHECK_EQUAL(1, pts->i);
|
||||
|
||||
pts->Increment();
|
||||
|
||||
CHECK_EQUAL(2, ts.i);
|
||||
CHECK_EQUAL(2, pts->i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user