Public Types | Public Member Functions | Data Fields

ts::Rv< R > Struct Template Reference

Return type for returning a value and status (errata). More...

#include <Errata.h>

Inherits ts::RvBase.

Collaboration diagram for ts::Rv< R >:
Collaboration graph
[legend]

Public Types

typedef Rv self
 Standard self reference type.
typedef RvBase super
 Standard super class reference type.
typedef R Result
 Type of result value.

Public Member Functions

 Rv ()
 Default constructor.
 Rv (Result const &r)
 Standard (success) constructor.
 Rv (Result const &r, Errata const &s)
 Construct from a result and a pre-existing status object.
 operator Result const & () const
 User conversion to the result type.
Resultoperator= (Result const &r)
 Assignment from result type.
template<typename U >
selfpush (Rv< U > const &that)
 Add the status from another instance to this one.
selfset (Result const &r)
 Set the result.
Resultresult ()
 Return the result.
Result const & result () const
 Return the result.
Errataerrata ()
 Return the status.
Errata const & errata () const
 Return the status.
selfoperator= (Errata const &status)
 Directly set the errata.
selfpush (Errata::Message const &msg)
 Push a message on to the status.

Data Fields

Result _result
 The actual result of the function.

Detailed Description

template<typename R>
struct ts::Rv< R >

Return type for returning a value and status (errata).

In general, a method wants to return both a result and a status so that errors are logged properly. This structure is used to do that in way that is more usable than just std::pair. - Simpler and shorter typography - Force use of errata rather than having to remember it (and the order) each time - Enable assignment directly to R for ease of use and compatibility so clients can upgrade asynchronously.

Definition at line 650 of file Errata.h.


Member Typedef Documentation

template<typename R>
typedef R ts::Rv< R >::Result

Type of result value.

Definition at line 653 of file Errata.h.

template<typename R>
typedef Rv ts::Rv< R >::self

Standard self reference type.

Definition at line 651 of file Errata.h.

template<typename R>
typedef RvBase ts::Rv< R >::super

Standard super class reference type.

Definition at line 652 of file Errata.h.


Constructor & Destructor Documentation

template<typename T >
ts::Rv< T >::Rv (  ) 

Default constructor.

The default constructor for R is used. The status is initialized to SUCCESS.

Definition at line 908 of file Errata.h.

template<typename T >
ts::Rv< T >::Rv ( Result const &  r  ) 

Standard (success) constructor.

This copies the result and sets the status to SUCCESS.

Note:
Not explicit so that clients can return just a result and have it be marked as SUCCESS.
Parameters:
r The function result

Definition at line 909 of file Errata.h.

template<typename T >
ts::Rv< T >::Rv ( Result const &  r,
Errata const &  s 
)

Construct from a result and a pre-existing status object.

Parameters:
r The function result
s A pre-existing status object

Definition at line 910 of file Errata.h.


Member Function Documentation

template<typename T >
Errata & ts::Rv< T >::errata (  ) 

Return the status.

Returns:
A reference to the errata in this object.

Definition at line 920 of file Errata.h.

References ts::RvBase::_errata.

Referenced by ts::config::Builder::literalValue(), main(), ts::config::detail::ValueTable::make(), ts::config::Value::makeChild(), and ts::Rv< R >::push().

template<typename T >
Errata const & ts::Rv< T >::errata (  )  const

Return the status.

Returns:
A reference to the errata in this object.

Definition at line 919 of file Errata.h.

References ts::RvBase::_errata.

template<typename T >
ts::Rv< T >::operator Result const & (  )  const

User conversion to the result type.

This makes it easy to use the function normally or to pass the result only to other functions without having to extract it by hand.

Definition at line 914 of file Errata.h.

References ts::Rv< R >::_result.

template<typename R>
Result& ts::Rv< R >::operator= ( Result const &  r  )  [inline]

Assignment from result type.

This allows the result to be assigned to a pre-declared return value structure. The return value is a reference to the internal result so that this operator can be chained in other assignments to instances of result type. This is most commonly used when the result is computed in to a local variable to be both returned and stored in a member.

      Rv<int> zret;
      int value;
 ... complex computations, result in value
      this->m_value = zret = value;
 ...
      return zret;
Returns:
A reference to the copy of r stored in this object.
Parameters:
r Result to assign

Definition at line 712 of file Errata.h.

References ts::Rv< R >::_result.

template<typename T >
Rv< T > & ts::Rv< T >::operator= ( Errata const &  status  ) 

Directly set the errata.

Parameters:
status Errata to assign.

Definition at line 927 of file Errata.h.

References ts::RvBase::_errata.

template<typename T >
Rv< T > & ts::Rv< T >::push ( Errata::Message const &  msg  ) 

Push a message on to the status.

Definition at line 932 of file Errata.h.

References ts::RvBase::_errata, and ts::Errata::push().

template<typename T >
template<typename U >
Rv< T > & ts::Rv< T >::push ( Rv< U > const &  that  ) 

Add the status from another instance to this one.

Returns:
A reference to this object.
Parameters:
that Source of status messages

Definition at line 937 of file Errata.h.

References ts::RvBase::_errata, ts::Rv< R >::errata(), and ts::Errata::push().

template<typename T >
T const & ts::Rv< T >::result (  )  const

Return the result.

Returns:
A reference to the result value in this object.

Definition at line 917 of file Errata.h.

References ts::Rv< R >::_result, and T.

template<typename T >
T & ts::Rv< T >::result (  ) 
template<typename T >
Rv< T > & ts::Rv< T >::set ( Result const &  r  ) 

Set the result.

This differs from assignment of the function result in that the return value is a reference to the Rv, not the internal result. This makes it useful for assigning a result local variable and then returning.

      Rv<int> zret;
      int value;
 ... complex computation, result in value
      return zret.set(value);
Parameters:
r Result to store

Definition at line 922 of file Errata.h.

References ts::Rv< R >::_result.


Field Documentation

template<typename R>
Result ts::Rv< R >::_result

The actual result of the function.

Definition at line 655 of file Errata.h.

Referenced by ts::Rv< R >::operator Result const &(), ts::Rv< R >::operator=(), ts::Rv< R >::result(), and ts::Rv< R >::set().


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