メインページ | モジュール | 名前空間一覧 | クラス階層 | 構成 | ファイル一覧 | 名前空間メンバ | 構成メンバ | ファイルメンバ | 関連ページ

toppers/time.hpp

解説を見る。
00001 /*
00002  *  TOPPERS/C++ API Template Library
00003  *      Toyohashi Open Platform for Embedded Real-Time Systems/
00004  *      C++ API Template Library
00005  *
00006  *  Copyright (C) 2004 by TAKAGI Nobuhisa
00007  *
00008  *  上記著作権者は,以下の (1)〜(4) の条件か,Free Software Foundation
00009  *  によって公表されている GNU General Public License の Version 2 に記
00010  *  述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
00011  *  を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
00012  *  利用と呼ぶ)することを無償で許諾する.
00013  *  (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
00014  *      権表示,この利用条件および下記の無保証規定が,そのままの形でソー
00015  *      スコード中に含まれていること.
00016  *  (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
00017  *      用できる形で再配布する場合には,再配布に伴うドキュメント(利用
00018  *      者マニュアルなど)に,上記の著作権表示,この利用条件および下記
00019  *      の無保証規定を掲載すること.
00020  *  (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
00021  *      用できない形で再配布する場合には,次のいずれかの条件を満たすこ
00022  *      と.
00023  *    (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
00024  *        作権表示,この利用条件および下記の無保証規定を掲載すること.
00025  *    (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
00026  *        報告すること.
00027  *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
00028  *      害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
00029  *
00030  *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
00031  *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
00032  *  含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
00033  *  接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
00034  *
00035  *  @(#) $Id: time.hpp,v 1.1.1.1 2004/04/14 09:30:31 takagi-n Exp $
00036  */
00037 
00050 #ifndef TOPPERS_TIME_HPP_
00051 #define TOPPERS_TIME_HPP_
00052 
00053 #include <toppers/raw_stub.hpp>
00054 #include <toppers/assert.hpp>
00055 #include <toppers/diagnostics.hpp>
00056 
00057 #ifndef TOPPERS_DEFAULT_STUB
00058 #define TOPPERS_DEFAULT_STUB    raw_stub<>
00059 #endif
00060 
00061 namespace toppers
00062 {
00063 
00075     template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00076               class Stub = TOPPERS_DEFAULT_STUB >
00077     class systemtime : Diagnostics
00078     {
00079     public:
00081         typedef ::SYSTIM time;
00082 
00084         static ER set(const time& t)
00085         {
00086             ER ercd = Stub::stub_set_tim(&t);
00087             return static_handle_error(ercd);
00088         }
00089 
00091         static ER get(time* p)
00092         {
00093             ER ercd = Stub::stub_get_tim(p);
00094             return static_handle_error(ercd);
00095         }
00096     };
00097 
00106     template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00107               class Stub = TOPPERS_DEFAULT_STUB >
00108     class xsystemtime : Diagnostics
00109     {
00110     public:
00112         typedef ::SYSUTIM   time;
00113 
00115         static ER get(time* p)
00116         {
00117             ER ercd = Stub::stub_vxget_tim(p);
00118             return static_handle_error(ercd);
00119         }
00120     };
00121 
00122 #ifdef  TOPPERS_STRUCT_SYSTIM
00123 
00124     inline const ::SYSTIM operator-(const ::SYSTIM& t1, const ::SYSTIM& t2)
00125     {
00126         ::SYSTIM t = t1;
00127         if (t.ltime < t2.ltime)
00128             --t.utime;
00129         t.ltime -= t2.ltime;
00130         t.utime -= t2.utime;
00131         return t;
00132     }
00133 
00134     inline bool operator==(const ::SYSTIM& t1, const ::SYSTIM& t2)
00135     {
00136         return t1.utime == t2.utime && t1.ltime == t2.ltime;
00137     }
00138 
00139     inline bool operator<(const ::SYSTIM& t1, const ::SYSTIM& t2)
00140     {
00141         return t1.utime < t2.utime || t1.ltime < t2.ltime;
00142     }
00143 
00144     inline bool operator!=(const ::SYSTIM& t1, const ::SYSTIM& t2)
00145     {
00146         return !(t1 == t2);
00147     }
00148 
00149     inline bool operator>(const ::SYSTIM& t1, const ::SYSTIM& t2)
00150     {
00151         return t2 < t1;
00152     }
00153 
00154     inline bool operator<=(const ::SYSTIM& t1, const ::SYSTIM& t2)
00155     {
00156         return !(t2 < t1);
00157     }
00158 
00159     inline bool operator>=(const ::SYSTIM& t1, const ::SYSTIM& t2)
00160     {
00161         return !(t1 < t2);
00162     }
00163 
00164 #endif  // TOPPERS_STRUCT_SYSTIM
00165 
00176     template <class SystemTime>
00177     class timer
00178     {
00179         typename SystemTime::time time_;
00180         typename SystemTime::time* logbuf_;
00181 
00182     public:
00184         explicit timer(typename SystemTime::time* log)
00185             : logbuf_(log)
00186         {
00187             SystemTime::get(&time_);
00188         }
00190         ~timer()
00191         {
00192             typename SystemTime::time   t;
00193             if (SystemTime::get(&t) == E_OK)
00194                 *logbuf_ = t - time_;
00195         }
00196     };
00197 
00198 }
00199 
00200 #endif  // ! TOPPERS_TIME_HPP_