core.h
Go to the documentation of this file.
#ifndef WIBBLE_COMMANDLINE_CORE_H
#define WIBBLE_COMMANDLINE_CORE_H
#include <wibble/exception.h>
#include <string>
#include <list>
#include <set>
namespace wibble {
namespace exception {
class BadOption : public Consistency
{
std::string m_error;
public:
BadOption(const std::string& error, const std::string& context = std::string("parsing commandline options")) throw ()
: Consistency(context), m_error(error) {}
~BadOption() throw () {}
virtual const char* type() const throw () { return "BadOption"; }
virtual std::string desc() const throw () { return m_error; }
};
}
namespace commandline {
class ArgList : public std::list<std::string>
{
public:
// Remove the item pointed by the iterator, and advance the iterator to the
// next item. Returns i itself.
inline iterator& eraseAndAdvance(iterator& i)
{
if (i == end())
return i;
iterator next = i;
++next;
erase(i);
i = next;
return i;
}
static bool isSwitch(const char* str);
static bool isSwitch(const std::string& str);
static bool isSwitch(const const_iterator& iter);
static bool isSwitch(const iterator& iter);
};
class Managed
{
public:
virtual ~Managed() {}
};
class MemoryManager
{
std::set<Managed*> components;
Managed* addManaged(Managed* o) { components.insert(o); return o; }
public:
~MemoryManager()
{
for (std::set<Managed*>::const_iterator i = components.begin();
i != components.end(); ++i)
delete *i;
}
template<typename T>
T* add(T* item) { addManaged(item); return item; }
};
}
}
// vim:set ts=4 sw=4:
#endif
wibble::commandline::ArgList
Definition: core.h:30
wibble::commandline::ArgList::isSwitch
static bool isSwitch(const char *str)
Definition: core.cpp:36
wibble::commandline::ArgList::eraseAndAdvance
iterator & eraseAndAdvance(iterator &i)
Definition: core.h:34
wibble::commandline::Managed
Definition: core.h:52
wibble::commandline::Managed::~Managed
virtual ~Managed()
Definition: core.h:54
wibble::commandline::MemoryManager
Keep track of various wibble::commandline components, and deallocate them at object destruction.
Definition: core.h:63
wibble::commandline::MemoryManager::~MemoryManager
~MemoryManager()
Definition: core.h:68
wibble::commandline::MemoryManager::add
T * add(T *item)
Definition: core.h:76
wibble::exception::BadOption
Definition: core.h:13
wibble::exception::BadOption::~BadOption
~BadOption()
Definition: core.h:19
wibble::exception::BadOption::type
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: core.h:21
wibble::exception::BadOption::BadOption
BadOption(const std::string &error, const std::string &context=std::string("parsing commandline options"))
Definition: core.h:17
wibble::exception::BadOption::desc
virtual std::string desc() const
Get a string describing what happened that threw the exception.
Definition: core.h:22
wibble::exception::Consistency
Exception thrown when some consistency check fails.
Definition: exception.h:255
wibble::exception::Context::context
const std::vector< std::string > & context() const
Definition: exception.h:166
exception.h
wibble::list::end
ListIterator< List > end(List)
Definition: list.h:425
wibble
Definition: amorph.h:17
wibble::iterator
Iterator< typename I::value_type > iterator(I i)
Definition: iterator.h:123