first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / filesystem / filename_list.h
1 #ifndef FILENAME_LIST_CLASS
2 #define FILENAME_LIST_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : filename_list                                                     *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 2005-$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 //! Implements a list of filenames.
19 /*!
20   This is based on an amorph so that adding to the list is efficient.
21   The underlying type held is actually a file_info rather than a filename.
22   This should not impose much extra overhead.
23
24   Note: this is a heavyweight header; it shouldn't be used in other headers.
25 */
26
27 #include "file_info.h"
28
29 #include <basis/contracts.h>
30 #include <structures/amorph.h>
31
32 namespace filesystem {
33
34 class filename_list
35 : public structures::amorph<file_info>, public virtual basis::packable
36 {
37 public:
38   filename_list();
39
40   filename_list &operator =(const filename_list &to_copy);
41
42   int total_files() const;
43     //!< returns the number of files currently held in the list.
44
45   double total_size() const;
46     //!< returns the full size of all files listed.
47
48   bool calculate_progress(const filename &file, double current_offset,
49       int &current_file, double &current_size);
50     //!< given the last "file" and position, this returns current positioning.
51     /*!< the "current_file" is set to the index of the "file" in the list
52     (using 1-based numbering for a 1,2,3,... series), and the "current_size"
53     is set to the total amount of bytes processed so far. */
54
55   filename_list &operator = (const structures::string_array &to_copy);
56
57   void fill(structures::string_array &to_fill);
58     //!< stuffs the array "to_fill" with the filesnames from our list.
59
60   const file_info *find(const filename &to_check) const;
61     //!< locates the record of information for the filename "to_check".
62     /*!< do not modify the returned object.  it contains the current state
63     of the file in question.  if the file wasn't in the list, then NIL is
64     returned. */
65
66   int locate(const filename &to_find) const;
67     //! finds the index for "to_find" or returns a negative number.
68
69   bool member(const filename &to_check) const;
70     //!< returns true if "to_check" is listed here.
71
72   bool member_with_state(const file_info &to_check, file_info::file_similarity comparison_method);
73     //!< returns true if the file "to_check" exists in the list with appropriate equivalence.
74     /*!< this will fail if the file name isn't present at all.  and then it will also not return
75     true if the size is different (when EQUAL_FILESIZE is true), when the timestamp is different
76     (when EQUAL_TIMESTAMP is true), and when the checksum is different (you get the idea). */
77
78   basis::astring text_form() const;
79
80   virtual int packed_size() const;
81
82   virtual void pack(basis::byte_array &packed_form) const;
83
84   virtual bool unpack(basis::byte_array &packed_form);
85 };
86
87 } //namespace.
88
89 #endif
90