managed_time_stamp.h

Go to the documentation of this file.
00001 #ifndef MANAGED_TIME_STAMP_CLASS
00002 #define MANAGED_TIME_STAMP_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : managed_time_stamp                                                *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2007-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include <basis/function.h>
00019 #include <hoople_api/string_conversions.h>
00020 #include <mechanisms/time_stamp.h>
00021 
00023 
00024 namespace hoople_api {
00025 
00027   public ref class managed_time_stamp
00028   {
00029   public:
00030     typedef double time_representation;
00031 
00032     managed_time_stamp() : _stamp(new time_stamp) {}
00034 
00035     managed_time_stamp(time_representation offset)
00036             : _stamp(new time_stamp(offset)) {}
00038 
00041     ~managed_time_stamp() { GC_WHACK(_stamp); }
00043 
00044     void reset() { _stamp->reset(); }
00046     void reset(time_representation offset) { _stamp->reset(offset); }
00048   
00049     time_representation value() { return _stamp->value(); }
00051   
00052     enum class stamp_display_style { STAMP_RELATIVE, STAMP_ABSOLUTE };
00053   
00054     System::String ^text_form(stamp_display_style style)
00056 
00059     {
00060       int style2 = int(style);
00061       return hoople_api::string_conversions::to_mstring
00062           (_stamp->text_form(time_stamp::stamp_display_style(style2)));
00063     }
00064   
00065     // standard operators: keep in mind that time is represented by an ever
00066     // increasing number.  so, if a value A is less than a value B, that means
00067     // that A is older than B, since it occurred at an earlier time.
00068     // also note that the managed version is not using c++ operators but is
00069     // instead using named functions based on acronyms.  for example, less than
00070     // or equal (<=) becomes lte.  the equality and inequality operations are
00071     // spelled out as equal and not_equal though.
00072     bool lt(const managed_time_stamp ^that)
00073         { return *_stamp < *that->_stamp; }
00074     bool gt(const managed_time_stamp ^that)
00075         { return *_stamp > *that->_stamp; }
00076     bool lte(const managed_time_stamp ^that)
00077         { return *_stamp <= *that->_stamp; }
00078     bool gte(const managed_time_stamp ^that)
00079         { return *_stamp >= *that->_stamp; }
00080     bool not_equal(const managed_time_stamp ^that)
00081         { return *_stamp != *that->_stamp; }
00082     bool equal(const managed_time_stamp ^that)
00083         { return *_stamp == *that->_stamp; }
00084 
00085     // longer names for comparisons, for those wishing more readable code.
00086     bool less_than(const managed_time_stamp ^that) { return this->lt(that); }
00087     bool greater_than(const managed_time_stamp ^that) { return this->gt(that); }
00088     bool less_than_or_equal(const managed_time_stamp ^that)
00089         { return this->lte(that); }
00090     bool greater_than_or_equal(const managed_time_stamp ^that)
00091         { return this->gte(that); }
00092     
00093   private:
00094     time_stamp *_stamp;  
00095   };
00096 }
00097 
00098 #endif
00099 

Generated on Fri Nov 28 04:29:15 2008 for HOOPLE Libraries by  doxygen 1.5.1