feisty meow concerns codebase
2.140
|
Encapsulates some measures and calculations based on a file's contents. More...
#include <file_info.h>
Public Types | |
enum | file_similarity { EQUAL_NAME = 0 , EQUAL_CHECKSUM = 0x1 , EQUAL_TIMESTAMP = 0x2 , EQUAL_FILESIZE = 0x4 , EQUAL_CHECKSUM_TIMESTAMP_FILESIZE = EQUAL_CHECKSUM & EQUAL_TIMESTAMP & EQUAL_FILESIZE } |
this enum encapsulates how files may be compared. More... | |
Public Types inherited from filesystem::filename | |
enum | write_modes { ALLOW_NEITHER = 0x0 , ALLOW_READ = 0x1 , ALLOW_WRITE = 0x2 , ALLOW_BOTH = ALLOW_READ | ALLOW_WRITE } |
enum | ownership_modes { NO_RIGHTS = 0x0 , USER_RIGHTS = 0x1 , GROUP_RIGHTS = 0x2 , OTHER_RIGHTS = 0x4 , ALL_RIGHTS = USER_RIGHTS | GROUP_RIGHTS | OTHER_RIGHTS } |
enum | directory_separator { pc_separator = '\\' , unix_separator = '/' } |
the default separator for directories per operating system. More... | |
Public Types inherited from basis::astring | |
enum | special_flag { UNTERMINATED = 62 , SPRINTF = 84 } |
enum | how_to_strip { FROM_FRONT = 1 , FROM_END = 2 , FROM_BOTH_SIDES = 3 } |
Public Member Functions | |
file_info () | |
blank constructor. More... | |
file_info (const filename &to_copy, double file_size, const file_time &time=file_time(), int checksum=0) | |
to get the real file size, timestamp and checksum, invoke the calculate method. More... | |
file_info (const file_info &to_copy) | |
virtual | ~file_info () |
DEFINE_CLASS_NAME ("file_info") | |
file_info & | operator= (const file_info &to_copy) |
basis::astring | text_form () const |
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. More... | |
const basis::astring & | secondary () const |
observes the alternate form of the name. More... | |
void | secondary (const basis::astring &new_sec) |
accesses the alternate form of the name. More... | |
const basis::byte_array & | attachment () const |
returns the chunk of data optionally attached to the file's info. More... | |
void | attachment (const basis::byte_array &new_attachment) |
sets the optional chunk of data hooked up to the file's info. More... | |
virtual int | packed_size () const |
Estimates the space needed for the packed structure. More... | |
virtual void | pack (basis::byte_array &packed_form) const |
Creates a packed form of the packable object in "packed_form". More... | |
virtual bool | unpack (basis::byte_array &packed_form) |
Restores the packable from the "packed_form". More... | |
Public Member Functions inherited from filesystem::filename | |
filename () | |
blank constructor. More... | |
filename (const basis::astring &name) | |
creates a filename from any part of a full pathname, if possible. More... | |
filename (const basis::astring &directory, const basis::astring &name_of_file) | |
constructs a filename from a "directory" and the "name_of_file". More... | |
filename (const filename &to_copy) | |
copy constructor. More... | |
DEFINE_CLASS_NAME ("filename") | |
virtual | ~filename () |
bool | good () const |
returns true if the filename seems to be valid. More... | |
void | reset (const basis::astring &name) |
changes the file name held by the object. More... | |
const basis::astring & | raw () const |
returns the astring that we're holding onto for the path. More... | |
basis::astring & | raw () |
accesses the astring that we're holding onto for the path. More... | |
filename & | operator= (const filename &to_copy) |
provides assignment for this object, plus a simple string. More... | |
filename & | operator= (const basis::astring &to_copy) |
provides assignment for this object, plus a simple string. More... | |
void | canonicalize () |
cleans up the filename as needed for the current operating system. More... | |
bool | exists () const |
returns true if the file exists. More... | |
bool | unlink () const |
actually removes the file, if possible. More... | |
filename | parent () const |
returns the parent filename for this one. More... | |
basis::astring | pop () |
removes the deepest component of the pathname. More... | |
void | push (const basis::astring &to_push) |
pushes a new filename onto the current pathname. More... | |
filename | basename () const |
returns the base of the filename; no directory. More... | |
filename | dirname () const |
returns the directory for the filename. More... | |
basis::astring | dirname (bool add_slash) const |
returns the directory for the filename and optionally adds a slash. More... | |
bool | had_directory () const |
returns true if the name that we were given had a non-empty directory. More... | |
char | drive (bool interact_with_fs=false) const |
returns the drive letter for the file, without the colon. More... | |
basis::astring | extension () const |
returns the extension for the file, if one is present. More... | |
basis::astring | rootname () const |
returns the root part of the basename without an extension. More... | |
bool | is_directory () const |
bool | is_writable () const |
bool | is_readable () const |
bool | is_executable () const |
bool | is_normal () const |
bool | chmod (int write_mode, int owner_mode) const |
changes the access rights on the file. More... | |
void | separate (bool &rooted, structures::string_array &pieces) const |
breaks the filename into its component parts. More... | |
void | join (bool rooted, const structures::string_array &pieces) |
undoes a separate() operation to get the filename back. More... | |
bool | compare_prefix (const filename &to_compare, basis::astring &sequel) |
examines "this" filename to see if it's a prefix of "to_compare". More... | |
bool | compare_prefix (const filename &to_compare) |
this simpler form doesn't bother with computing the sequel. More... | |
bool | compare_suffix (const filename &to_compare, basis::astring &prequel) |
compares the back end of a filename to this. More... | |
bool | compare_suffix (const filename &to_compare) |
Public Member Functions inherited from basis::astring | |
astring () | |
constructs an empty string. More... | |
astring (const char *initial) | |
constructs a copy of the string passed in "initial". More... | |
astring (char c, int repeat) | |
constructs a string with "repeat" characters of "c" in it. More... | |
astring (const astring &s) | |
Constructs a copy of the string "s". More... | |
astring (const base_string &initial) | |
constructs a string from the base class. More... | |
astring (special_flag way, const char *s,...) | |
constructor that sports a few variable parameter constructions. More... | |
virtual | ~astring () |
destroys any storage for the string. More... | |
DEFINE_CLASS_NAME ("astring") | |
virtual int | comparator (const astring &s2) const |
helps to fulfill orderable contract. More... | |
int | length () const |
Returns the current length of the string. More... | |
int | end () const |
returns the index of the last (non-null) character in the string. More... | |
bool | empty () const |
empty() reports if the string is empty, that is, of zero length(). More... | |
bool | non_empty () const |
non_empty() reports if the string has some contents. More... | |
bool | operator! () const |
the negation operator returns true if the string is empty. More... | |
bool | t () const |
t() is a shortcut for the string being "true", as in non-empty. More... | |
virtual const char * | observe () const |
observes the underlying pointer to the zero-terminated string. More... | |
const char * | c_str () const |
synonym for observe. mimics the STL method name. More... | |
const char * | s () const |
synonym for observe. the 's' stands for "string", if that helps. More... | |
virtual char | get (int index) const |
a constant peek at the string's internals at the specified index. More... | |
virtual char * | access () |
provides access to the actual string held. More... | |
char * | c_str () |
synonym for access. mimics the STL method. More... | |
char * | s () |
synonym for access. More... | |
char & | operator[] (int position) |
accesses individual characters in "this" string. More... | |
const char & | operator[] (int position) const |
observes individual characters in "this" string. More... | |
virtual void | put (int position, char to_put) |
stores the character "to_put" at index "position" in the string. More... | |
astring & | sprintf (const char *s,...) |
similar to the SPRINTF constructor, but works on an existing string. More... | |
int | convert (int default_value) const |
Converts the string into a corresponding integer. More... | |
long | convert (long default_value) const |
converts the string to a long integer. More... | |
float | convert (float default_value) const |
converts the string to a floating point number. More... | |
double | convert (double default_value) const |
converts the string to a double precision floating point number. More... | |
bool | equal_to (const char *that) const |
returns true if "that" is equal to this. More... | |
bool | iequals (const astring &that) const |
returns true if this is case-insensitively equal to "that". More... | |
bool | iequals (const char *that) const |
returns true if this is case-insensitively equal to "that". More... | |
bool | compare (const astring &to_compare, int start_first, int start_second, int count, bool case_sensitive) const |
Compares "this" string with "to_compare". More... | |
bool | begins (const astring &maybe_prefix) const |
Returns true if "this" string begins with "maybe_prefix". More... | |
bool | ibegins (const astring &maybe_prefix) const |
a case-insensitive method similar to begins(). More... | |
bool | ends (const astring &maybe_suffix) const |
returns true if this string ends with "maybe_suffix". More... | |
bool | iends (const astring &maybe_suffix) const |
astring & | operator= (const astring &s) |
Sets the contents of this string to "s". More... | |
astring & | operator= (const char *s) |
Sets the contents of this string to "s". More... | |
void | reset () |
clears out the contents string. More... | |
void | reset (special_flag way, const char *s,...) |
operates like the constructor that takes a 'special_flag'. More... | |
void | copy (char *to_stuff, int count) const |
Copies a maximum of "count" characters from this into "to_stuff". More... | |
void | stuff (char *to_stuff, int count) const |
a synonym for copy(). More... | |
astring | operator+ (const astring &s) const |
Returns the concatenation of "this" and "s". More... | |
astring & | operator+= (const astring &s) |
Modifies "this" by concatenating "s" onto it. More... | |
astring & | operator+= (const char *s) |
astring | operator+ (const char *s) const |
< synonym for the concatenation operator but uses a char pointer instead. More... | |
astring & | operator+= (char c) |
concatenater for single characters. More... | |
int | find (char to_find, int position=0, bool reverse=false) const |
Locates "to_find" in "this". More... | |
int | find (const astring &to_find, int posn=0, bool reverse=false) const |
finds "to_find" in this string. More... | |
int | ifind (char to_find, int position=0, bool reverse=false) const |
like the find() methods above, but case-insensitive. More... | |
int | ifind (const astring &to_find, int posn=0, bool reverse=false) const |
like the find() methods above, but case-insensitive. More... | |
int | find_any (const char *to_find, int position=0, bool reverse=false) const |
searches for any of the characters in "to_find". More... | |
int | ifind_any (const char *to_find, int position=0, bool reverse=false) const |
searches case-insensitively for any of the characters in "to_find". More... | |
int | find_non_match (const char *to_find, int position=0, bool reverse=false) const |
searches for any character that is not in "to_find" and returns index. More... | |
bool | contains (const astring &to_find) const |
Returns true if "to_find" is contained in this string or false if not. More... | |
bool | substring (astring &target, int start, int end) const |
a version that stores the substring in an existing "target" string. More... | |
astring | substring (int start, int end) const |
Returns the segment of "this" between the indices "start" and "end". More... | |
astring | middle (int start, int count) |
returns the middle of the string from "start" with "count" characters. More... | |
astring | left (int count) |
returns the left "count" characters from the string. More... | |
astring | right (int count) |
returns the right "count" characters from the string. More... | |
void | pad (int length, char padding=' ') |
makes the string "length" characters long. More... | |
void | trim (int length) |
shortens the string to "length" if it's longer than that. More... | |
void | insert (int position, const astring &to_insert) |
Copies "to_insert" into "this" at the "position". More... | |
virtual void | zap (int start, int end) |
Deletes the characters between "start" and "end" inclusively. More... | |
void | to_lower () |
to_lower modifies "this" by replacing capitals with lower-case. More... | |
void | to_upper () |
to_upper does the opposite of to_lower (that is, q becomes Q). More... | |
astring | lower () const |
like to_lower(), but returns a new string rather than modifying this. More... | |
astring | upper () const |
like to_upper(), but returns a new string rather than modifying this. More... | |
bool | replace (const astring &tag, const astring &replacement) |
replaces the first occurrence of "tag" text with the "replacement". More... | |
bool | replace_all (char to_replace, char new_char) |
changes all occurrences of "to_replace" with "new_char". More... | |
bool | replace_all (const astring &to_replace, const astring &new_string) |
void | shrink () |
changes all occurrences of "to_replace" into "new_string". More... | |
void | strip (const astring &strip_list, how_to_strip way=FROM_BOTH_SIDES) |
strips all chars from "strip_list" out of "this" given the "way". More... | |
void | strip_spaces (how_to_strip way=FROM_BOTH_SIDES) |
removes excess space characters from string's beginning, end or both. More... | |
void | strip_white_spaces (how_to_strip way=FROM_BOTH_SIDES) |
like strip_spaces, but includes tabs in the list to strip. More... | |
int | packed_size () const |
Reports the size required to pack this string into a byte array. More... | |
void | pack (byte_array &target) const |
stores this string in the "target". it can later be unpacked again. More... | |
bool | unpack (byte_array &source) |
retrieves a string (packed with pack()) from "source" into this string. More... | |
virtual bool | equal_to (const equalizable &s2) const |
< provides a case insensitive comparison routine. More... | |
virtual bool | less_than (const orderable &s2) const |
virtual base_string & | concatenate_string (const base_string &s) |
Modifies "this" by concatenating "s" onto it. More... | |
virtual base_string & | concatenate_char (char c) |
concatenater for single characters. More... | |
virtual base_string & | assign (const base_string &s) |
Sets the contents of this string to "s". More... | |
virtual base_string & | upgrade (const char *s) |
Sets the contents of this string to "s". More... | |
virtual bool | sub_string (base_string &target, int start, int end) const |
Gets the segment of "this" between the indices "start" and "end". More... | |
virtual bool | sub_compare (const base_string &to_compare, int start_first, int start_second, int count, bool case_sensitive) const |
Compares "this" string with "to_compare". More... | |
virtual void | insert (int position, const base_string &to_insert) |
Copies "to_insert" into "this" at the "position". More... | |
virtual void | text_form (base_string &state_fill) const |
Provides a text view of all the important info owned by this object. More... | |
astring & | base_sprintf (const char *s, va_list &args) |
byte_array & | get_implementation () |
Public Member Functions inherited from basis::base_string | |
virtual base_string & | operator= (const base_string &to_copy) |
sets this string's contents equal to the contents of "to_copy". More... | |
Public Member Functions inherited from basis::orderable | |
virtual bool | operator< (const orderable &s2) const |
the virtual method for object ordering. More... | |
Public Member Functions inherited from basis::equalizable | |
virtual bool | operator== (const equalizable &s2) const |
the virtual method for object equality. More... | |
Public Member Functions inherited from basis::text_formable | |
virtual const char * | class_name () const =0 |
Returns the bare name of this class as a constant character pointer. More... | |
Public Attributes | |
double | _file_size |
the size of the file. More... | |
file_time | _time |
the file's access time. More... | |
int | _checksum |
the checksum for the file. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from filesystem::filename | |
static bool | separator (char is_it) |
returns true if the character "is_it" in question is a separator. More... | |
static basis::astring | default_separator () |
returns the default separator character for this OS. More... | |
static bool | legal_character (char to_check) |
returns true if "to_check" is a valid character in a filename. More... | |
static void | detooth_filename (basis::astring &to_clean, char replacement='_') |
takes any known illegal file system characters out of "to_clean". More... | |
static basis::astring | null_device () |
returns the name for the black hole device that consumes all input, i.e. /dev/null. More... | |
Static Public Member Functions inherited from basis::astring | |
static const astring & | empty_string () |
useful wherever empty strings are needed, e.g., function defaults. More... | |
static bool | matches (const astring &match_list, char to_match) |
returns true if "to_match" is found in the "match_list" string. More... | |
Encapsulates some measures and calculations based on a file's contents.
Definition at line 28 of file file_info.h.
this enum encapsulates how files may be compared.
Enumerator | |
---|---|
EQUAL_NAME | |
EQUAL_CHECKSUM | |
EQUAL_TIMESTAMP | |
EQUAL_FILESIZE | |
EQUAL_CHECKSUM_TIMESTAMP_FILESIZE |
Definition at line 32 of file file_info.h.
filesystem::file_info::file_info | ( | ) |
blank constructor.
Definition at line 38 of file file_info.cpp.
filesystem::file_info::file_info | ( | const filename & | to_copy, |
double | file_size, | ||
const file_time & | time = file_time() , |
||
int | checksum = 0 |
||
) |
to get the real file size, timestamp and checksum, invoke the calculate method.
Definition at line 47 of file file_info.cpp.
filesystem::file_info::file_info | ( | const file_info & | to_copy | ) |
Definition at line 57 of file file_info.cpp.
|
virtual |
Definition at line 67 of file file_info.cpp.
const byte_array & filesystem::file_info::attachment | ( | ) | const |
returns the chunk of data optionally attached to the file's info.
this supports extending the file's record with extra data that might be needed during processing.
Definition at line 69 of file file_info.cpp.
void filesystem::file_info::attachment | ( | const basis::byte_array & | new_attachment | ) |
sets the optional chunk of data hooked up to the file's info.
Definition at line 71 of file file_info.cpp.
bool filesystem::file_info::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.
note that the file must exist for this to work. if "just_size_n_time" is true, then the checksum is not calculated. if the "prefix" is not empty, then it is used as a directory path that needs to be added to the filename to make it completely valid. this is common if the filename is stored relative to a path. the "checksum_edge" is used for checksum calculations; only 2 * checksum_edge bytes will be factored in, each part from the head and tail ends of the file.
Definition at line 87 of file file_info.cpp.
References _checksum, _file_size, _time, basis::astring::astring(), filesystem::filename::exists(), filesystem::byte_filer::FROM_START, FUNCDEF, filesystem::huge_file::good(), filesystem::huge_file::length(), basis::array< contents >::length(), LOG, basis::minimum(), basis::array< contents >::observe(), filesystem::huge_file::OKAY, filesystem::filename::raw(), filesystem::huge_file::read(), filesystem::huge_file::seek(), and basis::astring::t().
Referenced by filesystem::directory_tree::add_path(), and filesystem::directory_tree::compare_trees().
filesystem::file_info::DEFINE_CLASS_NAME | ( | "file_info" | ) |
Definition at line 220 of file file_info.cpp.
References _checksum, _file_size, and _time.
|
virtual |
Creates a packed form of the packable object in "packed_form".
This must append to the data in "packed_form" rather than clearing prior contents.
Reimplemented from filesystem::filename.
Definition at line 192 of file file_info.cpp.
References _checksum, _file_size, _time, basis::attach(), FUNCDEF, filesystem::file_time::pack(), filesystem::filename::pack(), and basis::astring::pack().
|
virtual |
Estimates the space needed for the packed structure.
Reimplemented from filesystem::filename.
Definition at line 182 of file file_info.cpp.
References _file_size, _time, basis::astring::packed_size(), filesystem::file_time::packed_size(), filesystem::filename::packed_size(), structures::packed_size(), and structures::PACKED_SIZE_INT32.
const astring & filesystem::file_info::secondary | ( | ) | const |
observes the alternate form of the name.
Definition at line 74 of file file_info.cpp.
Referenced by filesystem::directory_tree::compare_trees().
void filesystem::file_info::secondary | ( | const basis::astring & | new_sec | ) |
accesses the alternate form of the name.
Definition at line 76 of file file_info.cpp.
astring filesystem::file_info::text_form | ( | ) | const |
Definition at line 78 of file file_info.cpp.
References _checksum, _file_size, basis::astring::astring(), filesystem::filename::raw(), and basis::astring::t().
Referenced by filesystem::directory_tree::compare_trees().
|
virtual |
Restores the packable from the "packed_form".
This object becomes the unpacked form, and therefore must lose any of its prior contents that depend on the data in "packed_form". This is up to the derived unpack function to figure out. The "packed_form" is modified by extracting all of the pieces that are used for this object; the remainder stays in "packed_form". true is returned if the unpacking was successful.
Reimplemented from filesystem::filename.
Definition at line 203 of file file_info.cpp.
References _checksum, _file_size, _time, basis::detach(), filesystem::file_time::unpack(), filesystem::filename::unpack(), and basis::astring::unpack().
int filesystem::file_info::_checksum |
the checksum for the file.
Definition at line 42 of file file_info.h.
Referenced by calculate(), filesystem::filename_list::member_with_state(), operator=(), pack(), text_form(), and unpack().
double filesystem::file_info::_file_size |
the size of the file.
Definition at line 40 of file file_info.h.
Referenced by calculate(), filesystem::filename_list::member_with_state(), operator=(), pack(), packed_size(), text_form(), and unpack().
file_time filesystem::file_info::_time |
the file's access time.
Definition at line 41 of file file_info.h.
Referenced by filesystem::heavy_file_operations::buffer_files(), calculate(), filesystem::filename_list::member_with_state(), operator=(), pack(), packed_size(), and unpack().