Can PhysFS use ifstreams?

840 Views Asked by At

I have a problem. I have lots of code that uses ifstreams in this manner:

ex:

bool AudioManager::_loadSounds( const std::string& path, const std::string& appendPath )
{
    //open the file
    std::ifstream ifs( path.c_str() );

    //ensure it is open
    if(!ifs.is_open())
    {
        return false;
    }

    std::string line;

    //read each sound
    while( getline( ifs, line ) )
    {

...

The problem is I need to make an application-wide change to use PhysFS. All data will stay structured the same directory wise except it will be compartmentalized into zip files.

Is there a simple way to make PhysFS apply to ifstreams so that I do not need to modify all these classes?

2

There are 2 best solutions below

0
On BEST ANSWER

There is not a simple way to do it. No matter what, you're going to have to not use fstreams. However, you can continue to use streams by simply writing a std::streambuf-derived class that pulls its data from PhysFS. This isn't a trivial thing, since streambuf has various bits of complexity to it. But it is certainly doable.

You can take any istream-derived class and shove a different streambuf into it.

0
On

PhysFS is a C library, and has no concept of C++ types. You will either need to find a C++ wrapper or write your own if you want to treat PhysFS handles as stream objects.