feisty meow concerns codebase  2.140
file_time.h
Go to the documentation of this file.
1 #ifndef FILE_TIME_CLASS
2 #define FILE_TIME_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : file_time *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1992-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
19 
20 #include <basis/astring.h>
21 #include <basis/byte_array.h>
22 #include <basis/contracts.h>
23 
24 #include <stdio.h>
25 #include <time.h>
26 
27 namespace filesystem {
28 
29 class file_time
30 : public virtual basis::hoople_standard,
31  public virtual basis::orderable
32 {
33 public:
34  file_time();
35 
36  file_time(FILE *the_FILE);
38 
43 
44  file_time(const time_t &init);
46 
47 //hmmm: need a converter that sucks in an earth_time time_locus object.
48 
49  virtual ~file_time();
50 
51  DEFINE_CLASS_NAME("file_time");
52 
53  virtual void text_form(basis::base_string &time_string) const;
55 
56  virtual void readable_text_form(basis::base_string &time_string) const;
58 
59  void reset(FILE *the_FILE);
61 
65  void reset(const basis::astring &filename);
67 
68  void reset(const time_t &init);
70 
71  time_t raw() const { return _when; }
73 
74  bool set_time(const basis::astring &filename);
76 
77  // Standard comparison operators between this file time and the file time
78  // "ft2". These are meaningless if either time is invalid.
79  virtual bool less_than(const basis::orderable &ft2) const;
80  virtual bool equal_to(const basis::equalizable &ft2) const;
81 
82  // supports streaming the time into and out of a byte array.
83  virtual int packed_size() const;
84  virtual void pack(basis::byte_array &packed_form) const;
85  virtual bool unpack(basis::byte_array &packed_form);
86 
87 private:
88  time_t _when;
89 
90  int compare(const file_time &ft2) const;
92 };
93 
94 } //namespace.
95 
96 #endif
97 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Defines the base class for all string processing objects in hoople.
Definition: base_string.h:28
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Base class for object that can tell itself apart from other instances.
Definition: contracts.h:44
the base class of the most easily used and tested objects in the library.
Definition: contracts.h:161
A base for objects that can be alphabetically (lexicographically) ordered.
Definition: contracts.h:57
bool set_time(const basis::astring &filename)
sets the time for the the "filename" to the currently held time.
Definition: file_time.cpp:59
virtual bool equal_to(const basis::equalizable &ft2) const
Definition: file_time.cpp:109
virtual bool less_than(const basis::orderable &ft2) const
Definition: file_time.cpp:102
virtual int packed_size() const
Definition: file_time.cpp:132
virtual void pack(basis::byte_array &packed_form) const
Definition: file_time.cpp:134
virtual void text_form(basis::base_string &time_string) const
returns a definitive but sorta ugly version of the file's time.
Definition: file_time.cpp:116
void reset(FILE *the_FILE)
reacquires the time from a different FILE than constructed with.
Definition: file_time.cpp:80
time_t raw() const
provides the OS version of the file's timestamp.
Definition: file_time.h:71
virtual void readable_text_form(basis::base_string &time_string) const
sets "time_string" to a human readable form of the file's time.
Definition: file_time.cpp:121
DEFINE_CLASS_NAME("file_time")
virtual bool unpack(basis::byte_array &packed_form)
Definition: file_time.cpp:137
file_time()
sets up a bogus file_time object.
Definition: file_time.cpp:41
Provides operations commonly needed on file names.
Definition: filename.h:64
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37