next up previous contents
Next: Bugs and Limitations Up: Scanning Pools in a Application 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;
    }
A complete program using code similar to this may be found in the directory examples/pscan in the documentation distribution. See the instructions for Compiling and Running an Application in the Shore Software Installation Manual .



This page was generated from LaTeX sources
10/27/1997