KJB
|
Wrapper for the libKJB type Word_list (useful for globs). More...
#include <l_word_list.h>
Classes | |
class | const_iterator |
iterator class used to traverse and read the list More... | |
Public Member Functions | |
Word_list (const char *pattern, int(*filter)(const char *)=kjb_c::is_file) | |
Construct by searching for a Glob pattern, seeking files. More... | |
Word_list (const std::string &pattern, int(*filter)(const char *)=kjb_c::is_file) | |
Construct by searching for a Glob pattern, seeking files. More... | |
Word_list (int num_words=0) | |
take non-negative word-count; generate that many empty entries. More... | |
Word_list (int argc, const char *const *argv) | |
construct a word list from an "argv" style array of arguments. More... | |
Word_list (const Word_list &that) | |
copy ctor (slow) creates a deep copy of an existing word list. More... | |
Word_list & | operator= (const Word_list &that) |
assignment operator deep-copies contents of given list. More... | |
size_t | size () const |
Number of entries in the word list (could be empty, though). More... | |
int | count_strings () const |
return the number of non-empty entries in the list More... | |
const kjb_c::Word_list * | c_ptr () const |
Return the underlying C representation (as const) More... | |
size_t | match (const std::string &word) const |
Searches the word list for an entry, looking for an exact match. More... | |
const char * | operator[] (size_t index) const |
Access an entry of the word list; this performs range checking. More... | |
void | append (const std::string &word) |
insert a given string into the list (maybe increasing its size). More... | |
void | trim_empty_entries_at_tail () |
remove all empty entries from back (only) of the list. More... | |
operator std::vector< std::string > () const | |
Convert the word list into a STL vector of STL strings. More... | |
Word_list | operator+ (const Word_list &that) const |
concatenate two word lists More... | |
~Word_list () | |
dtor releases memory of underlying C structure More... | |
const_iterator | begin () const |
synonym for cbegin More... | |
const_iterator | end () const |
synonym for cend More... | |
const_iterator | cbegin () const |
generate, return const_iterator to front of list More... | |
const_iterator | cend () const |
generate, return const_iterator pointing one-past-last entry More... | |
Wrapper for the libKJB type Word_list (useful for globs).
This class is useful mostly because of the glob-related constructors. If you don't need globs, then consider using vector<string> instead. This container does not offer any deletion operations, at least currently. But it does at least offer input iterators.
When you dereference a valid const_iterator generated by this class, the result is like a const char*. For example, the following shows how to produce a very basic directory listing of regular filenames in the current working directory:
A glob(7) is what they call Unix filename pattern-matching expressions, such as "*.cpp" or "/tmp/????.pid" or the like. We wrap function kjb_c::kjb_glob in some of the ctors for this class – please see its man page.
|
inline |
Construct by searching for a Glob pattern, seeking files.
[in] | pattern | A string containing a filename "glob" pattern |
[in] | filter | Optional parameter specifying the kind of directory entry wanted: defaults to kjb_c::is_file, the common choice, but also can be kjb_c::is_directory or others. |
kjb::Result_error | if the file globbing fails (see note). |
kjb::KJB_error | if memory allocation fails. |
|
inline |
Construct by searching for a Glob pattern, seeking files.
[in] | pattern | A string containing a filename "glob" pattern |
[in] | filter | Optional parameter specifying the kind of directory entry wanted: defaults to kjb_c::is_file, the common choice, but also can be kjb_c::is_directory or others. Please see the documentation for the other ctor for further discussion. |
|
inline |
take non-negative word-count; generate that many empty entries.
KJB_error | if anything (such as memory allocation) fails. |
|
inline |
construct a word list from an "argv" style array of arguments.
|
inline |
copy ctor (slow) creates a deep copy of an existing word list.
KJB_error | if anything (such as memory allocation) fails. |
|
inline |
dtor releases memory of underlying C structure
|
inline |
insert a given string into the list (maybe increasing its size).
If the list contains empty entries, the given word will go into the first one encountered. Otherwise the list is reallocated and grown, and the given word goes in the first newly-created entry.
KJB_error | if anything (such as memory allocation) fails. |
|
inline |
synonym for cbegin
|
inline |
Return the underlying C representation (as const)
|
inline |
generate, return const_iterator to front of list
|
inline |
generate, return const_iterator pointing one-past-last entry
|
inline |
return the number of non-empty entries in the list
|
inline |
synonym for cend
|
inline |
Searches the word list for an entry, looking for an exact match.
|
inline |
Convert the word list into a STL vector of STL strings.
concatenate two word lists
assignment operator deep-copies contents of given list.
KJB_error | if anything (such as memory allocation) fails. |
|
inline |
Access an entry of the word list; this performs range checking.
|
inline |
Number of entries in the word list (could be empty, though).
A word list entry might point to a null-terminated string, or it might be empty, i.e., (char*)NULL. This counts all the entries, empty or not.
|
inline |
remove all empty entries from back (only) of the list.