*/
////////////////////////////////////////////////////////////////////////////////
-/*! \defgroup g_Resolvable Resolvable objects
+/*! \defgroup g_Resolvable Resolvable Objects
+ * \verbinclude g_Resolvable
*/
-/*! \defgroup g_ResolvableImplIf Implementation interfaces
- \ingroup g_Resolvable
+
+/*! \defgroup g_ResolvableImplIf Implementation interfaces
+ * \ingroup g_Resolvable
+ * \verbinclude g_ResolvableImplIf
*/
-/*! \defgroup g_ResolvableImpl Implementations
- \ingroup g_ResolvableImplIf
+
+/*! \defgroup g_ResolvableImpl Implementations
+ * \ingroup g_Resolvable
+ * \verbinclude g_ResolvableImpl
*/
+////////////////////////////////////////////////////////////////////////////////
+/*! \defgroup g_EnumerationClass Enumeration Class
+ * \verbinclude g_EnumerationClass
+*/
+////////////////////////////////////////////////////////////////////////////////
#define ZYPP_BASE_KINDOF_H
#include <iosfwd>
-#include <string>
+
+#include "zypp/base/String.h"
///////////////////////////////////////////////////////////////////
namespace zypp
//
// CLASS NAME : KindOf<_Tp>
//
- /**
+ /** Maintain string values representing different kinds of a type.
+ *
+ * \b Example: We have different kinds of Resolvable: Package, Patch,
+ * etc. We want some thing to identify these types and have a string
+ * value associated. Identification should be constructible from this
+ * string. An \ref g_EnumerationClass could do this, but we would also
+ * like to be exensible at runtime.
+ *
+ * KindOf stores a \b lowercased version of a string and uses this as
+ * identification.
+ *
+ * \todo How to make doxygen show the related ==/!= operator
+ * for KindOf vs std::string comarison?
+ * \todo Unify strings and associate numerical value for more
+ * efficient comparison and use in \c switch.
+ * \todo Make lowercased/uppercased/... an option. First of all
+ * get rid of the string::toLower calls operator.
+ * \todo Maybe collaboration with some sort of Registry.
*/
template<class _Tp>
class KindOf
{
public:
- /** Ctor */
+ /** DefaultCtor: empty string */
KindOf()
{}
- /** Ctor */
+ /** Ctor from string.
+ * Lowecase version of \a value_r is used as identification.
+ */
explicit
KindOf( const std::string & value_r )
- : _value( value_r )
+ : _value( string::toLower(value_r) )
{}
/** Dtor */
~KindOf()
{}
public:
- /** */
+ /** Identification string. */
const std::string & asString() const
{ return _value; }
+
private:
+ /** */
std::string _value;
};
///////////////////////////////////////////////////////////////////
+ /** \Relates KindOf stream output*/
template<class _Tp>
inline std::ostream & operator<<( std::ostream & str, const KindOf<_Tp> & obj )
{ return str << obj.asString(); }
///////////////////////////////////////////////////////////////////
+ /** \Relates KindOf */
template<class _Tp>
inline bool operator==( const KindOf<_Tp> & lhs, const KindOf<_Tp> & rhs )
{ return lhs.asString() == rhs.asString(); }
+ /** \Relates KindOf */
template<class _Tp>
inline bool operator==( const KindOf<_Tp> & lhs, const std::string & rhs )
- { return lhs.asString() == rhs; }
+ { return lhs.asString() == string::toLower(rhs); }
+ /** \Relates KindOf */
template<class _Tp>
inline bool operator==( const std::string & lhs, const KindOf<_Tp> & rhs )
- { return lhs == rhs.asString(); }
+ { return string::toLower(lhs) == rhs.asString(); }
+ /** \Relates KindOf */
template<class _Tp>
inline bool operator!=( const KindOf<_Tp> & lhs, const KindOf<_Tp> & rhs )
{ return !( lhs == rhs ); }
+ /** \Relates KindOf */
template<class _Tp>
inline bool operator!=( const KindOf<_Tp> & lhs, const std::string & rhs )
{ return !( lhs == rhs ); }
+ /** \Relates KindOf */
template<class _Tp>
inline bool operator!=( const std::string & lhs, const KindOf<_Tp> & rhs )
{ return !( lhs == rhs ); }
+ /** \Relates KindOf For use in std::container. */
template<class _Tp>
inline bool operator<( const KindOf<_Tp> & lhs, const KindOf<_Tp> & rhs )
{ return lhs.asString() < rhs.asString(); }
namespace string
{ /////////////////////////////////////////////////////////////////
+ /******************************************************************
+ **
+ ** FUNCTION NAME : form
+ ** FUNCTION TYPE : std::string
+ */
std::string form( const char * format, ... )
{
struct SafeBuf
return safe.asString();
}
+ /******************************************************************
+ **
+ ** FUNCTION NAME : toLower
+ ** FUNCTION TYPE : std::string
+ */
+ std::string toLower( const std::string & s )
+ {
+ if ( s.empty() )
+ return s;
+
+ std::string ret( s );
+ for ( std::string::size_type i = 0; i < ret.length(); ++i ) {
+ if ( isupper( ret[i] ) )
+ ret[i] = static_cast<char>(tolower( ret[i] ));
+ }
+ return ret;
+ }
+
+ /******************************************************************
+ **
+ ** FUNCTION NAME : toUpper
+ ** FUNCTION TYPE : std::string
+ */
+ std::string toUpper( const std::string & s )
+ {
+ if ( s.empty() )
+ return s;
+
+ std::string ret( s );
+ for ( std::string::size_type i = 0; i < ret.length(); ++i ) {
+ if ( islower( ret[i] ) )
+ ret[i] = static_cast<char>(toupper( ret[i] ));
+ }
+ return ret;
+ }
+
+
/////////////////////////////////////////////////////////////////
} // namespace string
///////////////////////////////////////////////////////////////////