paludis  Version 2.2.0
timestamp.hh
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 2009 Ciaran McCreesh
5  *
6  * This file is part of the Paludis package manager. Paludis is free software;
7  * you can redistribute it and/or modify it under the terms of the GNU General
8  * Public License version 2, as published by the Free Software Foundation.
9  *
10  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17  * Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_TIMESTAMP_HH
21 #define PALUDIS_GUARD_PALUDIS_UTIL_TIMESTAMP_HH 1
22 
23 #include <paludis/util/timestamp-fwd.hh>
24 #include <paludis/util/operators.hh>
26 #include <sys/stat.h>
27 #include <sys/time.h>
28 
29 namespace paludis
30 {
31  /**
32  * Wrapper class to simplify dealing with the zillion different ways C has
33  * of dealing with timestamps.
34  *
35  * Most definitely not for use for durations (that is, the difference
36  * between two date-times).
37  *
38  * \since 0.44
39  */
42  {
43  private:
44  time_t _s;
45  long _ns;
46 
47  public:
48  explicit Timestamp(const struct timespec &);
49  Timestamp(const time_t, const long);
50  Timestamp(const Timestamp &);
51 
52  Timestamp & operator= (const Timestamp &);
53 
54  bool operator== (const Timestamp &) const PALUDIS_ATTRIBUTE((warn_unused_result));
55  bool operator< (const Timestamp &) const PALUDIS_ATTRIBUTE((warn_unused_result));
56 
57  time_t seconds() const PALUDIS_ATTRIBUTE((warn_unused_result));
58  long nanoseconds() const PALUDIS_ATTRIBUTE((warn_unused_result));
59 
60  struct timespec as_timespec() const PALUDIS_ATTRIBUTE((warn_unused_result));
61  struct timeval as_timeval() const PALUDIS_ATTRIBUTE((warn_unused_result));
62 
63  static Timestamp now() PALUDIS_ATTRIBUTE((warn_unused_result));
64  };
65 }
66 
67 #endif
Definition: about_metadata-fwd.hh:23
Definition: timestamp.hh:40
#define PALUDIS_ATTRIBUTE(x)
Definition: attributes.hh:64
#define PALUDIS_VISIBLE
Definition: attributes.hh:71
bool operator==(const PackageID &, const PackageID &) PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE