cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsStateIndex.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ankur Kapoor, Peter Kazanzides
7  Created on: 2004-04-30
8 
9  (C) Copyright 2004-2010 Johns Hopkins University (JHU), All Rights Reserved.
10 
11 --- begin cisst license - do not edit ---
12 
13 This software is provided "as is" under an open source license, with
14 no warranty. The complete license can be found in license.txt and
15 http://www.cisst.org/cisst/license.txt.
16 
17 --- end cisst license ---
18 */
19 
20 
26 #ifndef _mtsStateIndex_h
27 #define _mtsStateIndex_h
28 
33 
35 
36 
52 
54 
55  public:
57  typedef unsigned long long int TimeTicksType;
58 
61 
62  private:
65  int TimeIndex;
66 
68  TimeTicksType TimeTicks;
69 
71  int BufferLength;
72 
73 public:
75  inline mtsStateIndex():
76  BaseType(), TimeIndex(0), TimeTicks(0), BufferLength(0)
77  {}
78 
80  inline mtsStateIndex(double timestamp, int index, TimeTicksType ticks, int Length):
81  BaseType(timestamp, false /* automatic timestamp */, true /* valid */),
82  TimeIndex(index), TimeTicks(ticks), BufferLength(Length)
83  {}
84 
87 
89  int Length(void) const {
90  return BufferLength;
91  }
92 
93  //*! Return the index into the circular buffer.*/
94  int Index(void) const {
95  return TimeIndex;
96  }
97 
99  TimeTicksType Ticks(void) const {
100  return TimeTicks;
101  }
102 
108  TimeTicks--;
109  TimeIndex--;
110  if (TimeIndex<0) {
111  TimeIndex = BufferLength-1;
112  }
113  return *this;
114  }
115 
117  mtsStateIndex& operator-=(int number) {
118  TimeTicks -= number;
119  TimeIndex = static_cast<int>(TimeTicks % BufferLength);
120  return *this;
121  }
122 
124  mtsStateIndex operator-(int number) {
125  mtsStateIndex tmp = *this;
126  return (tmp -= number);
127  }
128 
130  bool operator==(const mtsStateIndex & that) const {
131  return (TimeIndex == that.TimeIndex && TimeTicks == that.TimeTicks);
132  }
133 
135  bool operator!=(const mtsStateIndex & that) const {
136  return !(*this == that);
137  }
138 
140  virtual void ToStream(std::ostream & outputStream) const;
141 
143  virtual void ToStreamRaw(std::ostream & outputStream, const char delimiter = ' ',
144  bool headerOnly = false, const std::string & headerPrefix = "") const;
145 
149  void SerializeRaw(std::ostream & outputStream) const;
150 
153  virtual void DeSerializeRaw(std::istream & inputStream);
154 };
155 
157 
158 #endif // _mtsStateIndex_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
mtsStateIndex & operator--()
Definition: mtsStateIndex.h:107
~mtsStateIndex()
Definition: mtsStateIndex.h:86
Declaration of cmnSerializer and functions cmnSerializeRaw.
virtual void SerializeRaw(std::ostream &outputStream) const
virtual void DeSerializeRaw(std::istream &inputStream)
TimeTicksType Ticks(void) const
Definition: mtsStateIndex.h:99
bool operator==(const mtsStateIndex &that) const
Definition: mtsStateIndex.h:130
mtsStateIndex operator-(int number)
Definition: mtsStateIndex.h:124
virtual void ToStream(std::ostream &outputStream) const
Base class for high level objects.
Definition: cmnGenericObject.h:51
Base class for data object in cisstMultiTask.
Definition: mtsGenericObject.h:56
int Length(void) const
Definition: mtsStateIndex.h:89
mtsStateIndex()
Definition: mtsStateIndex.h:75
mtsStateIndex & operator-=(int number)
Definition: mtsStateIndex.h:117
Defines mtsGenericObject.
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
mtsGenericObject BaseType
Definition: mtsStateIndex.h:60
unsigned long long int TimeTicksType
Definition: mtsStateIndex.h:57
bool operator!=(const mtsStateIndex &that) const
Definition: mtsStateIndex.h:135
Rules of exporting.
Declaration of cmnDeSerializer and functions cmnDeSerializeRaw.
mtsStateIndex(double timestamp, int index, TimeTicksType ticks, int Length)
Definition: mtsStateIndex.h:80
Definition: mtsStateIndex.h:51
const int CMN_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:331
virtual void ToStreamRaw(std::ostream &outputStream, const char delimiter= ' ', bool headerOnly=false, const std::string &headerPrefix="") const
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition: cmnClassRegisterMacros.h:202
int Index(void) const
Definition: mtsStateIndex.h:94
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76