CUGL 2.0
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
cugl::WidgetLoader Class Reference

#include <CUWidgetLoader.h>

Inheritance diagram for cugl::WidgetLoader:
cugl::Loader< WidgetValue > cugl::BaseLoader

Public Member Functions

 WidgetLoader ()
 
void dispose () override
 
- Public Member Functions inherited from cugl::Loader< WidgetValue >
 Loader ()
 
std::shared_ptr< WidgetValueget (const std::string &key) const
 
std::shared_ptr< WidgetValueget (const char *key) const
 
std::shared_ptr< WidgetValueoperator[] (const std::string &key) const
 
std::shared_ptr< WidgetValueoperator[] (const char *key) const
 
size_t loadCount () const override
 
size_t waitCount () const override
 
void unloadAll () override
 
- Public Member Functions inherited from cugl::BaseLoader
 BaseLoader ()
 
 ~BaseLoader ()
 
virtual bool init ()
 
virtual bool init (const std::shared_ptr< ThreadPool > &threads)
 
std::shared_ptr< BaseLoadergetHook ()
 
std::shared_ptr< ThreadPoolgetThreadPool () const
 
void setThreadPool (const std::shared_ptr< ThreadPool > &threads)
 
void setManager (AssetManager *manager)
 
const AssetManagergetManager () const
 
bool load (const std::string &key, const std::string &source)
 
bool load (const char *key, const std::string &source)
 
bool load (const std::string &key, const char *source)
 
bool load (const char *key, const char *source)
 
bool load (const std::shared_ptr< JsonValue > &json)
 
void loadAsync (const std::string &key, const std::string &source, LoaderCallback callback)
 
void loadAsync (const char *key, const std::string &source, LoaderCallback callback)
 
void loadAsync (const std::string &key, const char *source, LoaderCallback callback)
 
void loadAsync (const char *key, const char *source, LoaderCallback callback)
 
void loadAsync (const std::shared_ptr< JsonValue > &json, LoaderCallback callback)
 
bool unload (const std::string &key)
 
bool unload (const char *key)
 
bool unload (const std::shared_ptr< JsonValue > &json)
 
bool contains (const std::string &key) const
 
bool contains (const char *key) const
 
bool complete () const
 
float progress () const
 

Static Public Member Functions

static std::shared_ptr< WidgetLoaderalloc ()
 
static std::shared_ptr< WidgetLoaderalloc (const std::shared_ptr< ThreadPool > &threads)
 

Protected Member Functions

void materialize (const std::string &key, const std::shared_ptr< WidgetValue > &widget, LoaderCallback callback)
 
virtual bool read (const std::string &key, const std::string &source, LoaderCallback callback, bool async) override
 
virtual bool read (const std::shared_ptr< JsonValue > &json, LoaderCallback callback, bool async) override
 
- Protected Member Functions inherited from cugl::Loader< WidgetValue >
bool purge (const std::string &key) override
 
bool verify (const std::string &key) const override
 
- Protected Member Functions inherited from cugl::BaseLoader
virtual bool purge (const std::shared_ptr< JsonValue > &json)
 

Additional Inherited Members

- Protected Attributes inherited from cugl::Loader< WidgetValue >
std::unordered_map< std::string, std::shared_ptr< WidgetValue > > _assets
 
std::unordered_set< std::string > _queue
 
- Protected Attributes inherited from cugl::BaseLoader
std::shared_ptr< ThreadPool_loader
 
AssetManager_manager
 

Detailed Description

This class is a implementation of Loader<JsonValue>

This asset loader allows us to allocate json assets. It is essentially a wrapper around JsonReader that allows it to be used with an instance of AssetManager.

As with all of our loaders, this loader is designed to be attached to an asset manager. Use the method getHook() to get the appropriate pointer for attaching the loader.

Constructor & Destructor Documentation

◆ WidgetLoader()

cugl::WidgetLoader::WidgetLoader ( )
inline

Creates a new, uninitialized Json loader

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate a loader on the heap, use one of the static constructors instead.

Member Function Documentation

◆ alloc() [1/2]

static std::shared_ptr<WidgetLoader> cugl::WidgetLoader::alloc ( )
inlinestatic

Returns a newly allocated music loader.

This method bootstraps the loader with any initial resources that it needs to load assets.

This loader will have no associated threads. That means any asynchronous loading will fail until a thread is provided via setThreadPool.

Returns
a newly allocated Json loader.

◆ alloc() [2/2]

static std::shared_ptr<WidgetLoader> cugl::WidgetLoader::alloc ( const std::shared_ptr< ThreadPool > &  threads)
inlinestatic

Returns a newly allocated music loader.

This method bootstraps the loader with any initial resources that it needs to load assets.

This loader will have no associated threads. That means any asynchronous loading will fail until a thread is provided via setThreadPool.

Parameters
threadsThe thread pool for asynchronous loading
Returns
a newly allocated Json loader.

◆ dispose()

void cugl::WidgetLoader::dispose ( )
inlineoverridevirtual

Disposes all resources and assets of this loader

Any assets loaded by this object will be immediately released by the loader. However, a Json asset may still be available if referenced by another smart pointer.

Once the loader is disposed, any attempts to load a new asset will fail. You must reinitialize the loader to begin loading assets again.

Reimplemented from cugl::BaseLoader.

◆ materialize()

void cugl::WidgetLoader::materialize ( const std::string &  key,
const std::shared_ptr< WidgetValue > &  widget,
LoaderCallback  callback 
)
protected

Finishes loading the Json file, cleaning up the wait queues.

Allocating a Json asset can be done safely in a separate thread. Hence this method is really just an internal helper for convenience.

This method supports an optional callback function which reports whether the asset was successfully materialized.

Parameters
keyThe key to access the asset after loading
widgetThe json asset fully loaded
callbackAn optional callback for asynchronous loading

◆ read() [1/2]

virtual bool cugl::WidgetLoader::read ( const std::shared_ptr< JsonValue > &  json,
LoaderCallback  callback,
bool  async 
)
overrideprotectedvirtual

Internal method to support asset loading.

This method supports either synchronous or asynchronous loading, as specified by the given parameter. If the loading is asynchronous, the user may specify an optional callback function.

Json loading is always asynchronously safe, so this method does not split the loading process.

This version of read provides support for JSON directories. A json directory entry is just a key with a string value for the path to the asset.

Parameters
jsonThe directory entry for the asset
callbackAn optional callback for asynchronous loading
asyncWhether the asset was loaded asynchronously
Returns
true if the asset was successfully loaded

Reimplemented from cugl::BaseLoader.

◆ read() [2/2]

virtual bool cugl::WidgetLoader::read ( const std::string &  key,
const std::string &  source,
LoaderCallback  callback,
bool  async 
)
overrideprotectedvirtual

Internal method to support asset loading.

This method supports either synchronous or asynchronous loading, as specified by the given parameter. If the loading is asynchronous, the user may specify an optional callback function.

Json loading is always asynchronously safe, so this method does not split the loading process.

Parameters
keyThe key to access the asset after loading
sourceThe pathname to the asset
callbackAn optional callback for asynchronous loading
asyncWhether the asset was loaded asynchronously
Returns
true if the asset was successfully loaded

Reimplemented from cugl::BaseLoader.


The documentation for this class was generated from the following file: