| Disk ARchive 2.5.10 Full featured and portable backup and archiving tool

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

datetime.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21
25
26 #ifndef DATETIME_HPP
27 #define DATETIME_HPP
28
29 extern "C"
30 {
31 #if HAVE_SYS_TYPES_H
32 #include <sys/types.h>
33 #endif
34
35 #if HAVE_UTIME_H
36 #include <utime.h>
37 #endif
38
39 #if HAVE_SYS_TIME_H
40 #include <sys/time.h>
41 #endif
42
43 } // end extern "C"
44
45 #include "../my_config.h"
46 #include "on_pool.hpp"
47 #include "infinint.hpp"
48 #include "archive_version.hpp"
49
50 namespace libdar
51 {
54
55 class datetime : public on_pool
56 {
57 public:
58 // time units must be sorted: the first is the smallest step, last is the largest increment.
59 // this makes the comparison operators (<, >, <=, >=,...) become naturally defined on that type
60 enum time_unit { tu_nanosecond, tu_microsecond, tu_second };
61
63 datetime(const infinint & value = 0) { val = value; uni = tu_second; };
64
70 datetime(time_t second, time_t subsec, time_unit unit);
71
73 datetime(generic_file &x, archive_version ver) { read(x, ver); };
74
75 // comparison operators
76
77 bool operator < (const datetime & ref) const;
78 bool operator == (const datetime & ref) const;
79 bool operator != (const datetime & ref) const { return ! (*this == ref); };
80 bool operator >= (const datetime & ref) const { return ! (*this < ref); };
81 bool operator > (const datetime & ref) const { return ref < *this; };
82 bool operator <= (const datetime & ref) const { return ref >= *this; };
83
84 // arithmetic on time
85 void operator -= (const datetime & ref);
86 void operator += (const datetime & ref);
87 datetime operator - (const datetime & ref) const { datetime tmp(*this); tmp -= ref; return tmp; };
88 datetime operator + (const datetime & ref) const { datetime tmp(*this); tmp += ref; return tmp; };
89
91 bool loose_equal(const datetime & ref) const;
92
94 datetime loose_diff(const datetime & ref) const;
95
97 infinint get_second_value() const { infinint sec, sub; get_value(sec, sub, uni); return sec; };
98
100 infinint get_subsecond_value(time_unit unit) const;
101
103 time_unit get_unit() const { return uni; };
104
111 bool get_value(time_t & second, time_t & subsecond, time_unit unit) const;
112
113
115 void dump(generic_file &x) const;
116
118 void read(generic_file &f, archive_version ver);
119
121 bool is_null() const { return val.is_zero(); };
122
124 bool is_integer_second() const { return (uni == tu_second); };
125
127 infinint get_storage_size() const;
128
130 void nullify() { val = 0; uni = tu_second ; };
131
132 private:
133 // the date must not be stored as a single integer
134 // to avoid reducing the possible addressable dates
135 // when compiling using 32 or 64 bits integer in place
136 // of infinint. The fraction cannot handle smaller unit
137 // than nanosecond if using 32 bits integer.
138
139 infinint val; //< the date expressed in the "uni" time unit
140 time_unit uni; //< the time unit used to store the subsecond fraction of the timestamp.
141
143 void reduce_to_largest_unit() const;
144 void get_value(infinint & sec, infinint & sub, time_unit unit) const;
145 void build(const infinint & sec, const infinint & sub, time_unit unit);
146
147 static time_unit min(time_unit a, time_unit b);
148 static time_unit max(time_unit a, time_unit b);
149 static const char time_unit_to_char(time_unit a);
150 static time_unit char_to_time_unit(const char a);
151
156 static const infinint & get_scaling_factor(time_unit source, time_unit dest);
157
158 };
159
161 extern archive_version db2archive_version(unsigned char db_version);
162
163
165
166 } // end of namespace
167
168 #endif
libdar::operator+=
std::vector< T > operator+=(std::vector< T > &a, const std::vector< T > &b)
template function to add two vectors
Definition: tools.hpp:332
libdar::db2archive_version
archive_version db2archive_version(unsigned char db_version)
converts dar_manager database version to dar archive version in order to properly read time fields ...
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
archive_version.hpp
class archive_version that rules which archive format to follow
on_pool.hpp
this is the base class of object that can be allocated on a memory pool
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47