- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Lang/Time.h

    00001 //==============================================================================
    00002 //
    00003 // Copyright (c) 2001           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 //==============================================================================
    00010
    00011 // File: Time.h
    00012 // Class Time
    00013 //
    00014 // "Time" is the data type for time values in the temporal network.
    00015 // The valid domain for Time values is the domain of long integers,
    00016 // plus positive and negative INFINITY values.
    00017 //
    00018 // A Time object is represented by a long integer and a single
    00019 // boolean values. The boolean value indicates whether the value is
    00020 // infinite (if true) or finite (if false). If the value is non-infinite
    00021 // then it is represented by the long integer. If it is infinite, then
    00022 // it's sign is positive if the long integer is non-negative, and negative
    00023 // otherwise.
    00024 //
    00025 // Time objects are initialized to zero, by default.
    00026 //
    00027 // In order to maintain valid values, the following properties are
    00028 // maintained:
    00029 //   +INFINITY + (any value except -INFINITY) = +INFINITY
    00030 //   -INFINITY + (any value except +INFINITY) = -INFINITY
    00031 //   +INFINITY + -INFINITY = error
    00032 //
    00033
    00034 // TODO: 1. see if you can make comparion operators use fewer operations
    00035
    00036 #ifndef TIME_H
    00037 #define TIME_H
    00038
    00039 #define MAX_TIME_LEN 80
    00040
    00041 // PHE: You don't need to include this
    00042 //#include "plandef.h"
    00043
    00044 #include <iostream>
    00045 #include <fstream>
    00046
    00047 #ifdef min
    00048 #undef min
    00049 #endif
    00050
    00051 #ifdef max
    00052 #undef max
    00053 #endif
    00054
    00055 namespace Mers {
    00056         namespace Utils {
    00057                 namespace Lang {
    00058
    00059                         class Time;
    00060
    00061                         typedef Time InfInt;
    00062
    00063                         class Time
    00064                         {
    00065                                 friend std::ostream& operator<<(std::ostream & os, Time const & t);
    00066                                 // effects: output stream operator.
    00067
    00068                                 friend std::istream& operator>>(std::istream & os, Time & t);
    00069                                 // effects: input stream operator.
    00070
    00071                         public:
    00072
    00073                                 // Static data members
    00074                                 static const Time NEG_INF;
    00075                                 static const Time POS_INF;
    00076
    00077                                 // Public Constructors
    00078                                 Time();
    00079                                 // effects: Initializes the object with a zero value.
    00080
    00081                                 Time(long val);
    00082                                 // effects: Initilizes the object assuming inf is false. The value
    00083                                 //          is initialized to val.
    00084
    00085                                 Time(int val);
    00086                                 // effects: Initializes the object assuming inf is false. The value
    00087                                 //              is initialized to (long) val.
    00088
    00089                                 Time(long val, bool inf);
    00090                                 // effects: Initilizes the object. If inf is true, then the value is
    00091                                 //          positive infinity if val is non-negative, negative
    00092                                 //          infinity otherwise. If inf is false, then the value is
    00093                                 //          initialized to val.
    00094
    00095                                 Time(const char * str);
    00096                                 // requires: str = { "+INF", "-INF", <int> }
    00097                                 // effects: Initilizes the object to value given in the character
    00098         //          string str;
    00099         //
    00100                                 //          If str does not either represent an integer value or
    00101                                 //          positive or negative infinity, then the value is set
    00102                                 //          to zero by default.
    00103
    00104                                 void set(long val, bool inf = false);
    00105                                 // effects: Modifies the value of this. The arguments have the same
    00106                                 //          effect as the constructor Time(long,bool).
    00107
    00108                                 // Public Variables
    00109                                 long      longval() const;
    00110                                 bool      isInfinite() const; // added by AFW
    00111
    00112                                 static Time& min(Time &a, Time &b);
    00113                                 static Time& max(Time &a, Time &b);
    00114
    00115                                 // Public Methods
    00116                                 Time& operator= (const char* str );
    00117                                 Time&  operator= (const long val);
    00118                                 Time&  operator= (const int val);
    00119                                 Time&  operator= (Time const & rhs);
    00120                                 Time   operator+ (Time const & rhs) const;
    00121                                 Time&  operator+=(Time const & rhs);
    00122                                 Time   operator- (Time const & rhs) const;
    00123                                 Time   operator- () const;
    00124                                 bool   operator> (Time const & rhs) const;
    00125                                 bool   operator< (Time const & rhs) const;
    00126                                 bool   operator==(Time const & rhs) const;
    00127                                 bool   operator!=(Time const & rhs) const;
    00128                                 bool   HasValue(const Time& rhs) const;
    00129                                 bool   operator<=(Time const & rhs) const;
    00130                                 bool   operator>=(Time const & rhs) const;
    00131
    00132                         private:
    00133                                 // Private Variables
    00134                                 long    value;
    00135                                 bool    inf_flag;
    00136
    00137                         };
    00138
    00139                         // Use to test Time class functions.
    00140 #ifdef _DEBUG
    00141                         void time_check();
    00142 #endif
    00143
    00144                 }
    00145         }
    00146 }
    00147
    00148 #endif
    00149