#include <zypp/Capability.h>
#include <zypp/CapFactory.h>
#include <zypp/CapSet.h>
+#include "main.h"
#define TAG INT << __PRETTY_FUNCTION__ << std::endl
using namespace std;
using namespace zypp;
-
+#include <zypp/ResKind.h>
/******************************************************************
**
**
CapFactory _f;
CapSetInsert( CapSet & x ) : _x(x) {}
void operator()( const char * v )
- { _x.insert( _f.parse( v ) ); }
+ { _x.insert( _f.parse( ResKind(), v ) ); }
};
int main( int argc, char * argv[] )
## ##################################################
-Main_SOURCES = Main.cc
+Main_SOURCES = Main.cc main.cc
Main_debug_SOURCES = $(Main_SOURCES)
Main_debug_LDFLAGS = -static
--- /dev/null
+#include "main.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
--- /dev/null
+#ifndef main_h
+#define main_h
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // main_h
*
*/
#include <iostream>
+#include <functional>
+#include <set>
#include "zypp/base/ReferenceCounted.h"
#include "zypp/base/NonCopyable.h"
#include "zypp/CapFactory.h"
-#include "zypp/capability/FileCap.h"
+#include "zypp/capability/Capabilities.h"
using namespace std;
+///////////////////////////////////////////////////////////////////
+namespace
+{ /////////////////////////////////////////////////////////////////
+
+ typedef zypp::capability::CapabilityImplPtr CapabilityImplPtr;
+
+ /** \todo check set ordering to assert no dups */
+ struct USetOrder : public std::binary_function<CapabilityImplPtr, CapabilityImplPtr, bool>
+ {
+ bool operator()( const CapabilityImplPtr & lhs,
+ const CapabilityImplPtr & rhs ) const
+ { return lhs->asString() < rhs->asString(); }
+ };
+
+ typedef std::set<CapabilityImplPtr,USetOrder> USet;
+
+ USet _uset;
+
+ /////////////////////////////////////////////////////////////////
+} // namespace
+///////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
// METHOD NAME : CapFactory::parse
// METHOD TYPE : Capability
//
- Capability CapFactory::parse( const std::string & strval_r ) const
+ /** \todo fix it */
+ Capability CapFactory::parse( const ResKind & refers_r, const std::string & strval_r ) const
{
// fix
- return Capability( new capability::FileCap );
+ CapabilityImplPtr newcap( new capability::NamedCap( refers_r, strval_r ) );
+ USet::iterator in( _uset.insert( newcap ).first );
+ return Capability( *in );
}
/******************************************************************
~CapFactory();
public:
- /** */
- Capability parse( const std::string & strval_r ) const;
-
+ /** */
+ Capability parse( const ResKind & refers_r, const std::string & strval_r ) const;
+ /*
+ template<typename _Res>
+ Capability parse( const std::string & strval_r ) const
+ { return parse( _Res::kind(), strval_r ); }
+ */
private:
/** Pointer to implementation */
detail::CapFactoryImplPtr _pimpl;
Capability::constImplPtr Capability::sayFriend() const
{ return _pimpl; }
+ const ResKind & Capability::refers() const
+ { return _pimpl->refers(); }
+
+ std::string Capability::asString() const
+ { return _pimpl->asString(); }
+
bool Capability::matches( constResolvablePtr resolvable_r,
- const SolverContext & solverContext_r )
+ const SolverContext & solverContext_r ) const
{ return _pimpl->matches( resolvable_r, solverContext_r ); }
- bool Capability::matches( constResolvablePtr resolvable_r )
+ bool Capability::matches( constResolvablePtr resolvable_r ) const
{ return _pimpl->matches( resolvable_r, SolverContext() ); }
/******************************************************************
//
// CLASS NAME : Capability
//
- /** */
+ /** Resolvable capabilitiy.
+ * \invariant Nonzero \c _pimpl
+ */
class Capability
{
private:
virtual ~Capability();
public:
+ /** */
+ const ResKind & refers() const;
+ /** */
+ std::string asString() const;
/** */
bool matches( constResolvablePtr resolvable_r,
- const SolverContext & colverContext_r );
+ const SolverContext & colverContext_r ) const;
/** */
- bool matches( constResolvablePtr resolvable_r );
+ bool matches( constResolvablePtr resolvable_r ) const;
private:
/** Pointer to implementation */
#include "zypp/base/ReferenceCounted.h"
#include "zypp/base/NonCopyable.h"
+#include "zypp/ResolvableFwd.h"
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
} // namespace detail
///////////////////////////////////////////////////////////////////
- DEFINE_PTR_TYPE(Resolvable)
-
- class ResKind;
- class Edition;
- class Arch;
///////////////////////////////////////////////////////////////////
//
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ class ResKind;
+ class Edition;
+ class Arch;
+ class Capability;
+
DEFINE_PTR_TYPE(Resolvable)
/////////////////////////////////////////////////////////////////
* \li \c shared_ptr Object ownership shared among multiple pointers
*
* \li \c weak_ptr Non-owning observers of an object owned by shared_ptr.
+ *
+ * \todo Intrusive Ptr class which supports constness. Used as PIMPL.
+ * Offers 'const Impl *' in const context, otherwise 'Impl *'. to
+ * prevent const classes from calling nonconst Impl methods.
*/
/*@{*/
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/capability/Capabilities.h
+ *
+*/
+#ifndef ZYPP_CAPABILITY_CAPABILITIES_H
+#define ZYPP_CAPABILITY_CAPABILITIES_H
+
+#include "zypp/capability/CapabilityImpl.h"
+#include "zypp/capability/NamedCap.h"
+
+#endif // ZYPP_CAPABILITY_CAPABILITIES_H
///////////////////////////////////////////////////////////////////
//
- // METHOD NAME : CapabilityImpl::~CapabilityImpl
- // METHOD TYPE : Dtor
+ // METHOD NAME : CapabilityImpl::CapabilityImpl
+ // METHOD TYPE : Ctor
//
- CapabilityImpl::~CapabilityImpl()
+ CapabilityImpl::CapabilityImpl( const ResKind & refers_r )
+ : _refers( refers_r )
{}
/******************************************************************
*/
std::ostream & operator<<( std::ostream & str, const CapabilityImpl & obj )
{
- return str << "CapabilityImpl";
+ return str << '[' << obj.refers() << "] " << obj.asString();
}
/////////////////////////////////////////////////////////////////
#include "zypp/ResolvableFwd.h"
#include "zypp/SolverContextFwd.h"
+#include "zypp/ResKind.h"
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
DEFINE_PTR_TYPE(CapabilityImpl)
+ /** \todo Check implementation */
+ typedef std::string CapKind;
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : CapabilityImpl
class CapabilityImpl : public base::ReferenceCounted, private base::NonCopyable
{
public:
- /** Dtor */
- virtual ~CapabilityImpl();
+ /** Ctor */
+ CapabilityImpl( const ResKind & refers_r );
public:
+ /** */
+ virtual const CapKind & kind() const = 0;
+ /** */
+ const ResKind & refers() const
+ { return _refers; }
+ /** */
+ virtual std::string asString() const = 0;
/** */
virtual bool matches( constResolvablePtr resolvable_r,
- const SolverContext & colverContext_r ) = 0;
+ const SolverContext & colverContext_r ) const = 0;
+
+ private:
+ /** */
+ ResKind _refers;
};
///////////////////////////////////////////////////////////////////
## ##################################################
-include_HEADERS = CapabilityImpl.h \
+include_HEADERS = \
+ CapabilityImpl.h\
+ Capabilities.h \
\
ConditionalCap.h\
FileCap.h \
## ##################################################
lib@PACKAGE@_capability_la_SOURCES = \
- CapabilityImpl.cc
+ CapabilityImpl.cc \
+ \
+ NamedCap.cc
## ##################################################
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/capability/NamedCap.cc
+ *
+*/
+#include "zypp/capability/NamedCap.h"
+
+using namespace std;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace capability
+ { /////////////////////////////////////////////////////////////////
+
+ const CapKind NamedCap::_kind( "NamedCap" );
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace capability
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
class NamedCap : public CapabilityImpl
{
public:
+ /** Ctor */
+ NamedCap( const ResKind & refers_r, const std::string & name_r )
+ : CapabilityImpl( refers_r )
+ , _name( name_r )
+ {}
+ public:
+ /** */
+ virtual const CapKind & kind() const
+ { return _kind; }
+ /** */
+ virtual std::string asString() const
+ { return _name; }
/** */
- bool matches( constResolvablePtr resolvable_r,
- const SolverContext & colverContext_r )
+ virtual bool matches( constResolvablePtr resolvable_r,
+ const SolverContext & colverContext_r ) const
{ return false; }
+ private:
+ /** */
+ static const CapKind _kind;
+ /** */
+ std::string _name;
};
///////////////////////////////////////////////////////////////////