MADNESS  0.10.1
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
madness::detail::WorldPtr< T > Class Template Reference

A global pointer address, valid anywhere in the world. More...

#include <worldptr.h>

Collaboration diagram for madness::detail::WorldPtr< T >:
Collaboration graph
[legend]

Public Types

typedef Tpointer
 Alias for the pointer type. More...
 
typedef ptr_traits< T >::reference reference
 
typedef unsigned long worldidT
 World ID type. More...
 

Public Member Functions

 WorldPtr ()
 Default constructor. More...
 
 WorldPtr (const WorldPtr< T > &other)
 Copy constructor. More...
 
template<typename U >
 WorldPtr (const WorldPtr< U > &other)
 Copy conversion constructor. More...
 
 WorldPtr (World &w, T *p)
 World pointer constructor. More...
 
pointer get () const
 Pointer accessor. More...
 
Worldget_world () const
 World accessor. More...
 
worldidT get_worldid () const
 World ID accessor. More...
 
bool has_owner () const
 Check that the world pointer has an owner. More...
 
bool is_local () const
 Check that the world pointer references a local pointer. More...
 
template<class Archive >
void load_internal_ (const Archive &ar)
 Deserialize the world pointer. More...
 
 operator bool () const
 Boolean conversion operator. More...
 
bool operator! () const
 Boolean conversion (not) operator. More...
 
template<typename U >
bool operator!= (const WorldPtr< U > &other) const
 Inequality comparison operator. More...
 
reference operator* () const
 Dereference operator. More...
 
pointer operator-> () const
 Pointer arrow operator. More...
 
template<typename U >
bool operator< (const WorldPtr< U > &other) const
 Less-than comparison operator. More...
 
WorldPtr< T > & operator= (const WorldPtr< T > &other)
 Copy assignment operator. More...
 
template<typename U >
WorldPtr< T > & operator= (const WorldPtr< U > &other)
 Copy conversion assignment operator. More...
 
template<typename U >
bool operator== (const WorldPtr< U > &other) const
 Equality comparison operator. More...
 
ProcessID owner () const
 Rank accessor. More...
 
template<class Archive >
void store_internal_ (const Archive &ar) const
 Serialize the world pointer. More...
 
template<typename U >
void swap (WorldPtr< U > &other)
 Swap the content of this with other. More...
 

Private Member Functions

ProcessID local_rank () const
 Current local rank. More...
 

Private Attributes

Tpointer_
 The pointer being referenced. More...
 
ProcessID rank_
 The rank of the node that the pointer belongs to. More...
 
Worldworld_
 A pointer to the world. More...
 
worldidT worldid_
 The world ID. More...
 

Friends

template<typename >
class WorldPtr
 
std::ostream & operator<< (std::ostream &out, const WorldPtr< T > &p)
 Output stream insertion operator for world pointers. More...
 

Detailed Description

template<typename T>
class madness::detail::WorldPtr< T >

A global pointer address, valid anywhere in the world.

Stores a globally addressable pointer. It can be sent to any process in the world.

Template Parameters
TThe pointer type.

Member Typedef Documentation

◆ pointer

template<typename T >
typedef T* madness::detail::WorldPtr< T >::pointer

Alias for the pointer type.

◆ reference

template<typename T >
typedef ptr_traits<T>::reference madness::detail::WorldPtr< T >::reference
Todo:
Brief description needed.

◆ worldidT

template<typename T >
typedef unsigned long madness::detail::WorldPtr< T >::worldidT

World ID type.

Constructor & Destructor Documentation

◆ WorldPtr() [1/4]

template<typename T >
madness::detail::WorldPtr< T >::WorldPtr ( )
inline

Default constructor.

Creates a NULL pointer. There is no owner; i.e. the owner is set to -1.

Todo:
Would it be worth adding a static constant ProcessID equal to -1 to signify an unowned pointer?

◆ WorldPtr() [2/4]

template<typename T >
madness::detail::WorldPtr< T >::WorldPtr ( World w,
T p 
)
inline

World pointer constructor.

Construct a world pointer form a local pointer.

Parameters
[in]wA reference to the local world.
[in]pThe local pointer.

◆ WorldPtr() [3/4]

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

Copy constructor.

Parameters
[in]otherThe world pointer to be copied.

◆ WorldPtr() [4/4]

template<typename T >
template<typename U >
madness::detail::WorldPtr< T >::WorldPtr ( const WorldPtr< U > &  other)
inline

Copy conversion constructor.

Copy and convert a pointer from U* to T* type.

Template Parameters
UThe pointer type of the other pointer.
Parameters
[in]otherThe world pointer to be copied.
Note
U* must be implicitly convertible to T* type.

Member Function Documentation

◆ get()

template<typename T >
pointer madness::detail::WorldPtr< T >::get ( ) const
inline

Pointer accessor.

Get the pointer from the world pointer.

Note
A default initialized pointer is not considered to be local because it is not associated with a world.
Returns
The local pointer.
Exceptions
MadnessExceptionWhen the pointer references a remote address.

References madness::detail::WorldPtr< T >::is_local(), MADNESS_ASSERT, and madness::detail::WorldPtr< T >::pointer_.

◆ get_world()

template<typename T >
World& madness::detail::WorldPtr< T >::get_world ( ) const
inline

World accessor.

Returns
A reference to the world (may be NULL).
Exceptions
MadnessExceptionWhen the pointer world has not been set (i.e. when has_owner()==false).

References MADNESS_ASSERT, and madness::detail::WorldPtr< T >::world_.

◆ get_worldid()

template<typename T >
worldidT madness::detail::WorldPtr< T >::get_worldid ( ) const
inline

World ID accessor.

Returns
The world ID of the world that the pointer belongs to.

References madness::detail::WorldPtr< T >::worldid_.

Referenced by madness::detail::WorldPtr< T >::load_internal_().

◆ has_owner()

template<typename T >
bool madness::detail::WorldPtr< T >::has_owner ( ) const
inline

Check that the world pointer has an owner.

Returns
True if the pointer has a valid owner; false otherwise.

References madness::detail::WorldPtr< T >::rank_, and madness::detail::WorldPtr< T >::world_.

◆ is_local()

template<typename T >
bool madness::detail::WorldPtr< T >::is_local ( ) const
inline

Check that the world pointer references a local pointer.

Returns
True if the pointer points to a local address; false if it points to a remote address or is NULL.

References madness::detail::WorldPtr< T >::local_rank(), and madness::detail::WorldPtr< T >::rank_.

Referenced by madness::detail::WorldPtr< T >::get(), madness::detail::WorldPtr< T >::operator*(), and madness::detail::WorldPtr< T >::operator->().

◆ load_internal_()

template<typename T >
template<class Archive >
void madness::detail::WorldPtr< T >::load_internal_ ( const Archive &  ar)
inline

Deserialize the world pointer.

Deserialize the world pointer for remote communication or write to disk.

Template Parameters
ArchiveThe archive object type.
Parameters
[in]arThe archive.

References madness::detail::WorldPtr< T >::get_worldid(), madness::detail::WorldPtr< T >::pointer_, madness::detail::WorldPtr< T >::rank_, madness::detail::WorldPtr< T >::world_, madness::World::world_from_id(), madness::detail::WorldPtr< T >::worldid_, and madness::archive::wrap_opaque().

◆ local_rank()

template<typename T >
ProcessID madness::detail::WorldPtr< T >::local_rank ( ) const
inlineprivate

Current local rank.

Returns
The rank of the current node. If the pointer is not set, then -2.
Note
-2 is returned so it is not equal to the null value of -1.

References madness::World::rank(), and madness::detail::WorldPtr< T >::world_.

Referenced by madness::detail::WorldPtr< T >::is_local().

◆ operator bool()

template<typename T >
madness::detail::WorldPtr< T >::operator bool ( ) const
inline

Boolean conversion operator.

Returns
True if the pointer is non-null; false otherwise.

References madness::detail::WorldPtr< T >::pointer_.

◆ operator!()

template<typename T >
bool madness::detail::WorldPtr< T >::operator! ( ) const
inline

Boolean conversion (not) operator.

Returns
True if the pointer is null; false otherwise.

References madness::detail::WorldPtr< T >::pointer_.

◆ operator!=()

template<typename T >
template<typename U >
bool madness::detail::WorldPtr< T >::operator!= ( const WorldPtr< U > &  other) const
inline

Inequality comparison operator.

Template Parameters
UAnother pointer type.
Parameters
[in]otherThe other pointer to compare with.
Returns
True if the pointers refer to different addresses or different nodes or different worlds; false otherwise.

References madness::detail::WorldPtr< T >::pointer_, madness::detail::WorldPtr< T >::rank_, and madness::detail::WorldPtr< T >::worldid_.

◆ operator*()

template<typename T >
reference madness::detail::WorldPtr< T >::operator* ( ) const
inline

Dereference operator.

Dereference the local pointer.

Returns
A reference to the local pointer.
Exceptions
MadnessExceptionIf the pointer references a remote address, or if the pointer is NULL.

References madness::detail::WorldPtr< T >::is_local(), MADNESS_ASSERT, and madness::detail::WorldPtr< T >::pointer_.

◆ operator->()

template<typename T >
pointer madness::detail::WorldPtr< T >::operator-> ( ) const
inline

Pointer arrow operator.

Access members of the pointer.

Returns
The local pointer.
Exceptions
MadnessExceptionIf the pointer references a remote address, or if the pointer is NULL.

References madness::detail::WorldPtr< T >::is_local(), MADNESS_ASSERT, and madness::detail::WorldPtr< T >::pointer_.

◆ operator<()

template<typename T >
template<typename U >
bool madness::detail::WorldPtr< T >::operator< ( const WorldPtr< U > &  other) const
inline

Less-than comparison operator.

This operator does a lexicographical comparison of world ID, rank, and pointer (in that order).

Template Parameters
UAnother pointer type.
Parameters
[in]otherThe other pointer to compare with.
Returns
True if the lexicographical comparison of world ID, rank, and pointer is true; false otherwise.

References madness::detail::WorldPtr< T >::pointer_, madness::detail::WorldPtr< T >::rank_, and madness::detail::WorldPtr< T >::worldid_.

◆ operator=() [1/2]

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

Copy assignment operator.

Parameters
[in]otherThe world pointer to be copied.
Returns
A reference to this object.

References madness::detail::WorldPtr< T >::pointer_, madness::detail::WorldPtr< T >::rank_, madness::detail::WorldPtr< T >::world_, and madness::detail::WorldPtr< T >::worldid_.

◆ operator=() [2/2]

template<typename T >
template<typename U >
WorldPtr<T>& madness::detail::WorldPtr< T >::operator= ( const WorldPtr< U > &  other)
inline

Copy conversion assignment operator.

Copy and convert a pointer from U* to T* type.

Template Parameters
UThe pointer type of the other pointer.
Parameters
[in]otherThe world pointer to be copied.
Returns
A reference to this object.
Note
U* must be implicitly convertible to T* type.

References madness::detail::WorldPtr< T >::pointer_, madness::detail::WorldPtr< T >::rank_, madness::detail::WorldPtr< T >::world_, and madness::detail::WorldPtr< T >::worldid_.

◆ operator==()

template<typename T >
template<typename U >
bool madness::detail::WorldPtr< T >::operator== ( const WorldPtr< U > &  other) const
inline

Equality comparison operator.

Template Parameters
UAnother pointer type.
Parameters
[in]otherThe pointer to compare with.
Returns
True if the pointers refer to the same address from the same node in the same world; false otherwise.

References madness::detail::WorldPtr< T >::pointer_, madness::detail::WorldPtr< T >::rank_, and madness::detail::WorldPtr< T >::worldid_.

◆ owner()

template<typename T >
ProcessID madness::detail::WorldPtr< T >::owner ( ) const
inline

Rank accessor.

Todo:
Finish this sentence: If the pointer is not associated with
Returns
The rank of the process that owns the pointer.

References madness::detail::WorldPtr< T >::rank_.

◆ store_internal_()

template<typename T >
template<class Archive >
void madness::detail::WorldPtr< T >::store_internal_ ( const Archive &  ar) const
inline

Serialize the world pointer.

Serialize the world pointer for remote communication or write to disk.

Template Parameters
ArchiveThe archive object type.
Parameters
[in]arThe archive.

References madness::detail::WorldPtr< T >::pointer_, madness::detail::WorldPtr< T >::rank_, madness::detail::WorldPtr< T >::worldid_, and madness::archive::wrap_opaque().

◆ swap()

template<typename T >
template<typename U >
void madness::detail::WorldPtr< T >::swap ( WorldPtr< U > &  other)
inline

Swap the content of this with other.

Template Parameters
UThe other world pointer type.
Parameters
[in,out]otherThe other world pointer.
Note
U* must be implicitly convertible to T* type.

References madness::detail::WorldPtr< T >::pointer_, madness::detail::WorldPtr< T >::rank_, madness::detail::swap(), madness::detail::WorldPtr< T >::world_, and madness::detail::WorldPtr< T >::worldid_.

Referenced by madness::detail::swap().

Friends And Related Function Documentation

◆ WorldPtr

template<typename T >
template<typename >
friend class WorldPtr
friend

◆ operator<<

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

Output stream insertion operator for world pointers.

Parameters
[in,out]outThe output stream.
[in]pThe world pointer.
Returns
The output stream.
Todo:
Does this friend function need to be implemented in the class or can we move it to a *.cc file?

Member Data Documentation

◆ pointer_

template<typename T >
T* madness::detail::WorldPtr< T >::pointer_
private

◆ rank_

template<typename T >
ProcessID madness::detail::WorldPtr< T >::rank_
private

◆ world_

template<typename T >
World* madness::detail::WorldPtr< T >::world_
private

◆ worldid_

template<typename T >
worldidT madness::detail::WorldPtr< T >::worldid_
private

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