Counter.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <mutex>
9 // define type : uintXX_t and intXX_t
10 #define __STDC_LIMIT_MACROS
11 // note in android include the macro of min max are overwitten
12 #include <cstdint>
13 
14 namespace ememory {
18  class Counter {
19  public:
23  enum class remove {
24  none,
25  data,
26  counter,
27  all
28  };
29  private:
30  int64_t m_counterShared;
31  int64_t m_counterWeak;
32  mutable std::mutex m_mutex;
33  public:
38  Counter(bool _fromWeak=false);
42  ~Counter();
48  int64_t incrementShared(bool _fromWeak=false);
58  int64_t incrementWeak();
68  int64_t getCountWeak() const;
73  int64_t getCountShared() const;
78  int64_t getCount() const;
79  };
80 }
81 
Remove only the Counter (data already removed)
int64_t incrementShared(bool _fromWeak=false)
Increment the shared counter (one more shared user)
int64_t incrementWeak()
Increment the weak counter (one more weak user)
int64_t getCount() const
Get the number of weak+shared counter.
Remove only the data.
Couter is an important part of the SharedPtr/WeakPtr implementation. This use a simple refcounting me...
Definition: Counter.hpp:18
int64_t getCountWeak() const
Get the number of weak counter.
ememory::Counter::remove decrementWeak()
Decrese of 1 the weak counter.
Counter(bool _fromWeak=false)
Contructor.
Ememory is a namespace to represent the.
Definition: Counter.hpp:14
ememory::Counter::remove decrementShared()
Decrese of 1 the shared counter.
remove
Remove case of the counter. When decrese the shared our weak counter, it is the upper class that need...
Definition: Counter.hpp:23
~Counter()
Destrunctor (Not virtual !!)
Remove Data and Counter.
int64_t getCountShared() const
Get the number of shared counter.