Public Types | Public Member Functions | Static Public Member Functions

Fiber::OnDemandCreator< Computer > Class Template Reference

A Creator object that allows to create data on demand, when they are used and accessed. More...

#include <OnDemandCreator.hpp>

List of all members.

Public Types

Public Member Functions

Static Public Member Functions


Detailed Description

template<class Computer>
class Fiber::OnDemandCreator< Computer >

A Creator object that allows to create data on demand, when they are used and accessed.

For instance, some Field may be defined on a Grid whose values are computed once the Field is accessed. Providing such an On-Demand-Field does neither require computational nor memory resources.

The computational logic is put in the template argument Computer. It must

  1. provide an type ResultArray_t, which is derived from a MemBase; the type ResultArray_t must define a type value_type which will be used as the value type of this Creator.
  2. provide a type Constructor_t, which is used to communicate data from the Creator to the actual Computer object. The Computer object is create dynamically with a copy of the data provided at the constructor of the OnDemandCreator.
  3. provide a constructor that takes one argument of type Constructor_t .
  4. provide a member function result() which returns a type that is convertible to RefPtr<MemBase>
struct  Compute
{
        typedef MemArray<1, double>  ResultArray_t;
        typedef index_t              Constructor_t;

        RefPtr<ResultArray_t>        result_storage;

        Compute(index_t howmany, const MemBase::Creator_t&C)
        {
                result_storage = new ResultArray_t(howmany, C);
        }

        RefPtr<ResultArray_t> result() const
        {
                return result_storage;
        }
};

RefPtr<CreativeArrayBase> cab = new OnDemandCreator<Compute>(123);

Member Enumeration Documentation

template<class Computer >
anonymous enum
Enumerator:
RANK 

The dimensionality of the data set.