Panda3D

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
CountedResource Class Reference
Inheritance diagram for CountedResource:

## Public Member Functions
| __init__ (self)
| __del__ (self)
| acquire (cls)
| decrementCounter (cls)
| getCount (cls)
| incrementCounter (cls)
| release (cls)

## Public Attributes
int | RESOURCE_COUNTER = 1
bool | RESOURCE_COUNTER_INIT_FAILED = True

## Detailed Description

    This class is an attempt to combine the RAIA idiom with reference
    counting semantics in order to model shared resources. RAIA stands
    for "Resource Allocation Is Acquisition" (see 'Effective C++' for a
    more in-depth explanation)

    When a resource is needed, create an appropriate CountedResource
    object.  If the resource is already available (meaning another
    CountedResource object of the same type already exists), no action
    is taken.  Otherwise, acquire() is invoked, and the resource is
    allocated. The resource will remain valid until all matching
    CountedResource objects have been deleted.  When no objects of
    a particular CountedResource type exist, the release() function for
    that type is invoked and the managed resource is cleaned up.

    Usage:
        Define a subclass of CountedResource that defines the
        @classmethods acquire() and release().  In these two
        functions, define your resource allocation and cleanup code.

    IMPORTANT:
        If you define your own __init__ and __del__ methods, you
        MUST be sure to call down to the ones defined in
        CountedResource.

    Notes:
        Until we figure out a way to wrangle a bit more functionality
        out of Python, you MUST NOT inherit from any class that has
        CountedResource as its base class. In debug mode, this will
        raise a runtime assertion during the invalid class's call to
        __init__(). If you have more than one resource that you want to
        manage/access with a single object, you should subclass
        CountedResource again. See the example code at the bottom of
        this file to see how to accomplish this (This is useful for
        dependent resources).

## Constructor & Destructor Documentation

## ◆ __init__()

__init__ | ( |  | self | ) |

## ◆ __del__()

__del__ | ( |  | self | ) |

## Member Function Documentation

## ◆ acquire()

acquire | ( |  | cls | ) |

Reimplemented in CursorResource, InvalidResource, and MouseResource.

## ◆ decrementCounter()

decrementCounter | ( |  | cls | ) |

## ◆ getCount()

getCount | ( |  | cls | ) |

## ◆ incrementCounter()

incrementCounter | ( |  | cls | ) |

## ◆ release()

release | ( |  | cls | ) |

Reimplemented in CursorResource, InvalidResource, and MouseResource.

## Member Data Documentation

## ◆ RESOURCE_COUNTER

int RESOURCE_COUNTER = 1

## ◆ RESOURCE_COUNTER_INIT_FAILED

bool RESOURCE_COUNTER_INIT_FAILED = True