feisty meow concerns codebase  2.140
file_info.h
Go to the documentation of this file.
1 #ifndef FILE_INFO_CLASS
2 #define FILE_INFO_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : file_info *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1993-$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 
18 #include "filename.h"
19 #include "file_time.h"
20 
21 #include <basis/definitions.h>
22 #include <basis/enhance_cpp.h>
23 
24 namespace filesystem {
25 
27 
28 class file_info : public filename
29 {
30 public:
33  EQUAL_NAME = 0, // we assume name equality is pre-eminent and always required.
34  EQUAL_CHECKSUM = 0x1, // the files have the same checksum, however computed.
35  EQUAL_TIMESTAMP = 0x2, // the files have exactly equal timestamps.
36  EQUAL_FILESIZE = 0x4, // the files have the same sizes.
38  };
39 
40  double _file_size;
42  int _checksum;
43 
44  file_info();
45 
46  file_info(const filename &to_copy, double file_size,
47  const file_time &time = file_time(), int checksum = 0);
49 
50  file_info(const file_info &to_copy);
51 
52  virtual ~file_info();
53 
54  DEFINE_CLASS_NAME("file_info");
55 
56  file_info &operator = (const file_info &to_copy);
57 
58  basis::astring text_form() const;
59 
60  bool calculate(const basis::astring &prefix, bool just_size_n_time,
61  int checksum_edge = 1 * basis::KILOBYTE);
63 
71  const basis::astring &secondary() const;
73  void secondary(const basis::astring &new_sec);
75 
76  const basis::byte_array &attachment() const;
78 
80  void attachment(const basis::byte_array &new_attachment);
82 
83  // standard streaming operations.
84  virtual int packed_size() const;
85  virtual void pack(basis::byte_array &packed_form) const;
86  virtual bool unpack(basis::byte_array &packed_form);
87 
88 private:
89  basis::astring c_secondary;
90  basis::byte_array c_attachment;
91 };
92 
93 } //namespace.
94 
95 #endif
96 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Encapsulates some measures and calculations based on a file's contents.
Definition: file_info.h:29
double _file_size
the size of the file.
Definition: file_info.h:40
file_info()
blank constructor.
Definition: file_info.cpp:38
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
Definition: file_info.cpp:192
const basis::astring & secondary() const
observes the alternate form of the name.
Definition: file_info.cpp:74
int _checksum
the checksum for the file.
Definition: file_info.h:42
file_time _time
the file's access time.
Definition: file_info.h:41
bool calculate(const basis::astring &prefix, bool just_size_n_time, int checksum_edge=1 *basis::KILOBYTE)
fills in the correct file size and checksum information for this file.
Definition: file_info.cpp:87
basis::astring text_form() const
Definition: file_info.cpp:78
file_similarity
this enum encapsulates how files may be compared.
Definition: file_info.h:32
@ EQUAL_CHECKSUM_TIMESTAMP_FILESIZE
Definition: file_info.h:37
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
Definition: file_info.cpp:203
virtual int packed_size() const
Estimates the space needed for the packed structure.
Definition: file_info.cpp:182
file_info & operator=(const file_info &to_copy)
Definition: file_info.cpp:220
DEFINE_CLASS_NAME("file_info")
const basis::byte_array & attachment() const
returns the chunk of data optionally attached to the file's info.
Definition: file_info.cpp:69
Provides operations commonly needed on file names.
Definition: filename.h:64
Constants and objects used throughout HOOPLE.
const int KILOBYTE
Number of bytes in a kilobyte.
Definition: definitions.h:134
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37