Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

osval.h

00001 // $Id: osval_8h-source.html,v 1.2 2002/06/20 17:09:51 mkrohn5 Exp $
00002 
00003 // Overflow-Safe Value Header File
00004 // Written by: Alberto Barsella
00005 
00006 // Copyright (C) 1999, 2000, Alberto Barsella <Alberto.Barsella@univ-lille1.fr>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 1, or (at your option)
00011 // any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 
00018 #ifndef __TOSVAL_INCLUDED
00019 #define __TOSVAL_INCLUDED
00020 
00021 #include <iostream>
00022 
00023 #include "common/global.h"
00024 
00025 class TDataPackageList;
00026 using namespace std;
00027 
00028 
00029 
00030 /* FIXME: should be removed or moved to global.cpp - Marco */
00031 inline int4 sign(const int4 i) {
00032   return (i > 0)? 1 : ((i == 0)? 0 : -1);
00033 }
00034 
00035 inline int4 iabs(const int4 i) {
00036   return (i > 0)? i : ((i == 0)? 0 : -i);
00037 }
00038 
00039 inline int4 min(const int4 a, const int4 b) {
00040   return (a < b)? a : b;
00041 }
00042 
00043 inline int4 max(const int4 a, const int4 b) {
00044   return (a > b)? a : b;
00045 }
00046 
00047 
00048 
00049 
00050 
00051 //----------------------------------------  class TOSVal  ----------------------------------------
00052 
00103 class TOSVal
00104 {
00105   public:
00106     TOSVal();
00107     TOSVal(const int4 iVal);
00108     // default destructor
00109     // default copy constructor
00110     // default operator=
00111 
00112     // special values for quantities
00113     // - infinity means an infinite amount
00114     // - maximum  is the maximum possible value: any attempt to
00115     //            go beyond this just does nothing
00116     //            it's used to prevent overflows
00117     static const int4 iInfinity;  // 2^31-1
00118     static const int4 iMaximum;   // 2*10^9       see osval.cpp
00119 
00120     // accessors
00121     int4 Value() const;
00122     bool Infinite() const;
00123     bool Maximum() const;
00124     bool Zero() const;
00125     bool Positive() const;
00126     bool Negative() const;
00127     TOSVal& operator=(const int4 iVal);
00128 
00129     // mathematical operators
00130     const TOSVal operator-(void) const;
00131     const TOSVal operator+(const TOSVal& v2) const;
00132     const TOSVal operator-(const TOSVal& v2) const;
00133     TOSVal& operator+=(const TOSVal& v2);
00134     TOSVal& operator-=(const TOSVal& v2);
00135 
00136     // rescale (= multiply by fraction)
00137     TOSVal Scale(const int4 iNum, const int4 iDenom) const;
00138 
00139     // comparison operators
00140     bool operator==(const TOSVal v2) const;
00141     bool operator>=(const TOSVal v2) const;
00142     bool operator<=(const TOSVal v2) const;
00143     bool operator>(const TOSVal v2) const;
00144     bool operator<(const TOSVal v2) const;
00145 
00146     bool operator==( int4 v2 ) const;
00147     bool operator!=( int4 v2 ) const;
00148 
00149     // output operator
00150     friend ostream& operator<<(ostream& os, const TOSVal& v);
00151 
00152     // load and save
00160     bool load( TDataPackageList* in, const string& sIdentifier, bool bUnique=true );
00168     bool save( TDataPackageList* out, const string& sIdentifier, bool bUnique=true ) const;
00169 
00170   private:
00171     int4 iValue;
00172 };
00173 
00174 
00175 
00176 
00177 
00178 #endif        // TOSVal

Generated on Thu Jun 20 18:13:16 2002 for Stellar Legacy by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001