jigdo API
Last update by Admin on 2010-05-23
util/status.hh
Go to the documentation of this file.00001 /* $Id: status.hh,v 1.4 2005/04/09 23:09:52 atterer Exp $ -*- C++ -*- 00002 __ _ 00003 |_) /| Copyright (C) 2003 | richard@ 00004 | \/¯| Richard Atterer | atterer.net 00005 ¯ '` ¯ 00006 This program is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU General Public License, version 2. See the file 00008 COPYING for details. 00009 00010 */ 00016 #ifndef STATUS_HH 00017 #define STATUS_HH 00018 00020 class Status { 00021 public: 00022 static const bool OK = false; 00023 static const bool FAILED = true; 00024 explicit Status(bool c) : code(c) { } 00025 Status(const Status& x) : code(x.code) { } 00026 Status& operator=(const Status& x) { code = x.code; return *this; } 00027 bool ok() const { return code == OK; } 00028 bool failed() const { return code == FAILED; } 00029 /* Default dtor */ 00030 /* Intentionally no operator bool() - should write ok() or failed() 00031 explicitly in if() conditions! */ 00032 bool code; 00033 private: 00034 // Prevent implicit conversions to bool 00035 explicit Status(int); 00036 explicit Status(unsigned); 00037 explicit Status(void*); 00038 }; 00039 00040 static const Status OK = Status(Status::OK); 00041 static const Status FAILED = Status(Status::FAILED); 00042 00043 inline bool operator==(const Status& a, const Status& b) { 00044 return a.code == b.code; 00045 } 00046 //______________________________________________________________________ 00047 00051 class XStatus { 00052 public: 00053 // static const int OK = 0; 00054 // static const int FAILED = -1; 00055 XStatus(const Status& x) : code(x.ok() ? 0 : -1) { } 00056 explicit XStatus(int c) : code(c) { } 00057 XStatus(const XStatus& x) : code(x.code) { } 00058 XStatus& operator=(const XStatus& x) { code = x.code; return *this; } 00059 XStatus& operator=(const Status& x) { 00060 code = (x.ok() ? 0 : -1); 00061 return *this; 00062 } 00065 bool xok() const { return code == 0; } 00066 bool xfailed() const { return code == -1; } 00067 //bool other() const { return code != 0 && code != -1; } 00068 bool returned(int x) const { return code == x; } 00069 /* Default dtor */ 00070 /* Intentionally no operator bool() - should write xok/xfailed/returned() 00071 explicitly in if() conditions! */ 00072 int code; 00073 }; 00074 00075 inline bool operator==(const XStatus& a, const XStatus& b) { 00076 return a.code == b.code; 00077 } 00078 00079 #endif
Generated on Tue Sep 23 14:27:42 2008 for jigdo by
