Loading...
Searching...
No Matches
instance_count.h
Go to the documentation of this file.
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2014 John Wellbelove
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_INSTANCE_COUNT_INCLUDED
#define ETL_INSTANCE_COUNT_INCLUDED
#include "platform.h"
#include <stdint.h>
namespace etl
{
//***************************************************************************
//***************************************************************************
template <typename T, typename TCounter = int32_t>
class instance_count
{
public:
typedef T type;
typedef TCounter counter_type;
//*************************************************************************
//*************************************************************************
instance_count()
{
++current_instance_count();
}
//*************************************************************************
//*************************************************************************
instance_count(const instance_count&)
{
++current_instance_count();
}
//*************************************************************************
//*************************************************************************
instance_count& operator=(const instance_count&)
{
return *this;
}
//*************************************************************************
//*************************************************************************
~instance_count()
{
--current_instance_count();
}
//*************************************************************************
//*************************************************************************
static const counter_type& get_instance_count()
{
return current_instance_count();
}
//*************************************************************************
//*************************************************************************
static void reset_instance_count()
{
current_instance_count() = 0;
}
private:
//*************************************************************************
//*************************************************************************
static counter_type& current_instance_count()
{
static counter_type counter = {0};
return counter;
}
};
} // namespace etl
#endif
etl::instance_count::operator=
instance_count & operator=(const instance_count &)
Assignment operator.
Definition instance_count.h:74
etl::instance_count::instance_count
instance_count(const instance_count &)
Copy construct and add 1.
Definition instance_count.h:66
etl::instance_count::reset_instance_count
static void reset_instance_count()
Get how many instances we have.
Definition instance_count.h:98
etl::instance_count::instance_count
instance_count()
Construct and add 1.
Definition instance_count.h:58
etl::instance_count::~instance_count
~instance_count()
Destruct and subtract 1.
Definition instance_count.h:82
etl::instance_count::get_instance_count
static const counter_type & get_instance_count()
Get how many instances we have.
Definition instance_count.h:90
etl
Definition absolute.h:40
platform.h