Changeset 14:3caa1d3122db in xplcommon for src/xplcommon/Failable.h


Ignore:
Timestamp:
12/29/12 10:03:12 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Moved the storage of the error code to where it belongs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/xplcommon/Failable.h

    r6 r14  
    8282
    8383//------------------------------------------------------------------------------
     84
     85/**
     86 * An object that references another failable object and fails
     87 * together with that object.
     88 *
     89 * The Child class should contain a function named getFailable()
     90 * which returns the failable object.
     91 */
     92template <class Child>
     93class FailableReference
     94{
     95public:
     96    /**
     97     * Indicate if the referenced object has failed.
     98     */
     99    bool failed() const;
     100
     101    /**
     102     * Get the error code from the referenced object.
     103     */
     104    errorCode_t getErrorCode() const;
     105
     106    /**
     107     * Discard the error code of the referenced object.
     108     */
     109    void repair();
     110};
     111
     112//------------------------------------------------------------------------------
    84113// Inline definitions
    85114//------------------------------------------------------------------------------
     
    119148
    120149//------------------------------------------------------------------------------
     150//------------------------------------------------------------------------------
     151
     152template <class Child>
     153inline bool FailableReference<Child>::failed() const
     154{
     155    return static_cast<const Child*>(this)->getFailable().failed();
     156}
     157
     158//------------------------------------------------------------------------------
     159
     160template <class Child>
     161inline errorCode_t FailableReference<Child>::getErrorCode() const
     162{
     163    return static_cast<const Child*>(this)->getFailable().getErrorCode();
     164}
     165
     166//------------------------------------------------------------------------------
     167
     168template <class Child>
     169inline void FailableReference<Child>::repair()
     170{
     171    static_cast<Child*>(this)->getFailable().repair();
     172}
     173
     174//------------------------------------------------------------------------------
    121175
    122176} /* namespace xplcommon */
Note: See TracChangeset for help on using the changeset viewer.