mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-02 14:04:22 +00:00
Split Base into LeanBase and Base.
Build not tested - intermediate commit.
This commit is contained in:
parent
d579b311f2
commit
c64e572fc8
2 changed files with 85 additions and 16 deletions
|
@ -18,49 +18,51 @@
|
||||||
#ifndef idCB253C1A5AFA46A18B8878ED4072CD96
|
#ifndef idCB253C1A5AFA46A18B8878ED4072CD96
|
||||||
#define idCB253C1A5AFA46A18B8878ED4072CD96
|
#define idCB253C1A5AFA46A18B8878ED4072CD96
|
||||||
|
|
||||||
|
#include "dindexer-machinery/scantask/leanbase.hpp"
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace mchlib {
|
namespace mchlib {
|
||||||
namespace scantask {
|
namespace scantask {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Base {
|
class Base : public LeanBase<T> {
|
||||||
protected:
|
protected:
|
||||||
Base ( void );
|
Base ( void );
|
||||||
virtual ~Base ( void ) noexcept = default;
|
virtual ~Base ( void ) noexcept = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T& get_or_create ( void );
|
|
||||||
void clear_data ( void );
|
void clear_data ( void );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void on_data_destroy ( T& parData ) = 0;
|
virtual void on_data_destroy ( T& parData ) = 0;
|
||||||
virtual void on_data_create ( T& parData ) = 0;
|
virtual void on_data_create ( T& parData ) = 0;
|
||||||
|
|
||||||
|
virtual T& on_data_get ( void ) final;
|
||||||
|
virtual void on_data_fill ( void ) final;
|
||||||
|
|
||||||
|
using LeanBase<T>::unset_data_created;
|
||||||
|
|
||||||
T m_data;
|
T m_data;
|
||||||
bool m_data_created;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Base<T>::Base() :
|
Base<T>::Base() {
|
||||||
m_data_created(false)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T& Base<T>::get_or_create() {
|
void Base<T>::on_data_fill() {
|
||||||
if (not m_data_created) {
|
this->on_data_create(m_data);
|
||||||
m_data_created = true;
|
|
||||||
this->on_data_create(m_data);
|
|
||||||
}
|
|
||||||
return m_data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Base<T>::clear_data() {
|
void Base<T>::clear_data() {
|
||||||
if (m_data_created) {
|
this->unset_data_created();
|
||||||
m_data_created = false;
|
this->on_data_destroy(m_data);
|
||||||
this->on_data_destroy(m_data);
|
}
|
||||||
}
|
|
||||||
|
template <typename T>
|
||||||
|
T& Base<T>::on_data_get() {
|
||||||
|
return m_data;
|
||||||
}
|
}
|
||||||
} //namespace scantask
|
} //namespace scantask
|
||||||
} //namespace mchlib
|
} //namespace mchlib
|
||||||
|
|
67
include/dindexer-machinery/scantask/leanbase.hpp
Normal file
67
include/dindexer-machinery/scantask/leanbase.hpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/* Copyright 2015, 2016, Michele Santullo
|
||||||
|
* This file is part of "dindexer".
|
||||||
|
*
|
||||||
|
* "dindexer" is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* "dindexer" is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef id982AF1D5C59C415584F56C1E6DDFE55E
|
||||||
|
#define id982AF1D5C59C415584F56C1E6DDFE55E
|
||||||
|
|
||||||
|
#include <ciso646>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
namespace mchlib {
|
||||||
|
namespace scantask {
|
||||||
|
template <typename T>
|
||||||
|
class LeanBase {
|
||||||
|
protected:
|
||||||
|
LeanBase ( void );
|
||||||
|
virtual ~LeanBase ( void ) noexcept = default;
|
||||||
|
|
||||||
|
void unset_data_created ( void );
|
||||||
|
|
||||||
|
public:
|
||||||
|
T& get_or_create ( void );
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void on_data_fill ( void ) = 0;
|
||||||
|
virtual T& on_data_get ( void ) = 0;
|
||||||
|
|
||||||
|
bool m_data_created;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
LeanBase<T>::LeanBase() :
|
||||||
|
m_data_created(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T& LeanBase<T>::get_or_create() {
|
||||||
|
if (not m_data_created) {
|
||||||
|
m_data_created = true;
|
||||||
|
this->on_data_fill();
|
||||||
|
}
|
||||||
|
return this->on_data_get();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void LeanBase<T>::unset_data_created() {
|
||||||
|
assert(m_data_created);
|
||||||
|
m_data_created = false;
|
||||||
|
}
|
||||||
|
} //namespace scantask
|
||||||
|
} //namespace mchlib
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue