aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Mike Kelly <pioto@pioto.org> 2007-07-19 21:57:13 +0000
committerAvatar Mike Kelly <pioto@pioto.org> 2007-07-19 21:57:13 +0000
commit4492d8e14c41bf723c5945d0c009853853992a21 (patch)
treed968f13ce8a509a15c0e6549c592776f169ec722
parentbaf73d121e213089dc6c016158d85dc8efe62aa9 (diff)
downloadpaludis-4492d8e14c41bf723c5945d0c009853853992a21.tar.gz
paludis-4492d8e14c41bf723c5945d0c009853853992a21.tar.xz
Add AAVisitor, which gives us an Iterator over all the filenames in a URIDepSpec.
-rw-r--r--paludis/repositories/e/Makefile.am17
-rw-r--r--paludis/repositories/e/aa_visitor.cc86
-rw-r--r--paludis/repositories/e/aa_visitor.hh82
-rw-r--r--paludis/repositories/e/aa_visitor_TEST.cc47
4 files changed, 231 insertions, 1 deletions
diff --git a/paludis/repositories/e/Makefile.am b/paludis/repositories/e/Makefile.am
index 529e42b..8d4c44e 100644
--- a/paludis/repositories/e/Makefile.am
+++ b/paludis/repositories/e/Makefile.am
@@ -33,6 +33,7 @@ paludis_repositories_e_includedir = $(includedir)/paludis-$(PALUDIS_PC_SLOT)/pal
libpaludiserepository_la_LDFLAGS = -version-info @VERSION_LIB_CURRENT@:@VERSION_LIB_REVISION@:0
paludis_repositories_e_include_HEADERS = \
+ aa_visitor.hh \
dep_lexer.hh \
dep_parser.hh \
dep_parser-se.hh \
@@ -79,6 +80,7 @@ paludis_repositories_e_include_HEADERS = \
vdb_unmerger.hh
libpaludiserepository_la_SOURCES = \
+ aa_visitor.cc \
dep_lexer.cc \
dep_parser.cc \
dep_spec_pretty_printer.cc \
@@ -193,7 +195,19 @@ dep_parser_TEST_LDADD = \
$(top_builddir)/test/libtest.a \
$(DYNAMIC_LD_LIBS)
+aa_visitor_TEST_SOURCES = aa_visitor_TEST.cc
+
+aa_visitor_TEST_LDADD = \
+ libpaludiserepository.la \
+ $(top_builddir)/paludis/util/libpaludisutil.la \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
+ $(top_builddir)/test/libtest.a \
+ $(DYNAMIC_LD_LIBS)
+
EXTRA_DIST = \
+ aa_visitor_TEST.cc \
dep_lexer_TEST.cc \
dep_parser.se \
dep_parser-se.hh \
@@ -377,7 +391,8 @@ TESTS = \
e_repository_TEST \
vdb_unmerger_TEST \
$(GLSA_TESTS) \
- e_repository_sets_TEST
+ e_repository_sets_TEST \
+ aa_visitor_TEST
check_PROGRAMS = $(TESTS)
diff --git a/paludis/repositories/e/aa_visitor.cc b/paludis/repositories/e/aa_visitor.cc
new file mode 100644
index 0000000..48e9304
--- /dev/null
+++ b/paludis/repositories/e/aa_visitor.cc
@@ -0,0 +1,86 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Mike Kelly <pioto@pioto.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/dep_spec.hh>
+#include <paludis/repositories/e/aa_visitor.hh>
+#include <paludis/util/visitor-impl.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
+
+/** \file
+ * Implementation of aa_visitor.hh
+ *
+ * \ingroup grpaavisitor
+ */
+
+using namespace paludis;
+using namespace paludis::erepository;
+
+namespace paludis
+{
+ template<>
+ struct Implementation<AAVisitor>
+ {
+ std::list<std::string> aa;
+ };
+}
+
+AAVisitor::AAVisitor() :
+ PrivateImplementationPattern<AAVisitor>(new Implementation<AAVisitor>)
+{
+}
+
+AAVisitor::~AAVisitor()
+{
+}
+
+void
+AAVisitor::visit_sequence(const AllDepSpec &,
+ URISpecTree::ConstSequenceIterator cur,
+ URISpecTree::ConstSequenceIterator e)
+{
+ std::for_each(cur, e, accept_visitor(*this));
+}
+
+void
+AAVisitor::visit_sequence(const UseDepSpec &,
+ URISpecTree::ConstSequenceIterator cur,
+ URISpecTree::ConstSequenceIterator e)
+{
+ std::for_each(cur, e, accept_visitor(*this));
+}
+
+void
+AAVisitor::visit_leaf(const URIDepSpec & p)
+{
+ _imp->aa.push_back(p.filename());
+}
+
+AAVisitor::Iterator
+AAVisitor::begin() const
+{
+ return Iterator(_imp->aa.begin());
+}
+
+AAVisitor::Iterator
+AAVisitor::end() const
+{
+ return Iterator(_imp->aa.end());
+}
+
diff --git a/paludis/repositories/e/aa_visitor.hh b/paludis/repositories/e/aa_visitor.hh
new file mode 100644
index 0000000..59e1065
--- /dev/null
+++ b/paludis/repositories/e/aa_visitor.hh
@@ -0,0 +1,82 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Mike Kelly <pioto@pioto.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_AAVISITOR_HH
+#define PALUDIS_GUARD_PALUDIS_AAVISITOR_HH 1
+
+#include <paludis/dep_spec.hh>
+
+/** \file
+ * Declarations for the AAVisitor class.
+ *
+ * \ingroup grpaavisitor
+ */
+
+namespace paludis
+{
+ namespace erepository
+ {
+ /**
+ * Get a list of all the URIs in a URIDepSpec, regardless of USE
+ * flag settings.
+ *
+ * \ingroup grpaavisitor
+ */
+ class PALUDIS_VISIBLE AAVisitor :
+ public ConstVisitor<URISpecTree>,
+ private PrivateImplementationPattern<AAVisitor>
+ {
+ public:
+ ///\name Basic operations
+ ///\{
+
+ AAVisitor();
+
+ ~AAVisitor();
+
+ ///\}
+
+ /// \name Visit functions
+ ///{
+
+ void visit_sequence(const AllDepSpec &,
+ URISpecTree::ConstSequenceIterator,
+ URISpecTree::ConstSequenceIterator);
+
+ void visit_sequence(const UseDepSpec &,
+ URISpecTree::ConstSequenceIterator,
+ URISpecTree::ConstSequenceIterator);
+
+ void visit_leaf(const URIDepSpec &);
+
+ ///}
+
+ /// \name Iterator functions
+ ///{
+
+ typedef libwrapiter::ForwardIterator<AAVisitor, const std::string> Iterator;
+
+ Iterator begin() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ Iterator end() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ ///}
+ };
+ }
+}
+#endif
diff --git a/paludis/repositories/e/aa_visitor_TEST.cc b/paludis/repositories/e/aa_visitor_TEST.cc
new file mode 100644
index 0000000..03e99d3
--- /dev/null
+++ b/paludis/repositories/e/aa_visitor_TEST.cc
@@ -0,0 +1,47 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Mike Kelly <pioto@pioto.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "aa_visitor.hh"
+#include "dep_parser.hh"
+#include <paludis/util/join.hh>
+#include <paludis/util/visitor-impl.hh>
+#include <paludis/repositories/e/eapi.hh>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+
+using namespace test;
+using namespace paludis;
+using namespace paludis::erepository;
+
+namespace test_cases
+{
+ struct AAVisitorTest : TestCase
+ {
+ AAVisitorTest() : TestCase("aa visitor") { }
+
+ void run()
+ {
+ AAVisitor p1;
+ DepParser::parse_uri("( a -> b c x? ( d e ) )", *EAPIData::get_instance()->eapi_from_string("paludis-1"))->accept(p1);
+ TEST_CHECK_EQUAL(join(p1.begin(), p1.end(), " "), "b c d e");
+ }
+ } test_aa_visitor;
+}
+