Sha256: 7a5c78e98434768855da29ffb19b5d3ce2c09787a28bc0833d4c9ec0ef534beb

Contents?: true

Size: 1.25 KB

Versions: 50

Compression:

Stored size: 1.25 KB

Contents

// Undocumented for the first few iterations. Interface may change rapidly.
// This is mainly a proof of concept. Stability will be the highest on OS X.

#ifndef GOSU_ASYNC_HPP
#define GOSU_ASYNC_HPP

#include <Gosu/Fwd.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <memory>
#include <string>

namespace Gosu
{
    template<typename Result>
    class AsyncResult
    {
        boost::shared_ptr<boost::try_mutex> mutex;
        boost::shared_ptr<std::auto_ptr<Result> > result;
        
    public:
        AsyncResult(const boost::shared_ptr<boost::try_mutex>& mutex,
                    const boost::shared_ptr<std::auto_ptr<Result> >& result)
        : mutex(mutex), result(result)
        {
        }
        
        bool hasValue() const
        {
            boost::try_mutex::scoped_try_lock lock(*mutex);
            return lock && result->get();
        }
        
        std::auto_ptr<Result> takeValue()
        {
            boost::try_mutex::scoped_lock lock(*mutex);
            return *result;
        }
    };
    
	// TODO: Will only work if the window doesn't die inbetween.
	// TODO: More functions to come; or a general interface?

	AsyncResult<Image>
		asyncNewImage(Window& window, const std::wstring& filename);
}

#endif

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
gosu-0.7.15 Gosu/Async.hpp
gosu-0.7.14 Gosu/Async.hpp
gosu-0.7.10.1 Gosu/Async.hpp
gosu-0.7.10.2 Gosu/Async.hpp
gosu-0.7.10.3 Gosu/Async.hpp
gosu-0.7.11 Gosu/Async.hpp
gosu-0.7.12 Gosu/Async.hpp
gosu-0.7.13.2 Gosu/Async.hpp
gosu-0.7.13.3 Gosu/Async.hpp
gosu-0.7.13 Gosu/Async.hpp