Nebula
Loading...
Searching...
No Matches
posixfiletime.h
Go to the documentation of this file.
1#pragma once
2#ifndef POSIX_POSIXFILETIME_H
3#define POSIX_POSIXFILETIME_H
4//------------------------------------------------------------------------------
13#include "core/types.h"
14
15//------------------------------------------------------------------------------
16namespace Posix
17{
19{
20public:
24 PosixFileTime(const Util::String& str);
26 PosixFileTime(uint64_t epochTime);
28 friend bool operator==(const PosixFileTime& a, const PosixFileTime& b);
30 friend bool operator!=(const PosixFileTime& a, const PosixFileTime& b);
32 friend bool operator>(const PosixFileTime& a, const PosixFileTime& b);
34 friend bool operator<(const PosixFileTime& a, const PosixFileTime& b);
35
37 uint GetHighBits() const;
39 uint GetLowBits() const;
41 void SetBits(uint lowbits, uint highbits);
42
44 Util::String AsString() const;
46 uint64_t AsEpochTime() const;
48 void SetFromEpochTime(uint64_t epochTime);
49
50private:
51 friend class PosixFSWrapper;
52 friend class PosixCalendarTime;
53
54 timespec time;
55};
56
57//------------------------------------------------------------------------------
60inline
62{
63 time.tv_sec = 0;
64 time.tv_nsec = 0;
65}
66
67//------------------------------------------------------------------------------inline
71{
72 this->SetFromEpochTime(epochTime);
73}
74
75//------------------------------------------------------------------------------
78inline uint
80{
81 return this->time.tv_sec;
82}
83
84//------------------------------------------------------------------------------
87inline uint
89{
90 return this->time.tv_nsec;
91}
92
93//------------------------------------------------------------------------------
96inline void
98{
99 this->time.tv_nsec = lowbits;
100 this->time.tv_sec = highbits;
101}
102//------------------------------------------------------------------------------
105inline bool
107{
108 return (a.time.tv_sec == b.time.tv_sec) && (a.time.tv_nsec == b.time.tv_nsec);
109}
110
111//------------------------------------------------------------------------------
114inline bool
116{
117 return (a.time.tv_sec != b.time.tv_sec) || (a.time.tv_nsec != b.time.tv_nsec);
118}
119
120//------------------------------------------------------------------------------
123inline bool
125{
126 if (a.time.tv_sec < b.time.tv_sec) return false;
127 if (a.time.tv_sec > b.time.tv_sec) return true;
128 if (a.time.tv_nsec > b.time.tv_nsec) return true;
129 return false;
130}
131
132//------------------------------------------------------------------------------
135inline bool
136operator <(const PosixFileTime& a, const PosixFileTime& b)
137{
138 if (a.time.tv_sec > b.time.tv_sec) return false;
139 if (a.time.tv_sec < b.time.tv_sec) return true;
140 if (a.time.tv_nsec < b.time.tv_nsec) return true;
141 return false;
142}
143
144//------------------------------------------------------------------------------inline void
148{
149 this->time.tv_sec = epochTime / 1000ULL;
150 this->time.tv_nsec = (epochTime % 1000ULL) * 1000000ULL;
151}
152
153//------------------------------------------------------------------------------inline uint64_t
157{
158 return (this->time.tv_sec * 1000ULL) + (this->time.tv_nsec / 1000000ULL);
159}
160
161
162}; // namespace Posix
163//------------------------------------------------------------------------------
164#endif
165
void SetFromEpochTime(uint64_t epochTime)
set from epoch time
Definition posixfiletime.h:147
uint GetLowBits() const
get log bits of internal time structure (resolution is platform dependent!)
Definition posixfiletime.h:88
void SetBits(uint lowbits, uint highbits)
set both parts of time (platform dependent)
Definition posixfiletime.h:97
friend class PosixFSWrapper
Definition posixfiletime.h:51
friend bool operator<(const PosixFileTime &a, const PosixFileTime &b)
operator <
Definition posixfiletime.h:136
uint GetHighBits() const
get high bits of internal time structure (resolution is platform dependent!)
Definition posixfiletime.h:79
friend bool operator>(const PosixFileTime &a, const PosixFileTime &b)
operator >
Definition posixfiletime.h:124
uint64_t AsEpochTime() const
convert to epoch time
Definition posixfiletime.h:156
friend bool operator!=(const PosixFileTime &a, const PosixFileTime &b)
operator !=
Definition posixfiletime.h:115
timespec time
Definition posixfiletime.h:54
PosixFileTime()
constructor
Definition posixfiletime.h:61
friend class PosixCalendarTime
Definition posixfiletime.h:52
friend bool operator==(const PosixFileTime &a, const PosixFileTime &b)
operator ==
Definition posixfiletime.h:106
Util::String AsString() const
convert to string
Definition posixfiletime.cc:25
Posix implemention of a read-many write-few lock.
Definition posixsysfunc.cc:21
bool operator==(const PosixFileTime &a, const PosixFileTime &b)
Definition posixfiletime.h:106
bool operator>(const PosixFileTime &a, const PosixFileTime &b)
Definition posixfiletime.h:124
bool operator<(const PosixFileTime &a, const PosixFileTime &b)
Definition posixfiletime.h:136
bool operator!=(const PosixFileTime &a, const PosixFileTime &b)
Definition posixfiletime.h:115
Nebula's universal string class.
Definition String.cs:8
unsigned int uint
Definition types.h:33