ReturnStatus.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2006-10-27 14:56:11 -0500 (Fri, 27 Oct 2006) $
00011  * Version:       $Revision: 19378 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef _VPR_RETURN_STATUS_H_
00043 #define _VPR_RETURN_STATUS_H_
00044 
00045 #include <vpr/vprConfig.h>
00046 #include <iostream>
00047 
00048 
00049 namespace vpr
00050 {
00056    class ReturnStatus
00057    {
00058    public:
00060       enum Code
00061       {
00062          Succeed,          
00063          Fail,             
00064          WouldBlock,       
00065          Timeout,          
00066          InProgress,       
00067          NotConnected,     
00068          ConnectionAborted 
00069       };
00070 
00072       ReturnStatus() : mReturnStatus(vpr::ReturnStatus::Succeed)
00073       {
00074       }
00075 
00083       void copy(const ReturnStatus& status)
00084       {
00085          mReturnStatus = status.mReturnStatus;
00086       }
00087 
00093       void setCode(const Code& c)
00094       {
00095          mReturnStatus = c;
00096       }
00097 
00101       const Code& code() const
00102       {
00103          return mReturnStatus;
00104       }
00105 
00107       ReturnStatus(const ReturnStatus& status)
00108       {
00109          this->copy(status);
00110       }
00111 
00113       ReturnStatus(const Code& c)
00114       {
00115          this->setCode(c);
00116       }
00117 
00123       ReturnStatus& operator=(const ReturnStatus& status)
00124       {
00125          if((&status) != this)
00126          {
00127             this->copy( status );
00128          }
00129          return *this;
00130       }
00131 
00137       ReturnStatus& operator=(const Code& c)
00138       {
00139          this->setCode(c);
00140          return *this;
00141       }
00142 
00148       bool operator==(const ReturnStatus& status) const
00149       {
00150          return status.mReturnStatus == mReturnStatus;
00151       }
00152 
00158       bool operator==(const Code& c) const
00159       {
00160          return c == mReturnStatus;
00161       }
00162 
00168       bool operator!=(const ReturnStatus& status) const
00169       {
00170          return status.mReturnStatus != mReturnStatus;
00171       }
00172 
00179       bool operator!=(const Code& c) const
00180       {
00181          return c != mReturnStatus;
00182       }
00183 
00184    public:
00187       bool success() const
00188       {
00189          return mReturnStatus == vpr::ReturnStatus::Succeed;
00190       }
00191 
00192       bool failure() const
00193       {
00194          return mReturnStatus == vpr::ReturnStatus::Fail;
00195       }
00196 
00197       bool wouldBlock() const
00198       {
00199          return mReturnStatus == vpr::ReturnStatus::WouldBlock;
00200       }
00201 
00202       bool inProgress() const
00203       {
00204          return mReturnStatus == vpr::ReturnStatus::InProgress;
00205       }
00206 
00207       bool timeout() const
00208       {
00209          return mReturnStatus == vpr::ReturnStatus::Timeout;
00210       }
00211 
00215       bool connectionAborted() const
00216       {
00217          return mReturnStatus == vpr::ReturnStatus::ConnectionAborted;
00218       }
00220 
00221    private:
00222       ReturnStatus::Code mReturnStatus;
00223    };
00224 } // namespace vpr
00225 
00226 inline std::ostream& operator<<(std::ostream& out, const vpr::ReturnStatus& ret)
00227 {
00228    switch(ret.code())
00229    {
00230    case vpr::ReturnStatus::Succeed:
00231       out << "Succeed";
00232       break;
00233    case vpr::ReturnStatus::Fail:             
00234       out << "Fail";
00235       break;
00236    case vpr::ReturnStatus::WouldBlock:       
00237       out << "WouldBlock";
00238       break;
00239    case vpr::ReturnStatus::Timeout:          
00240       out << "Timeout";
00241       break;
00242    case vpr::ReturnStatus::InProgress:       
00243       out << "InProgress";
00244       break;
00245    case vpr::ReturnStatus::NotConnected:
00246       out << "NotConnected";
00247       break;
00248    default:
00249       out << "Unknown";
00250       break;
00251    }
00252 
00253    return out;
00254 }
00255 
00256 #endif

Generated on Thu Jan 4 10:52:10 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1