The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
reference_counted_object.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef REFERENCE_COUNTED_OBJECT_HPP_INCLUDED
16 #define REFERENCE_COUNTED_OBJECT_HPP_INCLUDED
17 
18 #include <boost/intrusive_ptr.hpp>
19 
21 {
22 public:
26  return *this;
27  }
29 
30  void add_ref() const { ++count_; }
31  void dec_ref() const { if(--count_ == 0) { delete const_cast<reference_counted_object*>(this); } }
32 
33  int refcount() const { return count_; }
34 
35 protected:
36  void turn_reference_counting_off() const { count_ = 1000000; }
37 private:
38  mutable int count_;
39 };
40 
42  obj->add_ref();
43 }
44 
46  obj->dec_ref();
47 }
48 
51 
52 #endif
reference_counted_object(const reference_counted_object &)
boost::intrusive_ptr< reference_counted_object > object_ptr
GLhandleARB obj
Definition: glew.h:4486
void intrusive_ptr_add_ref(const reference_counted_object *obj)
reference_counted_object & operator=(const reference_counted_object &)
boost::intrusive_ptr< const reference_counted_object > const_object_ptr
void intrusive_ptr_release(const reference_counted_object *obj)