2020-09-06 19:01:12 +01:00
|
|
|
#ifndef VOXEL_VIEWER_REF_COUNT_H
|
|
|
|
#define VOXEL_VIEWER_REF_COUNT_H
|
|
|
|
|
2022-04-14 21:22:22 +01:00
|
|
|
#include "errors.h"
|
2021-12-13 21:38:10 +00:00
|
|
|
|
2022-01-31 21:29:08 +00:00
|
|
|
namespace zylann {
|
|
|
|
|
|
|
|
// Simple reference counter.
|
|
|
|
// This one is not thread-safe.
|
|
|
|
class RefCount {
|
2020-09-06 19:01:12 +01:00
|
|
|
public:
|
2021-04-15 20:16:27 +01:00
|
|
|
inline void add() {
|
|
|
|
++_count;
|
2020-09-06 19:01:12 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 20:16:27 +01:00
|
|
|
inline void remove() {
|
2022-04-14 21:22:22 +01:00
|
|
|
ZN_ASSERT_RETURN_MSG(_count != 0, "Trying to decrease refcount when it's already zero");
|
2021-04-15 20:16:27 +01:00
|
|
|
--_count;
|
2020-09-06 19:01:12 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 20:16:27 +01:00
|
|
|
inline unsigned int get() const {
|
|
|
|
return _count;
|
2020-09-06 19:01:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-04-15 20:16:27 +01:00
|
|
|
unsigned int _count = 0;
|
2020-09-06 19:01:12 +01:00
|
|
|
};
|
|
|
|
|
2022-01-31 21:29:08 +00:00
|
|
|
} // namespace zylann
|
|
|
|
|
2020-09-06 19:01:12 +01:00
|
|
|
#endif // VOXEL_VIEWER_REF_COUNT_H
|