class KindOf<>: lowercase identification string and caseinsensitive
authorMichael Andres <ma@suse.de>
Thu, 24 Nov 2005 11:36:59 +0000 (11:36 +0000)
committerMichael Andres <ma@suse.de>
Thu, 24 Nov 2005 11:36:59 +0000 (11:36 +0000)
comparison with string.

doc/autodoc/Doxyfile.in
zypp/@DOXYGEN/DOXYGEN.h
zypp/Rel.h
zypp/base/KindOf.h
zypp/base/String.cc
zypp/base/String.h

index c69fe1a..2a92a82 100644 (file)
@@ -77,7 +77,7 @@ RECURSIVE              = YES
 EXCLUDE                =
 EXCLUDE_SYMLINKS       = NO
 EXCLUDE_PATTERNS       =
-EXAMPLE_PATH           =
+EXAMPLE_PATH           = @top_srcdir@/@PACKAGE@/@DOXYGEN
 EXAMPLE_PATTERNS       =
 EXAMPLE_RECURSIVE      = NO
 IMAGE_PATH             =
index 4506871..c91f771 100644 (file)
 
 */
 ////////////////////////////////////////////////////////////////////////////////
-/*!  \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
+*/
+////////////////////////////////////////////////////////////////////////////////
index 89cfbe1..4b43d40 100644 (file)
@@ -37,6 +37,8 @@ namespace zypp
    * to \c false. While \ref ANY should always resolve to \c true, and
    * may be handy in queries when you're looking for a Resolvable in
    * \c ANY Edition.
+   *
+   * \ingroup g_EnumerationClass
   */
   struct Rel
   {
index fc0e097..ca3d26c 100644 (file)
@@ -13,7 +13,8 @@
 #define ZYPP_BASE_KINDOF_H
 
 #include <iosfwd>
-#include <string>
+
+#include "zypp/base/String.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -26,64 +27,93 @@ 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(); }
index db1c182..acc23a3 100644 (file)
@@ -27,6 +27,11 @@ namespace zypp
     namespace string
     { /////////////////////////////////////////////////////////////////
 
+      /******************************************************************
+       **
+       **      FUNCTION NAME : form
+       **      FUNCTION TYPE : std::string
+      */
       std::string form( const char * format, ... )
       {
         struct SafeBuf
@@ -47,6 +52,43 @@ namespace zypp
         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
     ///////////////////////////////////////////////////////////////////
index f188e43..cae4a48 100644 (file)
@@ -30,6 +30,17 @@ namespace zypp
       std::string form( const char * format, ... )
       __attribute__ ((format (printf, 1, 2)));
 
+
+      /** Return lowercase version of \a s
+       * \todo improve
+      */
+      std::string toLower( const std::string & s );
+
+      /** Return uppercase version of \a s
+       * \todo improve
+      */
+      std::string toUpper( const std::string & s );
+
       /////////////////////////////////////////////////////////////////
     } // namespace string
     ///////////////////////////////////////////////////////////////////