-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadTimestamp.h
More file actions
executable file
·117 lines (97 loc) · 4.04 KB
/
ReadTimestamp.h
File metadata and controls
executable file
·117 lines (97 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* @file ReadTimestamp.h
* @ingroup DataManagement
* @author Dominique Vaufreydaz, Grenoble Alpes University, Inria
* @copyright All right reserved.
*/
#ifndef __READ_TIMESTAMP__
#define __READ_TIMESTAMP__
#include <stdio.h>
#include <string>
#include <System/TemporaryMemoryBuffer.h>
#include "DataFile.h"
#include "TimestampTools.h"
namespace MobileRGBD {
/**
* @class ReadTimestamp ReadTimestamp.cpp ReadTimestamp.h
* @brief Read timestamp files, i.e. files with timestamp at beginning of each line.
* Timestamp are time in seconds since origine (usually epoch time) dot milliseconds.
* The rest of the line, if any, is ignored. Timestamp *must* be ordered.
* This is an example of such file
* @code
* 1433341728.727 // Wed, 03 Jun 2015 14:28:48.727 GMT
* 1433341728.743
* 1433341728.805
* 1433341728.868
* 1433341728.899
* @endcode
*
* @author Dominique Vaufreydaz, Grenoble Alpes University, Inria
*/
class ReadTimestamp
{
public:
static const size_t DefaultLineBufferSize; /*!< @brief Default buffer size for line reading (default 10 MiB) */
static const unsigned short int DefaultValidityTimeInMs; /*!< @brief When searching for a specified timestamp, DefaultValidityTimeInMs specifies a threshold to for validity (33ms). */
/** @brief Constructor. Create a ReadTimeStamp object using specific file.
*
* @param FileName [in] Name of the file to open (even with '/' separator under Windows as Windows handles it also as a folder/file separator).
* @param SizeOfLineBuffer [in] Size of buffer to read each line of the file (default=DefaultLineBufferSize).
*/
ReadTimestamp( const std::string& FileName, size_t SizeOfLineBuffer = (size_t)DefaultLineBufferSize );
/** @brief virtual destructor (always).
*/
virtual ~ReadTimestamp();
/** @brief Restart file at beginning (if file is closed, file is re-opened).
*/
virtual void Reinit();
/** @brief Close file.
*/
void Close();
/** @brief Search for a specific timestamp in the file.
*
* @param RequestedTimestamp [in] Timestamp to search for.
* @param ValidityTimeInMs [in]
* @return Searching for a line starting with the RequestedTimestamp. Return true if this line exists. If the previous timestamp is less than ValidityTimeInMs ms before,
it is considered as valid (for synchronous read of several files). In all other cases, return false;
*/
virtual bool SearchDataForTimestamp( const TimeB &RequestedTimestamp, unsigned short int ValidityTimeInMs = (unsigned short int)DefaultValidityTimeInMs );
/** @brief Get the next timestamp of the file if any.
*
* @return True is the next timestamp has been retrieve.
*/
virtual bool GetNextTimestamp();
/** @brief Get the next timestamp of the file if any.
*
* @return True is the previous timestamp has been retrieve.
*/
bool GetPreviousTimestamp();
/** @brief Rewind if possible to the previous timestamp.
*
* @return True is the rewind was possible and done.
*/
bool Rewind();
char* LineBuffer; /*!< @brief Buffer to read the line. */
int LineBufferSize; /*!< @brief Actual size of the line buffer. */
int EndOfTimestampPosition; /*!< @brief Actual size of the line buffer. */
TimeB CurrentTimestamp; /*!< @brief Current value for the timestamp extracted from the file. */
bool CurrentTimestampIsInitialized; /*!< @brief CurrentTimestamp is valid. */
protected:
/** @brief Retrieve position of the current timestamp in the file (for the Rewind method).
*
*/
void AddTimestampPos()
{
if ( fin != (FILE*)NULL )
{
PreviousTimestampPosInFile[0] = PreviousTimestampPosInFile[1];
PreviousTimestampPosInFile[1] = ftell( fin );
}
}
DataFile fin; /*!< @brief DataFile object to read usual or compressed files. */
std::string FiletoOpen; /*!< @brief Store the file name. */
long int PreviousTimestampPosInFile[2]; /*!< @brief Store previous position in file in order to permit rewind. */
TimeB PreviousTimestamp; /*!< @brief Value of the preivous timestamp. */
};
} // namespace MobileRGBD
#endif // __READ_TIMESTAMP__