MADNESS  version 0.9
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
madness::Future< T > Class Template Reference

A future is a possibly yet unevaluated value. More...

#include <ref.h>

Public Types

typedef RemoteReference
< FutureImpl< T > > 
remote_refT
 

Public Member Functions

 Future ()
 Makes an unassigned future. More...
 
 Future (const T &t)
 Makes an assigned future. More...
 
 Future (const remote_refT &remote_ref)
 Makes a future wrapping a remote reference. More...
 
 Future (const archive::BufferInputArchive &input_arch)
 Makes an assigned future from an input archive. More...
 
 Future (const Future< T > &other)
 Copy constructor is shallow. More...
 
 ~Future ()
 
bool is_default_initialized () const
 Default initialized query. More...
 
Future< T > & operator= (const Future< T > &other)
 Assignment future = future makes a shallow copy just like copy constructor. More...
 
void set (const Future< T > &other)
 A.set(B) where A & B are futures ensures A has/will have the same value as B. More...
 
void set (const T &value)
 Assigns the value ... it can only be set ONCE. More...
 
void set (const archive::BufferInputArchive &input_arch)
 Assigns the value ... it can only be set ONCE. More...
 
T & get ()
 Gets the value, waiting if necessary (error if not a local future) More...
 
const T & get () const
 Gets the value, waiting if necessary (error if not a local future) More...
 
bool probe () const
 Query the whether this future has been assigned. More...
 
 operator T & ()
 Same as get() More...
 
 operator const T & () const
 Same as get() const. More...
 
remote_refT remote_ref (World &world) const
 Returns a structure used to pass references to another process. More...
 
bool is_local () const
 
bool is_remote () const
 
void register_callback (CallbackInterface *callback)
 Registers an object to be called when future is assigned. More...
 

Static Public Member Functions

static const Future< T > default_initializer ()
 See Gotchas on the documentation mainpage about why this exists and how to use it. More...
 

Friends

std::ostream & operator (std::ostream &out, const Future< T > &f)
 

Detailed Description

template<typename T>
class madness::Future< T >

A future is a possibly yet unevaluated value.

Uses delegation to FutureImpl to provide desired copy/assignment semantics as well as safe reference counting for remote futures.

Since we are using Futures a lot to store local values coming from containers and inside task wrappers for messages, we included in this class a value. If a future is assigned before a copy/remote-reference is taken, the shared ptr is never made. The point of this is to eliminate the two mallocs that must be peformed for every new shared_ptr.

Member Typedef Documentation

template<typename T>
typedef RemoteReference< FutureImpl<T> > madness::Future< T >::remote_refT

Constructor & Destructor Documentation

template<typename T>
madness::Future< T >::Future ( )
inline

Makes an unassigned future.

template<typename T>
madness::Future< T >::Future ( const T &  t)
inlineexplicit

Makes an assigned future.

template<typename T>
madness::Future< T >::Future ( const remote_refT remote_ref)
inlineexplicit

Makes a future wrapping a remote reference.

template<typename T>
madness::Future< T >::Future ( const archive::BufferInputArchive input_arch)
inlineexplicit

Makes an assigned future from an input archive.

template<typename T>
madness::Future< T >::Future ( const Future< T > &  other)
inline

Copy constructor is shallow.

template<typename T>
madness::Future< T >::~Future ( )
inline

Member Function Documentation

template<typename T>
static const Future<T> madness::Future< T >::default_initializer ( )
inlinestatic

See Gotchas on the documentation mainpage about why this exists and how to use it.

Referenced by madness::future_vector_factory().

template<typename T>
T& madness::Future< T >::get ( )
inline
template<typename T>
const T& madness::Future< T >::get ( ) const
inline

Gets the value, waiting if necessary (error if not a local future)

template<typename T>
bool madness::Future< T >::is_default_initialized ( ) const
inline

Default initialized query.

Returns
true if this future was constructed with default_initializer(), otherwise false.
template<typename T>
bool madness::Future< T >::is_local ( ) const
inline
template<typename T>
bool madness::Future< T >::is_remote ( ) const
inline
template<typename T>
madness::Future< T >::operator const T & ( ) const
inline

Same as get() const.

template<typename T>
madness::Future< T >::operator T & ( )
inline

Same as get()

template<typename T>
Future<T>& madness::Future< T >::operator= ( const Future< T > &  other)
inline

Assignment future = future makes a shallow copy just like copy constructor.

template<typename T>
bool madness::Future< T >::probe ( ) const
inline

Query the whether this future has been assigned.

Returns
true if the future has been assigned, otherwise false

Referenced by madness::WorldGopInterface::bcast(), madness::Future< bool >::operator=(), madness::Future< bool >::register_callback(), madness::Future< bool >::remote_ref(), and madness::detail::DistCache< keyT >::set_cache_value().

template<typename T>
void madness::Future< T >::register_callback ( CallbackInterface callback)
inline

Registers an object to be called when future is assigned.

Callbacks are invoked in the order registered. If the future is already assigned the callback is immediately invoked.

template<typename T>
remote_refT madness::Future< T >::remote_ref ( World world) const
inline

Returns a structure used to pass references to another process.

This is used for passing pointers/references to another process. To make remote references completely safe, the RemoteReference increments the internal reference count of the Future. The counter is decremented by either assigning to the remote Future or its destructor if it is never assigned. The remote Future is ONLY useful for setting the future. It will NOT be notified if the value is set elsewhere.

If this is already a reference to a remote future, the actual remote reference is returned ... i.e., not a a reference to the local future. Therefore, the local future will not be notified when the result is set (i.e., the communication is short circuited).

Referenced by madness::FunctionImpl< T, NDIM >::coeffs_for_jun(), madness::Function< double, 6 >::eval(), madness::Function< double, 6 >::evaldepthpt(), madness::Function< double, 6 >::evalR(), madness::WorldContainerImpl< keyT, valueT, hashfunT >::find(), madness::FunctionImpl< T, NDIM >::find_me(), madness::DerivativeBase< T, NDIM >::find_neighbor(), and madness::FunctionImpl< Q, NDIM >::project_out2().

template<typename T>
void madness::Future< T >::set ( const Future< T > &  other)
inline

A.set(B) where A & B are futures ensures A has/will have the same value as B.

An exception is thrown if A is already assigned since a Future is a single assignment variable. We don't yet track multiple assignments from unassigned futures.

If B is already assigned, this is the same as A.set(B.get()) which sets A to the value of B.

If B has not yet been assigned, the behavior is to ensure that when B is assigned that both A and B will be assigned and have the same value (though they may/may not refer to the same underlying copy of the data and indeed may even be in different processes).

Referenced by madness::detail::DistCache< keyT >::get_cache_value(), madness::Future< bool >::operator=(), madness::detail::run_function(), madness::Future< bool >::set(), madness::detail::DistCache< keyT >::set_cache_value(), madness::FunctionImpl< T, NDIM >::sock_it_to_me(), and madness::FunctionImpl< T, NDIM >::sock_it_to_me_too().

template<typename T>
void madness::Future< T >::set ( const T &  value)
inline

Assigns the value ... it can only be set ONCE.

template<typename T>
void madness::Future< T >::set ( const archive::BufferInputArchive input_arch)
inline

Assigns the value ... it can only be set ONCE.

Friends And Related Function Documentation

template<typename T>
std::ostream& operator ( std::ostream &  out,
const Future< T > &  f 
)
friend

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