cisst-saw
Loading...
Searching...
No Matches
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 Author(s): Ankur Kapoor, Peter Kazanzides
6 Created on: 2004-04-30
7
8 (C) Copyright 2004-2023 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19
24
25#ifndef _mtsStateIndex_h
26#define _mtsStateIndex_h
27
32
34
35
51
52 CMN_DECLARE_SERVICES(CMN_DYNAMIC_CREATION, CMN_LOG_ALLOW_DEFAULT);
53
54 public:
56 typedef unsigned long long int TimeTicksType;
57
60
61 private:
64 int TimeIndex;
65
67 TimeTicksType TimeTicks;
68
70 int BufferLength;
71
72public:
74 inline mtsStateIndex():
75 BaseType(), TimeIndex(0), TimeTicks(0), BufferLength(0)
76 {}
77
79 inline mtsStateIndex(double timestamp, int index, TimeTicksType ticks, int Length):
80 BaseType(timestamp, false /* automatic timestamp */, true /* valid */),
81 TimeIndex(index), TimeTicks(ticks), BufferLength(Length)
82 {}
83
86
88 int Length(void) const {
89 return BufferLength;
90 }
91
92 //*! Return the index into the circular buffer.*/
93 int Index(void) const {
94 return TimeIndex;
95 }
96
98 TimeTicksType Ticks(void) const {
99 return TimeTicks;
100 }
101
107 TimeTicks--;
108 TimeIndex--;
109 if (TimeIndex<0) {
110 TimeIndex = BufferLength-1;
111 }
112 return *this;
113 }
114
117 TimeTicks -= number;
118 TimeIndex = static_cast<int>(TimeTicks % BufferLength);
119 return *this;
120 }
121
124 mtsStateIndex tmp = *this;
125 return (tmp -= number);
126 }
127
129 bool operator==(const mtsStateIndex & that) const {
130 return (TimeIndex == that.TimeIndex && TimeTicks == that.TimeTicks);
131 }
132
134 bool operator!=(const mtsStateIndex & that) const {
135 return !(*this == that);
136 }
137
139 void ToStream(std::ostream & outputStream) const override;
140
142 void ToStreamRaw(std::ostream & outputStream, const char delimiter = ' ',
143 bool headerOnly = false, const std::string & headerPrefix = "") const override;
144
148 void SerializeRaw(std::ostream & outputStream) const override;
149
152 void DeSerializeRaw(std::istream & inputStream) override;
153};
154
156
157#endif // _mtsStateIndex_h
mtsGenericObject(void)
Definition mtsGenericObject.h:77
Definition mtsStateIndex.h:50
mtsStateIndex(double timestamp, int index, TimeTicksType ticks, int Length)
Definition mtsStateIndex.h:79
mtsStateIndex & operator--()
Definition mtsStateIndex.h:106
bool operator==(const mtsStateIndex &that) const
Definition mtsStateIndex.h:129
void DeSerializeRaw(std::istream &inputStream) override
void SerializeRaw(std::ostream &outputStream) const override
unsigned long long int TimeTicksType
Definition mtsStateIndex.h:56
void ToStream(std::ostream &outputStream) const override
mtsGenericObject BaseType
Definition mtsStateIndex.h:59
TimeTicksType Ticks(void) const
Definition mtsStateIndex.h:98
void ToStreamRaw(std::ostream &outputStream, const char delimiter=' ', bool headerOnly=false, const std::string &headerPrefix="") const override
mtsStateIndex & operator-=(int number)
Definition mtsStateIndex.h:116
bool operator!=(const mtsStateIndex &that) const
Definition mtsStateIndex.h:134
mtsStateIndex operator-(int number)
Definition mtsStateIndex.h:123
int Index(void) const
Definition mtsStateIndex.h:93
mtsStateIndex()
Definition mtsStateIndex.h:74
~mtsStateIndex()
Definition mtsStateIndex.h:85
int Length(void) const
Definition mtsStateIndex.h:88
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition cmnClassRegisterMacros.h:199
const int CMN_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:328
Declaration of cmnDeSerializer and functions cmnDeSerializeRaw.
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CMN_LOG_ALLOW_DEFAULT
Definition cmnLogLoD.h:76
Declaration of cmnSerializer and functions cmnSerializeRaw.
Rules of exporting.
Defines mtsGenericObject.