next up previous contents
Next: Bugs and Limitations Up: Scanning Pools in a Previous: The PoolScan Class

 

A Pool Scan Example

The following function counts the total number of objects in the indicated pool.

    int count(const char *pathname)
    {
        REF(any) ref;
        int count;

        // Open a scan over the pool given by `pathname.'
        PoolScan scan(pathname);

        // Make sure the scan was successfully opened.
        if(scan != RCOK){
            cout << "Error scanning pool " << pathname << ": "
                 << rc << endl;
            return 0;
        }

        // Scan until end-of-scan or an error is encountered.
        for(count = 0; scan.next(ref) == RCOK; ++count);

        // Check for errors
        if(scan.rc().err_num() != OC_EndOfScan){
            cout << "Error scanning pool " << pathname << ": "
                 << rc << endl;
            return 0;
        }

        cout << path << " has " << count << " objects." << endl;

        // The destructor will close the scan object.

        return count;
    }



Marvin Solomon
Fri Aug 2 13:39:13 CDT 1996