wibble
1.1
wibble
commandline
core.h
Go to the documentation of this file.
1
#ifndef WIBBLE_COMMANDLINE_CORE_H
2
#define WIBBLE_COMMANDLINE_CORE_H
3
4
#include <
wibble/exception.h
>
5
#include <string>
6
#include <list>
7
#include <set>
8
9
namespace
wibble
{
10
11
namespace
exception {
12
class
BadOption
:
public
Consistency
13
{
14
std::string m_error;
15
16
public
:
17
BadOption
(
const
std::string& error,
const
std::string&
context
= std::string(
"parsing commandline options"
)) throw ()
18
:
Consistency
(
context
), m_error(error) {}
19
~BadOption
() throw () {}
20
21
virtual
const
char
*
type
()
const
throw () {
return
"BadOption"
; }
22
virtual
std::string
desc
()
const
throw () {
return
m_error; }
23
24
};
25
}
26
27
namespace
commandline {
28
29
class
ArgList
:
public
std::list<std::string>
30
{
31
public
:
32
// Remove the item pointed by the iterator, and advance the iterator to the
33
// next item. Returns i itself.
34
inline
iterator
&
eraseAndAdvance
(
iterator
& i)
35
{
36
if
(i ==
end
())
37
return
i;
38
iterator
next = i;
39
++next;
40
erase(i);
41
i = next;
42
return
i;
43
}
44
45
static
bool
isSwitch
(
const
char
* str);
46
static
bool
isSwitch
(
const
std::string& str);
47
static
bool
isSwitch
(
const
const_iterator& iter);
48
static
bool
isSwitch
(
const
iterator
& iter);
49
};
50
51
class
Managed
52
{
53
public
:
54
virtual
~Managed
() {}
55
};
56
62
class
MemoryManager
63
{
64
std::set<Managed*> components;
65
66
Managed
* addManaged(
Managed
* o) { components.insert(o);
return
o; }
67
public
:
68
~MemoryManager
()
69
{
70
for
(std::set<Managed*>::const_iterator i = components.begin();
71
i != components.end(); ++i)
72
delete
*i;
73
}
74
75
template
<
typename
T>
76
T*
add
(T* item) { addManaged(item);
return
item; }
77
};
78
79
}
80
81
}
82
83
// vim:set ts=4 sw=4:
84
#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
Generated by
1.9.1