|
Boost : |
From: dylan_at_[hidden]
Date: 2001-11-16 01:42:59
Just a couple of classes I wrote that I wondered if anyone thought
any place in boost:
arguments : simple command-line arguments and options parser:
class arguments
{
public:
arguments(int argc, char* argv[]);
bool has_option(const char* name) const;
bool get_option(const char* name, bool& value) const;
bool get_option(const char* name, int& value) const;
bool get_option(const char* name, float& value) const;
bool get_option(const char* name, double& value) const;
bool get_option(const char* name, const char*& value) const;
bool get_option(const char* name, std::string& value) const;
const char* program() const;
typedef const char* const* iterator;
// first non-option argument
iterator begin() const;
iterator end() const;
private:
int find_option_index(const char* name) const;
int argc_;
char** argv_;
mutable int arga_;
};
Sample usage:
int main(int argc, char* argv[])
{
arguments args(argc, argv);
int key = 0;
args.get_option("key key);
bool verbose = args.has_option("v");
for (arguments::iterator it = args.begin(); it != args.end(); ++it)
encrypt_file(*it, key, verbose);
}
For Windows, it does automatic wildcard expansion, and to do this I
wrote a wildcard finder class, the POSIX version of which is:
struct file_finder
{
file_finder(const char* pattern);
~file_finder();
typedef const char* const* iterator;
operator bool() const;
iterator begin();
iterator end();
private:
glob_t glob_;
};
The Win32 version is somewhat more complex and uses FindFirstFile etc.
but works just the same.
Any interest? Already proposed? Wasting my time?
Thanks
Dylan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk