aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-19 21:21:29 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-19 21:21:29 +0000
commitdd28ac10ae9d9ef7e9fe893e3a21c637db85272f (patch)
treeae77056f4587b9fbb095387e1fc3ed85408ccd9b
parent09849ab2e660ce87faf80055e86ea29e123dd948 (diff)
downloadpaludis-dd28ac10ae9d9ef7e9fe893e3a21c637db85272f.tar.gz
paludis-dd28ac10ae9d9ef7e9fe893e3a21c637db85272f.tar.xz
Tidy up args a bit
-rw-r--r--paludis/args/args_dumper.hh2
-rw-r--r--paludis/args/args_group.cc26
-rw-r--r--paludis/args/args_group.hh47
-rw-r--r--paludis/args/args_handler.cc3
-rw-r--r--paludis/args/args_option.cc2
5 files changed, 56 insertions, 24 deletions
diff --git a/paludis/args/args_dumper.hh b/paludis/args/args_dumper.hh
index 34ba0a1..494ccb2 100644
--- a/paludis/args/args_dumper.hh
+++ b/paludis/args/args_dumper.hh
@@ -21,7 +21,7 @@
#ifndef PALUDIS_GUARD_PALUDIS_ARGS_ARGS_DUMPER_HH
#define PALUDIS_GUARD_PALUDIS_ARGS_ARGS_DUMPER_HH 1
-#include <ostream>
+#include <iosfwd>
#include <paludis/args/args_visitor.hh>
#include <paludis/util/visitor.hh>
diff --git a/paludis/args/args_group.cc b/paludis/args/args_group.cc
index 593e3e7..eb428a7 100644
--- a/paludis/args/args_group.cc
+++ b/paludis/args/args_group.cc
@@ -18,6 +18,7 @@
*/
#include "args.hh"
+#include <list>
/** \file
* Implementation for ArgsGroup.
@@ -27,7 +28,18 @@
using namespace paludis::args;
+namespace paludis
+{
+ template<>
+ struct Implementation<ArgsGroup> :
+ InternalCounted<ArgsGroup>
+ {
+ std::list<ArgsOption *> args_options;
+ };
+}
+
ArgsGroup::ArgsGroup(ArgsHandler * h, const std::string & name) :
+ PrivateImplementationPattern<ArgsGroup>(new Implementation<ArgsGroup>),
_name(name),
_handler(h)
{
@@ -38,10 +50,22 @@ void
ArgsGroup::add(ArgsOption * const value)
{
/// \bug Should check for uniqueness of short and long names.
- _args_options.push_back(value);
+ _imp->args_options.push_back(value);
}
ArgsGroup::~ArgsGroup()
{
}
+ArgsGroup::Iterator
+ArgsGroup::begin() const
+{
+ return Iterator(_imp->args_options.begin());
+}
+
+ArgsGroup::Iterator
+ArgsGroup::end() const
+{
+ return Iterator(_imp->args_options.end());
+}
+
diff --git a/paludis/args/args_group.hh b/paludis/args/args_group.hh
index c4d4aa5..fcbc1c1 100644
--- a/paludis/args/args_group.hh
+++ b/paludis/args/args_group.hh
@@ -20,10 +20,13 @@
#ifndef PALUDIS_GUARD_ARGS_ARGS_GROUP_HH
#define PALUDIS_GUARD_ARGS_ARGS_GROUP_HH 1
-#include <list>
#include <paludis/args/args_option.hh>
+#include <paludis/util/instantiation_policy.hh>
+#include <paludis/util/private_implementation_pattern.hh>
#include <string>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
+
/** \file
* Declaration for ArgsGroup.
*
@@ -42,40 +45,46 @@ namespace paludis
*
* \ingroup grplibpaludisargs
*/
- class ArgsGroup
+ class ArgsGroup :
+ private PrivateImplementationPattern<ArgsGroup>,
+ private InstantiationPolicy<ArgsGroup, instantiation_method::NonCopyableTag>
{
- friend class ArgsHandler;
- friend class ArgsOption;
-
private:
- ArgsGroup(const ArgsGroup &);
-
- void operator= (const ArgsGroup &);
-
const std::string _name;
- std::list<ArgsOption *> _args_options;
-
ArgsHandler * _handler;
- protected:
+ public:
+ ArgsHandler * handler()
+ {
+ return _handler;
+ }
+
/**
* Add an ArgsOption instance (called by the ArgsOption
* constructor).
*/
void add(ArgsOption * const value);
- public:
- /**
- * Constructor.
- */
+ ///\name Iterate over our ArgsOptions.
+ ///\{
+
+ typedef libwrapiter::ForwardIterator<ArgsGroup, ArgsOption * const> Iterator;
+
+ Iterator begin() const;
+ Iterator end() const;
+
+ ///\}
+
+ ///\name Basic operations
+ ///\{
+
ArgsGroup(ArgsHandler * h, const std::string & name);
- /**
- * Destructor.
- */
~ArgsGroup();
+ ///\}
+
/**
* Fetch our name.
*/
diff --git a/paludis/args/args_handler.cc b/paludis/args/args_handler.cc
index 3273756..8d08b15 100644
--- a/paludis/args/args_handler.cc
+++ b/paludis/args/args_handler.cc
@@ -112,8 +112,7 @@ ArgsHandler::dump_to_stream(std::ostream & s) const
{
s << (*g)->name() << ":" << std::endl;
- std::for_each((*g)->_args_options.begin(), (*g)->_args_options.end(),
- accept_visitor(&dump));
+ std::for_each((*g)->begin(), (*g)->end(), accept_visitor(&dump));
s << std::endl;
}
diff --git a/paludis/args/args_option.cc b/paludis/args/args_option.cc
index b7f4287..505fe95 100644
--- a/paludis/args/args_option.cc
+++ b/paludis/args/args_option.cc
@@ -37,7 +37,7 @@ ArgsOption::ArgsOption(ArgsGroup * const g, const std::string & long_name,
_specified(false)
{
g->add(this);
- g->_handler->add_option(this, long_name, short_name);
+ g->handler()->add_option(this, long_name, short_name);
}
ArgsOption::~ArgsOption()