00001 /* 00002 * WOscLib, an object oriented OSC library. 00003 * Copyright (C) 2005 Uli Clemens Franke, Weiss Engineering LTD, Switzerland. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * For details see lgpl.txt 00020 * 00021 * Weiss Engineering LTD. 00022 * Florastrass 42 00023 * 8610 Uster 00024 * Switzerland 00025 * 00026 * uli.franke@weiss.ch 00027 */ 00028 00029 /** WOscTimeTag header file. 00030 * \file 00031 * 00032 * $Author: cls-nebadje $ ( \ref _UcfWOscLib ) 00033 * $Date: 2009-01-14 17:16:49 $ 00034 * $Revision: 1.6 $ 00035 * 00036 * Copyright (c) Weiss Engineering Ltd 00037 * 00038 */ 00039 #ifndef __WOSCTIMETAG_H__ 00040 #define __WOSCTIMETAG_H__ 00041 00042 #include "WOscLib.h" 00043 #include <stdlib.h> // for NULL 00044 #include <stdint.h> // uint64_t 00045 00046 class WOscTimeTag; 00047 00048 /* ----------------------------------------------------------------------- */ 00049 /* WOscSystemTime */ 00050 /* ----------------------------------------------------------------------- */ 00051 00052 /** Implementation of the system time. 00053 * Every system using this library can inherit its own specific 00054 * class and override the getSystemTime() - member-function. 00055 * If not overridden (using the base class (this one :)), see 00056 * WOscSystemTime::GetSystemTime() for details. 00057 * 00058 */ 00059 class WOSC_EXPORT WOscSystemTime{ 00060 public: 00061 virtual ~WOscSystemTime() {} 00062 virtual WOscTimeTag GetSystemTime() const; 00063 }; 00064 00065 00066 /* ----------------------------------------------------------------------- */ 00067 /* WOscTimeTag */ 00068 /* ----------------------------------------------------------------------- */ 00069 00070 /** Definition of time in an OSC system. 00071 * The OSC-specification ( \ref WOscLibOsc_spec_page "OSC specifications" ) states: 00072 * Time tags are represented by a 64 bit fixed point number. The first 32 bits specify 00073 * the number of seconds since midnight on January 1, 1900, and the last 32 bits specify 00074 * fractional parts of a second to a precision of about 200 picoseconds. This is the rep- 00075 * resentation used by Internet NTP timestamps. The time tag value consisting of 63 zero 00076 * bits followed by a one in the least signifigant bit is a special case meaning "immediately." 00077 * 00078 * \remarks 00079 * This is one of the platform (compiler/processor/operating-system) dependent 00080 * parts of the library. WOscTimeTag is affected regarding the number- 00081 * representation (32/64 datatypes supported) and the endianness (big- 00082 * endian or little-endian). Both can be switched by preprocessor-defines. 00083 * 00084 * \see 00085 * WOscSystemTime 00086 */ 00087 class WOSC_EXPORT WOscTimeTag{ 00088 00089 public: 00090 WOscTimeTag(); 00091 WOscTimeTag(const char* rawTimeTag); 00092 WOscTimeTag(const WOscTimeTag& rhs); 00093 00094 static WOscTimeTag GetCurrentTime(const WOscSystemTime* systemTime = NULL); 00095 static WOscTimeTag GetImmediateTime(); 00096 static WOscTimeTag GetLargestTimeTag(); 00097 static WOscTimeTag GetSmallestTimeTag(); 00098 00099 void SetToCurrentTime(const WOscSystemTime* systemTime = NULL); 00100 void SetToImmediateTime(); 00101 void SetToLargestTimeTag(); 00102 void SetToSmallestTimeTag(); 00103 00104 WOscTimeTag operator+ (const WOscTimeTag& rhs) const; 00105 WOscTimeTag operator+= (const WOscTimeTag& rhs); 00106 WOscTimeTag operator= (const WOscTimeTag& rhs); 00107 WOscTimeTag operator- (const WOscTimeTag& rhs) const; 00108 WOscTimeTag operator-= (const WOscTimeTag& rhs); 00109 00110 bool operator< (const WOscTimeTag& rhs) const; 00111 bool operator<= (const WOscTimeTag& rhs) const; 00112 bool operator== (const WOscTimeTag& rhs) const; 00113 bool operator!= (const WOscTimeTag& rhs) const; 00114 bool operator> (const WOscTimeTag& rhs) const; 00115 bool operator>= (const WOscTimeTag& rhs) const; 00116 00117 const char* ToCharArray() const; 00118 void WriteToCharArray(char* buffer) const; 00119 void InitFromCharArray(const char* buffer); 00120 uint64_t GetRawTimeTag() const { return m_timeTag; } 00121 /** Time-tag related constants. 00122 * \remarks 00123 * Use TIME_TAG_SIZE when referring to char-buffers 00124 * related with the WOscTimeTag. 00125 */ 00126 enum Constants 00127 { 00128 TIME_TAG_SIZE = 8, /**< buffer size for char-arrayed timetags.*/ 00129 }; 00130 00131 private: 00132 friend class WOscSystemTime; 00133 /** Binary time-tag representation for platforms with 8-byte integers. */ 00134 uint64_t m_timeTag; 00135 }; 00136 00137 #endif // #ifndef __WOSCTIMETAG_H__