Click here to Skip to main content
15,885,141 members
Articles / Desktop Programming / MFC

Portable thread-based garbage collection library, for C++

Rate me:
Please Sign up or sign in to vote.
4.47/5 (6 votes)
19 May 20065 min read 31.2K   331   21  
a description of LibGC, a portable thread-based garbage collection library for C++
#ifndef LIBGC_BASICPTR_HPP
#define LIBGC_BASICPTR_HPP


#include "libgc/garbage_collector.hpp"
#include "libgc/object.hpp"


namespace libgc {


/** base class for all pointer classes.
 */
class basic_ptr : public gc_ptr {
protected:    
    /** the default constructor.
     */ 
    basic_ptr() {
    }
    
    /** constructor from value.
        @param val initial value
     */ 
    basic_ptr(void *val) : gc_ptr(val) {
    }
    
    /** the copy constructor.
        @param obj source object.
     */
    basic_ptr(const basic_ptr &obj) : gc_ptr(obj) {
    }     
    
    /** the destructor.
     */
    ~basic_ptr() {
    }   
    
    /** the assignment operator.
        @param obj source object.
        @return reference to this.
     */  
    basic_ptr &operator = (const basic_ptr &obj) {
        gc_ptr::operator = (obj);
        return *this;
    }     
    
    /** pushes a root pointer to the garbage collector.
        @param ptr pointer to push to the collector.
     */
    static void collector_push_ptr(basic_ptr &ptr) {
        garbage_collector::get_garbage_collector().push_ptr(ptr);
    }
    
    /** pops a root pointer from the garbage collector.
     */
    static void collector_pop_ptr() {
        garbage_collector::get_garbage_collector().pop_ptr();
    }    
    
    /** pushes a weak root pointer to the garbage collector.
        @param ptr pointer to push to the collector.
     */
    static void collector_push_weak_ptr(basic_ptr &ptr) {
        garbage_collector::get_garbage_collector().push_weak_ptr(ptr);
    }
    
    /** pops a weak root pointer from the garbage collector.
     */
    static void collector_pop_weak_ptr() {
        garbage_collector::get_garbage_collector().pop_weak_ptr();
    }    
    
    /** adds a member pointer to the given object.
        @param obj object to add the pointer to.
        @param ptr pointer to add.
     */
    static void add_member_ptr(object *obj, basic_ptr &ptr) {
        object::add_member_ptr(obj, ptr);
    }
    
    /** adds a weak member pointer to the given object.
        @param obj object to add the pointer to.
        @param ptr pointer to add.
     */
    static void add_weak_member_ptr(object *obj, basic_ptr &ptr) {
        object::add_weak_member_ptr(obj, ptr);
    }
}; 


} //namespace libgc


#endif //LIBGC_BASICPTR_HPP

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions