containers.lazyarray - ICE 0.1 API documentation

ICE 0.1 API documentation

# containers.lazyarray

Array that lazily loads items. Used for resource management.

struct LazyArrayIndex(T,ID = string);

  Index to a LazyArray. ID specifies type of resource identifier.

  Note:
  DO NOT change alignment here as it causes a gc bug that garbage collects the id_ string even if it's still used.

  ID id_;

    Identifier of the resource. This is cleared after the resource is loaded.

  uint index_;

    Index of the resource in the LazyArray once loaded (uint.max when not loaded).

  const pure nothrow bool loaded(ref const LazyArray!(T,ID) array);

    Is the resource loaded?

  pure nothrow this(ID id);

    Construct a LazyArrayIndex_ pointing to resource with specified identifier.

  const pure nothrow @safe string toString();

    Get a string representation of the ID

    (only works if the resource has not been loaded.)

  void index(const uint rhs);

    Set the index once the resource is loaded.

  const pure nothrow const(ID) id(ref const LazyArray!(T,ID) array);

    Get the resource identitifer.

  pure nothrow ID idNonConst(ref const LazyArray!(T,ID) array);

    Get the resource identitifer (non-const version).

struct LazyArray(T,ID = string);

  Array that lazily loads items. Used for resource management.

  LazyArray uses special indices (LazyArrayIndex_), which contain resource identifiers. When we ask for an element from LazyArray by indexing with this index, it checks if the element is loaded.
  If it's loaded, it returns a pointer to it.
  If it's not loaded, it loads and stores it (using a user-provided delegate), and returns a pointer to it. If the resource could not be loaded, it returns null.
  The LazyArrayIndex_ indices are always updated to point to the loaded resource based on the resource ID.
  LazyArray cannot be copied for simplicity of implementation.

  struct Item;

    Item with a resource ID.

  Vector!(Item,BufferSwappingAllocator!(Item,8)) storage_;

    Allocated storage.

  bool delegate(ID, out T) loadData_;

    Delegate used to load data if it's requested and not loaded yet.

  T* opIndex(ref LazyArrayIndex!(T,ID) index);

    Get the item at specified index, loading it if needed. Returns null on failure.

  int opApply(int delegate(ref T) dg);

    Used by foreach.

    Foreach will iterate over all elements of the array in linear order from start to end.

  pure nothrow void loaderDelegate(bool delegate(ID, out T) rhs);

    Set the delegate used to load elements.

    The delegate must take a resource ID and an output argument to write the loaded element to. It must return true if the element was loaded successfully and false otherwise.
    The loader delegate should take the resource ID, load the resource based on it and write it to output. It should never throw, although it's not forced to be nothrow for practicality reasons.

Copyright © Ferdinand Majerech 2011. | Page generated by AutoDDoc and Ddoc.