Slimelite BBS

containers that contain function pairs

Back to EMULATE

From Darin McBride · 1996-04-09 02:41 · #73667 in EMULATE

Perhaps after building a few of these classes I'll see some 'resemblance' and look into templating these ideas... :-)

Again, Chris, Jerry, Bob... the purpose here is not to make a complete class, but to enable me to forget about calling the 'free' function here.  One day I might look into a more 'full-featured' class that hides everything, but this was more to allow me a slower transition to full-fledged OOP design.  I thought it might give others some ideas... :-)

// the following class simplifies using the DIR* to run through the
// directory entries, including the automatic closing of the directory
// when the variable goes out of scope.
class Dir
{
    private:
        DIR* m_DIR;
        dirent* m_de;
    public:
        Dir(const char * pszPath) { m_DIR = opendir(pszPath); Next(); }
        ~Dir() { closedir(m_DIR); m_DIR = NULL; }

        operator DIR*() { return m_DIR; }
        operator !() const { return m_DIR == NULL; }
        dirent* Current() { return m_de; }
        dirent* Next() { m_de = readdir(m_DIR); return m_de; }
};



--- Maximus/2 3.01
 * Origin: Tanktalus' Tower BBS (PVT) (1:342/708)