--- /dev/null
+#include <stdio.h>
+#include <iostream>
+#include <iterator>
+#include <list>
+
+#include "zypp/ZYppFactory.h"
+#include "zypp/PoolQuery.h"
+#include "zypp/PoolQueryUtil.tcc"
+#include "zypp/RepoInfo.h"
+#include "zypp/Arch.h"
+#include "zypp/Pathname.h"
+
+using std::cout;
+using std::endl;
+using std::string;
+using namespace zypp;
+
+
+bool result_cb( const sat::Solvable & solvable )
+{
+ zypp::PoolItem pi( zypp::ResPool::instance().find( solvable ) );
+ cout << pi.resolvable() << endl;
+ // name: yast2-sound 2.16.2-9 i586
+ return true;
+}
+
+
+static void init_pool()
+{
+ Pathname dir(TESTS_SRC_DIR);
+ dir += "/zypp/data/PoolQuery";
+
+ ZYpp::Ptr z = getZYpp();
+ ZConfig::instance().setSystemArchitecture(Arch("i586"));
+
+ RepoInfo i1; i1.setAlias("factory");
+ sat::Pool::instance().addRepoSolv(dir / "factory.solv", i1);
+ RepoInfo i2; i2.setAlias("factory-nonoss");
+ sat::Pool::instance().addRepoSolv(dir / "factory-nonoss.solv", i2);
+ RepoInfo i3; i3.setAlias("zypp_svn");
+ sat::Pool::instance().addRepoSolv(dir / "zypp_svn.solv", i3);
+ RepoInfo i4; i4.setAlias("@System");
+ sat::Pool::instance().addRepoSolv(dir / "@System.solv", i4);
+}
+
+
+int main (int argc, const char ** argv)
+{
+ init_pool();
+
+ PoolQuery q;
+ //q.addString("novell");
+ q.addAttribute(sat::SolvAttr::name, "novell");
+ q.addAttribute(sat::SolvAttr::summary, "novell");
+
+ std::for_each(q.begin(), q.end(), &result_cb);
+
+ cout << q.size() << endl;
+}
BOOST_CHECK(q1.size() == 5);
}
+
/////////////////////////////////////////////////////////////////////////////
// 1xx multiple attribute queries
/////////////////////////////////////////////////////////////////////////////
BOOST_CHECK(q1.size() == 7);
}
+
// multi attr (same value) substring matching (case sensitive and insensitive)
BOOST_AUTO_TEST_CASE(pool_query_101)
{
}
+// multi attr (same value via addAttribute())
+BOOST_AUTO_TEST_CASE(pool_query_103)
+{
+ cout << "****103.1****" << endl;
+ PoolQuery q;
+ q.addAttribute(sat::SolvAttr::name, "novell");
+ q.addAttribute(sat::SolvAttr::summary, "novell");
+
+// std::for_each(q.begin(), q.end(), &result_cb);
+ BOOST_CHECK(q.size() == 42);
+
+ cout << "****103.2****" << endl;
+
+ PoolQuery q1;
+ q1.addString("novell");
+ q1.addAttribute(sat::SolvAttr::name);
+ q1.addAttribute(sat::SolvAttr::summary);
+
+// std::for_each(q1.begin(), q1.end(), &result_cb);
+ BOOST_CHECK(q1.size() == 42);
+
+ cout << endl;
+}
+
/////////////////////////////////////////////////////////////////////////////
// 3xx repo filter queries (addRepo(alias_str))
/////////////////////////////////////////////////////////////////////////////
StrContainer _strings;
/** Regex-compiled search strings. */
mutable string _rcstrings;
+ mutable regex_t _regex;
/** Raw attributes */
AttrMap _attrs;
/** Regex-compiled attributes */
mutable CompiledAttrMap _rcattrs;
+ mutable map<sat::SolvAttr, regex_t> _rattrs;
/** Repos to search. */
StrContainer _repos;
Impl * clone() const
{ return new Impl( *this ); }
};
-/*
- template <class _OutputIterator>
- struct CollectNonEmpty
- {
- CollectNonEmpty( _OutputIterator iter_r ) : _iter( iter_r ) {}
- template<class _Tp>
- bool operator()( const _Tp & value_r ) const
+
+ struct MyInserter
+ {
+ MyInserter(PoolQuery::StrContainer & cont) : _cont(cont) {}
+
+ bool operator()(const string & str)
{
- if (value_r.empty())
- return true;
- *_iter++ = value_r;
+ _cont.insert(str);
return true;
}
+
+ PoolQuery::StrContainer & _cont;
+ };
- private:
- mutable _OutputIterator _iter;
+
+ struct EmptyFilter
+ {
+ bool operator()(const string & str)
+ {
+ return !str.empty();
+ }
};
-*/
+
+
void PoolQuery::Impl::compile() const
{
_cflags = _flags;
else if (_attrs.size() == 1)
{
StrContainer joined;
- for(StrContainer::const_iterator it = _strings.begin(); it != _strings.end(); ++it)
- if (!it->empty())
- joined.insert(*it);
- for(StrContainer::const_iterator it = _attrs.begin()->second.begin(); it != _attrs.begin()->second.end(); ++it)
- if (!it->empty())
- joined.insert(*it);
+ invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
+ invokeOnEach(_attrs.begin()->second.begin(), _attrs.begin()->second.end(), EmptyFilter(), MyInserter(joined));
_rcstrings = createRegex(joined);
_rcattrs.insert(pair<sat::SolvAttr, string>(_attrs.begin()->first, string()));
}
-
// // MULTIPLE ATTRIBUTES
else
{
+ // check whether there are any per-attribute strings
bool attrvals_empty = true;
for (AttrMap::const_iterator ai = _attrs.begin(); ai != _attrs.end(); ++ai)
if (!ai->second.empty())
attremptycheckend:
+ // chceck whether the per-attribute strings are all the same
bool attrvals_thesame = true;
- for (AttrMap::const_iterator ai = _attrs.begin(); ai != _attrs.end(); ++ai)
+ AttrMap::const_iterator ai = _attrs.begin();
+ const StrContainer & set1 = ai->second;
+ ++ai;
+ for (; ai != _attrs.end(); ++ai)
{
-
+ StrContainer result;
+ set_difference(
+ set1.begin(), set1.end(),
+ ai->second.begin(), ai->second.end(),
+ inserter(result, result.begin())/*, ltstr()*/);
+ if (!result.empty())
+ {
+ copy(result.begin(), result.end(), ostream_iterator<string>(cout, " "));
+ attrvals_thesame = false;
+ break;
+ }
}
// // THE SAME STRINGS FOR DIFFERENT ATTRS
// create regex; store in _rcattrs and _rcstrings; flag 'same'; if more strings flag regex;
if (attrvals_empty || attrvals_thesame)
{
+ StrContainer joined;
if (attrvals_empty)
{
- // compile the search string
- StrContainer joined;
- for(StrContainer::const_iterator it = _strings.begin(); it != _strings.end(); ++it)
- if (!it->empty())
- joined.insert(*it);
+ invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
+ _rcstrings = createRegex(joined);
+ }
+ else
+ {
+ invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
+ invokeOnEach(_attrs.begin()->second.begin(), _attrs.begin()->second.end(), EmptyFilter(), MyInserter(joined));
_rcstrings = createRegex(joined);
-
- // copy the _attrs keys to _rcattrs
- for (AttrMap::const_iterator ai = _attrs.begin(); ai != _attrs.end(); ++ai)
- _rcattrs.insert(pair<sat::SolvAttr, string>(ai->first, string()));
}
+ // copy the _attrs keys to _rcattrs
+ for_(ai, _attrs.begin(), _attrs.end())
+ _rcattrs.insert(pair<sat::SolvAttr, string>(ai->first, string()));
}
// // DIFFERENT STRINGS FOR DIFFERENT ATTRS
// if _attrs is not empty and it contains non-empty vectors with non-empty strings
// create regex; store in _rcattrs; flag 'different'; if more strings flag regex;
else
{
-
+ /* set_union(A.begin(), A.end(), B.begin(), B.end(),
+ ostream_iterator<const char*>(cout, " "),
+ ltstr());*/
}
}