- added ByteCount and Unit
authorMichael Andres <ma@suse.de>
Tue, 13 Dec 2005 18:29:26 +0000 (18:29 +0000)
committerMichael Andres <ma@suse.de>
Tue, 13 Dec 2005 18:29:26 +0000 (18:29 +0000)
- fixed solver/testsuite

13 files changed:
zypp/@DOXYGEN/DOXYGEN.h
zypp/@Review/FSize.cc [deleted file]
zypp/@Review/FSize.h [deleted file]
zypp/@Review/stringutil.h
zypp/ByteCount.cc [new file with mode: 0644]
zypp/ByteCount.h [new file with mode: 0644]
zypp/Makefile.am
zypp/base/Makefile.am
zypp/base/StringVal.cc [deleted file]
zypp/base/StringVal.h [deleted file]
zypp/base/Unit.cc [new file with mode: 0644]
zypp/base/Unit.h [new file with mode: 0644]
zypp/solver/testsuite/.cvsignore [new file with mode: 0644]

index 3fcbdb6..e2d95c5 100644 (file)
@@ -36,7 +36,3 @@
  * \verbinclude g_BackenSpecific
 */
 ////////////////////////////////////////////////////////////////////////////////
-/*! \defgroup g_CodeFlaws Flaws to cleanup
- * \verbinclude g_CodeFlaws
-*/
-////////////////////////////////////////////////////////////////////////////////
diff --git a/zypp/@Review/FSize.cc b/zypp/@Review/FSize.cc
deleted file mode 100644 (file)
index cd0dc66..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*---------------------------------------------------------------------\
-|                                                                      |
-|                      __   __    ____ _____ ____                      |
-|                      \ \ / /_ _/ ___|_   _|___ \                     |
-|                       \ V / _` \___ \ | |   __) |                    |
-|                        | | (_| |___) || |  / __/                     |
-|                        |_|\__,_|____/ |_| |_____|                    |
-|                                                                      |
-|                               core system                            |
-|                                                        (C) SuSE GmbH |
-\----------------------------------------------------------------------/
-
-  File:       FSize.cc
-
-  Author:     Michael Andres <ma@suse.de>
-  Maintainer: Michael Andres <ma@suse.de>
-
-  Purpose:
-
-/-*/
-
-#include <stdlib.h>
-
-#include <iostream>
-
-#include <y2util/stringutil.h>
-#include <y2util/FSize.h>
-
-using namespace std;
-
-FSize::FSize( const string &sizeStr, const Unit unit_r )
-  : _size( atoll( sizeStr.c_str() ) * factor( unit_r ) )
-{
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-//     METHOD NAME : FSize::fillBlock
-//     METHOD TYPE : FSize &
-//
-//     DESCRIPTION :
-//
-FSize & FSize::fillBlock( FSize blocksize_r )
-{
-  if ( _size && blocksize_r ) {
-    long long diff = _size % blocksize_r;
-    if ( diff ) {
-      if ( _size > 0 )
-       _size += blocksize_r;
-      _size -= diff;
-    }
-  }
-  return *this;
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-//     METHOD NAME : FSize::bestUnit
-//     METHOD TYPE : FSize::Unit
-//
-//     DESCRIPTION :
-//
-FSize::Unit FSize::bestUnit() const
-{
-  long long usize( _size < 0 ? -_size : _size );
-  if ( usize < KB )
-    return B;
-  if ( usize < MB )
-    return K;
-  if ( usize < GB )
-    return M;
-  if ( usize < TB )
-    return G;
-  return T;
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-//     METHOD NAME : FSize::form
-//     METHOD TYPE : std::string
-//
-//     DESCRIPTION :
-//
-std::string FSize::form( const Unit unit_r, unsigned fw, unsigned prec, const bool showunit ) const
-{
-  if ( prec == bestPrec ) {
-    switch ( unit_r )
-    {
-      case T:  prec = 3; break;
-      case G:  prec = 2; break;
-      case M:  prec = 1; break;
-      case K:  prec = 1; break;
-      case B:  prec = 0; break;
-    }
-  } else if ( unit_r == B )
-    prec = 0; // doesn't make sense for Byte
-
-  string ret = stringutil::form( "%*.*f", fw, prec, ( double( _size ) / factor( unit_r ) ) );
-  if ( showunit ) {
-    ret = stringutil::form( "%s %s", ret.c_str(), unit( unit_r ) );
-  }
-  return ret;
-}
-
-
-///////////////////////////////////////////////////////////////////
-//
-//
-//     METHOD NAME : FSize::asString
-//     METHOD TYPE : std::string
-//
-//     DESCRIPTION :
-//
-std::string FSize::asString() const
-{
-  return form();
-}
-
-/******************************************************************
-**
-**
-**     FUNCTION NAME : operator<<
-**     FUNCTION TYPE : std::ostream &
-**
-**     DESCRIPTION :
-*/
-std::ostream & operator<<( std::ostream & str, const FSize & obj )
-{
-  return str << obj.asString();
-}
-
diff --git a/zypp/@Review/FSize.h b/zypp/@Review/FSize.h
deleted file mode 100644 (file)
index d4e52c9..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/*---------------------------------------------------------------------\
-|                                                                      |
-|                      __   __    ____ _____ ____                      |
-|                      \ \ / /_ _/ ___|_   _|___ \                     |
-|                       \ V / _` \___ \ | |   __) |                    |
-|                        | | (_| |___) || |  / __/                     |
-|                        |_|\__,_|____/ |_| |_____|                    |
-|                                                                      |
-|                               core system                            |
-|                                                        (C) SuSE GmbH |
-\----------------------------------------------------------------------/
-
-  File:       FSize.h
-
-  Author:     Michael Andres <ma@suse.de>
-  Maintainer: Michael Andres <ma@suse.de>
-
-  Purpose: Store and operate on (file/package/partition) sizes (long long).
-
-/-*/
-#ifndef _FSize_h_
-#define _FSize_h_
-
-#include <iosfwd>
-#include <string>
-
-///////////////////////////////////////////////////////////////////
-//
-//     CLASS NAME : FSize
-//
-/**
- * @short Store and operate on (file/package/partition) sizes (long long).
- **/
-class FSize {
-
-  public:
-
-    /**
-     * The Units
-     **/
-    enum Unit { B = 0, K, M, G, T };
-
-  private:
-
-    /**
-     * The size in Byte
-     **/
-    long long _size;
-
-  public:
-
-    static const long long KB = 1024;
-    static const long long MB = 1024 * KB;
-    static const long long GB = 1024 * MB;
-    static const long long TB = 1024 * GB;
-
-    /**
-     * Return ammount of Byte in Unit.
-     **/
-    static long long factor( const Unit unit_r ) {
-      switch ( unit_r ) {
-      case T: return TB;
-      case G: return GB;
-      case M: return MB;
-      case K: return KB;
-      case B: break;
-      }
-      return 1;
-    }
-
-    /**
-     * String representation of Unit.
-     **/
-    static const char * unit( const Unit unit_r ) {
-      switch ( unit_r ) {
-      case T: return "TB";
-      case G: return "GB";
-      case M: return "MB";
-      case K: return "kB";
-      case B: break;
-      }
-      return "B";
-    }
-
-  public:
-
-    /**
-     * Construct from size in Byte.
-     **/
-    FSize( const long long size_r = 0 )
-      : _size( size_r )
-    {}
-
-    /**
-     * Construct from size in certain unit.
-     * E.g. <code>FSize( 1, FSize::K )</code> makes 1024 Byte.
-     **/
-    FSize( const long long size_r, const Unit unit_r )
-      : _size( size_r * factor( unit_r ) )
-    {}
-
-    /**
-      Construct from string containing a number in given unit.
-    */
-    FSize( const std::string &sizeStr, const Unit unit_r = B );
-
-    /**
-     * Conversion to long long
-     **/
-    operator long long() const { return _size; }
-
-    FSize & operator+=( const long long rhs ) { _size += rhs; return *this; }
-    FSize & operator-=( const long long rhs ) { _size -= rhs; return *this; }
-    FSize & operator*=( const long long rhs ) { _size *= rhs; return *this; }
-    FSize & operator/=( const long long rhs ) { _size /= rhs; return *this; }
-
-    FSize & operator++(/*prefix*/) { _size += 1; return *this; }
-    FSize & operator--(/*prefix*/) { _size -= 1; return *this; }
-
-    FSize operator++(int/*postfix*/) { return _size++; }
-    FSize operator--(int/*postfix*/) { return _size--; }
-
-    /**
-     * Adjust size to multiple of <code>blocksize_r</code>
-     **/
-    FSize & fillBlock( FSize blocksize_r = KB );
-
-    /**
-     * Return size adjusted to multiple of <code>blocksize_r</code>
-     **/
-    FSize fullBlock( FSize blocksize_r = KB ) const { FSize ret( _size ); return ret.fillBlock(  blocksize_r );        }
-
-    /**
-     * Return size in Unit ( not rounded )
-     **/
-    long long operator()( const Unit unit_r ) const { return _size / factor( unit_r ); }
-
-    /**
-     * Return the best unit for string representation.
-     **/
-    Unit bestUnit() const;
-
-    /**
-     * Used as precision argument to form(), the 'best' precision according to
-     * Unist is chosen.
-     **/
-    static const unsigned bestPrec = (unsigned)-1;
-
-    /**
-     * Return string representation in given Unit. Parameter <code>fw</code> and
-     * <code>prec</code> denote field width and precision as in a "%*.*f" printf
-     * format string. Avalue of <code>bestPrec</code> automatically picks an
-     * appropriate precision depending on the unit.
-     * If <code>showunit</code> ist true, the string representaion
-     * of Unit is <em>appended</em> separated by a single blank.
-     *
-     * If Unit is <b>B</b>yte, precision is set to zero.
-     **/
-    std::string form( const Unit unit_r, unsigned fw = 0, unsigned prec = bestPrec, const bool showunit = true ) const;
-
-    /**
-     * Return string representation in bestUnit.
-     **/
-    std::string form( unsigned fw = 0, unsigned prec = bestPrec, const bool showunit = true ) const {
-      return form( bestUnit(), fw, prec, showunit );
-    }
-
-    /**
-     * Default string representation (precision 1 and unit appended).
-     **/
-    std::string asString() const;
-
-    /**
-     * Write asString.
-     **/
-    friend std::ostream & operator<<( std::ostream & str, const FSize & obj );
-};
-
-///////////////////////////////////////////////////////////////////
-
-#endif // _FSize_h_
index 4f155d0..63dd04c 100644 (file)
@@ -20,6 +20,7 @@
   functions.
 
 /-*/
+
 #ifndef stringutil_h
 #define stringutil_h
 
diff --git a/zypp/ByteCount.cc b/zypp/ByteCount.cc
new file mode 100644 (file)
index 0000000..2fef83f
--- /dev/null
@@ -0,0 +1,93 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/ByteCount.cc
+ *
+*/
+#include <iostream>
+
+#include "zypp/ByteCount.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+  const ByteCount::Unit ByteCount::B( 1, "B", 0 );
+  const ByteCount::Unit ByteCount::K( 1024, "K", 1 );
+  const ByteCount::Unit ByteCount::M( 1048576, "M", 1 );
+  const ByteCount::Unit ByteCount::G( 1073741824, "G", 2 );
+  const ByteCount::Unit ByteCount::T( 1099511627776, "T", 3 );
+
+  const ByteCount::Unit ByteCount::kB( 1000, "kB", 1 );
+  const ByteCount::Unit ByteCount::MB( 1000000, "MB", 1 );
+  const ByteCount::Unit ByteCount::GB( 1000000000, "GB", 2 );
+  const ByteCount::Unit ByteCount::TB( 1000000000000, "TB", 3 );
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   METHOD NAME : ByteCount::fillBlock
+  //   METHOD TYPE : ByteCount &
+  //
+  ByteCount & ByteCount::fillBlock( ByteCount blocksize_r )
+  {
+    if ( _count && blocksize_r )
+      {
+        SizeType diff = _count % blocksize_r;
+        if ( diff )
+          {
+            if ( _count > 0 )
+              _count += blocksize_r;
+            _count -= diff;
+          }
+      }
+    return *this;
+  }
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   METHOD NAME : ByteCount::bestUnit
+  //   METHOD TYPE : ByteCount::Unit
+  //
+  const ByteCount::Unit & ByteCount::bestUnit() const
+  {
+    SizeType usize( _count < 0 ? -_count : _count );
+    if ( usize < K.factor() )
+      return B;
+    if ( usize < M.factor() )
+      return K;
+    if ( usize < G.factor() )
+      return M;
+    if ( usize < T.factor() )
+      return G;
+    return T;
+  }
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   METHOD NAME : ByteCount::bestUnit1000
+  //   METHOD TYPE : ByteCount::Unit
+  //
+  const ByteCount::Unit & ByteCount::bestUnit1000() const
+  {
+    SizeType usize( _count < 0 ? -_count : _count );
+    if ( usize < kB.factor() )
+      return B;
+    if ( usize < MB.factor() )
+      return kB;
+    if ( usize < GB.factor() )
+      return MB;
+    if ( usize < TB.factor() )
+      return GB;
+    return TB;
+  }
+
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/ByteCount.h b/zypp/ByteCount.h
new file mode 100644 (file)
index 0000000..cab90d4
--- /dev/null
@@ -0,0 +1,153 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/ByteCount.h
+ *
+*/
+#ifndef ZYPP_BYTECOUNT_H
+#define ZYPP_BYTECOUNT_H
+
+#include <iosfwd>
+
+#include "zypp/base/Unit.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   CLASS NAME : ByteCount
+  //
+  /** Store and operate with byte count.
+   *
+  */
+  class ByteCount
+  {
+    friend std::ostream & operator<<( std::ostream & str, const ByteCount & obj );
+
+  public:
+
+    typedef base::Unit      Unit;
+    typedef Unit::ValueType SizeType;
+
+    /** \name Byte unit constants. */
+    //@{
+    /** 1 Byte */
+    static const Unit B;
+    /** 1024 Byte */
+    static const Unit K;
+    /** 1024^2 Byte */
+    static const Unit M;
+    /** 1024^3 Byte */
+    static const Unit G;
+    /** 1024^4 Byte */
+    static const Unit T;
+    /** 1000 Byte */
+    static const Unit kB;
+    /** 1000^2 Byte */
+    static const Unit MB;
+    /** 1000^3 Byte */
+    static const Unit GB;
+    /** 1000^4 Byte */
+    static const Unit TB;
+    //@}
+
+  public:
+
+    /** Default ctor */
+    ByteCount()
+    : _count( 0 )
+    {}
+    /** Ctor taking a count and optinal Unit. */
+    ByteCount( const SizeType count_r, const Unit & unit_r = B )
+    : _count( count_r * unit_r.factor() )
+    {}
+
+  public:
+
+    /** Conversion to SizeType. */
+    operator SizeType() const
+    { return _count; }
+
+
+    /** \name Arithmetic operations.
+     * \c + \c - \c * \c / are provided via conversion to SizeType.
+    */
+    //@{
+    ByteCount & operator+=( const SizeType rhs ) { _count += rhs; return *this; }
+    ByteCount & operator-=( const SizeType rhs ) { _count -= rhs; return *this; }
+    ByteCount & operator*=( const SizeType rhs ) { _count *= rhs; return *this; }
+    ByteCount & operator/=( const SizeType rhs ) { _count /= rhs; return *this; }
+
+    ByteCount & operator++(/*prefix*/) { _count += 1; return *this; }
+    ByteCount & operator--(/*prefix*/) { _count -= 1; return *this; }
+
+    ByteCount operator++(int/*postfix*/) { return _count++; }
+    ByteCount operator--(int/*postfix*/) { return _count--; }
+    //@}
+
+    /** Adjust count to multiple of \a blocksize_r (default 1K).
+     * Zero blocksize_r is treated as 1B.
+    */
+    ByteCount & fillBlock( ByteCount blocksize_r = K );
+
+    /** Return count adjusted to multiple of \a blocksize_r (default 1K). */
+    ByteCount fullBlocks( ByteCount blocksize_r = K ) const
+    { return ByteCount(*this).fillBlock( blocksize_r ); }
+
+  public:
+
+    /** Return the best Unit (B,K,M,G,T) for count. */
+    const Unit & bestUnit() const;
+
+    /** Return the best Unit (B,kB,MB,GB,TB) for count. */
+    const Unit & bestUnit1000() const;
+
+    /** \name Conversion to string.
+     * \li \a field_width_r Width for the number part (incl. precision)
+     * \li \a unit_width_r With for the unit symbol (without symbol if zero)
+     * \li \a prec_r Precision to use.
+     * \see zypp::base::Unit
+    */
+    //@{
+    /** Auto selected Unit and precision. */
+    std::string asString( unsigned field_width_r = 0,
+                          unsigned unit_width_r  = 1 ) const
+    { return asString( bestUnit(), field_width_r, unit_width_r ); }
+    /** Auto selected Unit. */
+    std::string asString( unsigned field_width_r,
+                          unsigned unit_width_r,
+                          unsigned prec_r ) const
+    { return asString( bestUnit(), field_width_r, unit_width_r, prec_r ); }
+    /** Auto selected precision. */
+    std::string asString( const Unit & unit_r,
+                          unsigned field_width_r = 0,
+                          unsigned unit_width_r  = 1 ) const
+    { return asString( unit_r, field_width_r, unit_width_r, unit_r.prec() ); }
+    /** Nothing auto selected. */
+    std::string asString( const Unit & unit_r,
+                          unsigned field_width_r,
+                          unsigned unit_width_r,
+                          unsigned prec_r ) const
+    { return unit_r.form( _count, field_width_r, unit_width_r, prec_r ); }
+    //@}
+
+  private:
+    SizeType _count;
+  };
+  ///////////////////////////////////////////////////////////////////
+
+  /** \relates ByteCount Stream output */
+  inline std::ostream & operator<<( std::ostream & str, const ByteCount & obj )
+  { return str << obj.asString(); }
+
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_BYTECOUNT_H
index 30c7ee1..9e15b1a 100644 (file)
@@ -7,6 +7,7 @@ SUBDIRS = base parser capability solver source detail media url
 
 include_HEADERS = NeedAType.h \
        Arch.h          \
+       ByteCount.h     \
        Capability.h    \
        CapFactory.h    \
        CapSet.h        \
@@ -41,6 +42,7 @@ lib_LTLIBRARIES =     lib@PACKAGE@.la
 
 lib@PACKAGE@_la_SOURCES = \
        Arch.cc         \
+       ByteCount.cc    \
        Capability.cc   \
        CapFactory.cc   \
        CapSet.cc       \
index 8177b74..a82b3d7 100644 (file)
@@ -16,7 +16,7 @@ include_HEADERS =     \
        PtrTypes.h      \
        ReferenceCounted.h      \
        String.h        \
-       StringVal.h     \
+       Unit.h          \
                \
                \
        ExternalDataSource.h
@@ -33,7 +33,7 @@ lib@PACKAGE@_base_la_SOURCES =        \
        IOStream.cc     \
        ReferenceCounted.cc     \
        String.cc       \
-       StringVal.cc    \
+       Unit.cc         \
                \
                \
        ExternalDataSource.cc
diff --git a/zypp/base/StringVal.cc b/zypp/base/StringVal.cc
deleted file mode 100644 (file)
index 22c75da..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/base/StringVal.cc
- *
-*/
-#include "zypp/base/StringVal.h"
-
-using namespace std;
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-  ///////////////////////////////////////////////////////////////////
-  namespace base
-  { /////////////////////////////////////////////////////////////////
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : StringVal::StringVal
-    // METHOD TYPE : Ctor
-    //
-    StringVal::StringVal()
-    {}
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : StringVal::StringVal
-    // METHOD TYPE : Ctor
-    //
-    StringVal::StringVal( const std::string & rhs )
-    : _value( rhs )
-    {}
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : StringVal::StringVal
-    // METHOD TYPE : Ctor
-    //
-    StringVal::StringVal( const StringVal & rhs )
-    : _value( rhs._value )
-    {}
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : StringVal::~StringVal
-    // METHOD TYPE : Dtor
-    //
-    StringVal::~StringVal()
-    {}
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : StringVal::operator=
-    // METHOD TYPE : const StringVal &
-    //
-    const StringVal & StringVal::operator=( const std::string & rhs )
-    {
-      _value = rhs;
-      return *this;
-    }
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : StringVal::operator=
-    // METHOD TYPE : const StringVal &
-    //
-    const StringVal & StringVal::operator=( const StringVal & rhs )
-    {
-      _value = rhs._value;
-      return *this;
-    }
-
-    /////////////////////////////////////////////////////////////////
-  } // namespace base
-  ///////////////////////////////////////////////////////////////////
-  /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
diff --git a/zypp/base/StringVal.h b/zypp/base/StringVal.h
deleted file mode 100644 (file)
index 5aa5ab0..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/base/StringVal.h
- *
-*/
-#ifndef ZYPP_BASE_STRINGVAL_H
-#define ZYPP_BASE_STRINGVAL_H
-
-#include <iosfwd>
-#include <string>
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-  ///////////////////////////////////////////////////////////////////
-  namespace base
-  { /////////////////////////////////////////////////////////////////
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // CLASS NAME : StringVal
-    //
-    /** */
-    class StringVal
-    {
-    public:
-      /** */
-      operator const std::string &() const
-      { return _value; }
-      /** */
-      const std::string & asString() const
-      { return _value; }
-    protected:
-      /** */
-      StringVal();
-      /** */
-      explicit
-      StringVal( const std::string & rhs );
-      /** */
-      StringVal( const StringVal & rhs );
-      /** */
-      ~StringVal();
-      /** */
-      const StringVal & operator=( const std::string & rhs );
-      /** */
-      const StringVal & operator=( const StringVal & rhs );
-    private:
-      std::string _value;
-    };
-    ///////////////////////////////////////////////////////////////////
-
-    inline std::ostream & operator<<( std::ostream & str, const StringVal & obj )
-    { return str << static_cast<const std::string &>(obj); }
-
-    ///////////////////////////////////////////////////////////////////
-
-    inline bool operator==( const StringVal & lhs, const StringVal & rhs )
-    { return lhs.asString() == rhs.asString(); }
-
-    inline bool operator==( const StringVal & lhs, const std::string & rhs )
-    { return lhs.asString() == rhs; }
-
-    inline bool operator==( const std::string & lhs, const StringVal & rhs )
-    { return lhs == rhs.asString(); }
-
-
-    inline bool operator!=( const StringVal & lhs, const StringVal & rhs )
-    { return !( lhs == rhs ); }
-
-    inline bool operator!=( const StringVal & lhs, const std::string & rhs )
-    { return !( lhs == rhs ); }
-
-    inline bool operator!=( const std::string & lhs, const StringVal & rhs )
-    { return !( lhs == rhs ); }
-
-    /////////////////////////////////////////////////////////////////
-  } // namespace base
-  ///////////////////////////////////////////////////////////////////
-  /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_BASE_STRINGVAL_H
diff --git a/zypp/base/Unit.cc b/zypp/base/Unit.cc
new file mode 100644 (file)
index 0000000..264a1d8
--- /dev/null
@@ -0,0 +1,42 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/base/Unit.cc
+ *
+*/
+#include "zypp/base/String.h"
+
+#include "zypp/base/Unit.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace base
+  { /////////////////////////////////////////////////////////////////
+
+    std::string Unit::form( double val_r,
+                            const std::string & symbol_r,
+                            unsigned field_width_r,
+                            unsigned unit_width_r,
+                            unsigned prec_r )
+    {
+      std::string ret = str::form( "%*.*f", field_width_r, prec_r, val_r );
+      if ( unit_width_r )
+        {
+          ret +=  str::form( " %*s", unit_width_r, symbol_r.c_str() );
+        }
+      return ret;
+    }
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace base
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/base/Unit.h b/zypp/base/Unit.h
new file mode 100644 (file)
index 0000000..a59ba71
--- /dev/null
@@ -0,0 +1,103 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/base/Unit.h
+ *
+*/
+#ifndef ZYPP_BASE_UNIT_H
+#define ZYPP_BASE_UNIT_H
+
+#include <iosfwd>
+#include <string>
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace base
+  { /////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // CLASS NAME : Unit
+    //
+    /** Simple handling of Units.
+     *
+     * Unit strores factor and symbol, and a precision value for printing.
+     * \ref form builds a string from a value according to the format
+     * specification.
+     * \code
+     * static const Unit B( 1, "B", 0 );
+     * static const Unit K( 1024, "K", 1 );
+     * static const Unit M( 1048576, "M", 1 );
+     * static const Unit G( 1073741824, "G", 2 );
+     * static const Unit T( 1099511627776, "T", 3 );
+     * \endcode
+    */
+      class Unit
+      {
+      public:
+        typedef long long ValueType;
+
+        /** Default ctor */
+        Unit()
+        : _factor( 1 )
+        , _prec( 0 )
+        {}
+
+        /** ctor */
+        Unit( ValueType factor_r, std::string symbol_r, unsigned prec_r )
+        : _factor( factor_r )
+        , _symbol( symbol_r )
+        , _prec( prec_r )
+        {}
+
+        ValueType factor() const
+        { return _factor; }
+
+        const std::string & symbol() const
+        { return _symbol; }
+
+        unsigned prec() const
+        { return _prec; }
+
+        /** Build string representation of \a val_r. */
+        std::string form( ValueType val_r,
+                          unsigned field_width_r = 0,
+                          unsigned unit_width_r  = 1 ) const
+        { return form( val_r, field_width_r, unit_width_r, _prec ); }
+
+        std::string form( ValueType val_r,
+                          unsigned field_width_r,
+                          unsigned unit_width_r,
+                          unsigned prec_r ) const
+        { return form( double(val_r)/_factor, _symbol,
+                       field_width_r, unit_width_r, prec_r ); }
+
+
+        static std::string form( double val_r,
+                                 const std::string & symbol_r,
+                                 unsigned field_width_r,
+                                 unsigned unit_width_r,
+                                 unsigned prec_r );
+
+      private:
+        ValueType   _factor;
+        std::string _symbol;
+        unsigned    _prec;
+      };
+    ///////////////////////////////////////////////////////////////////
+
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace base
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_BASE_UNIT_H
diff --git a/zypp/solver/testsuite/.cvsignore b/zypp/solver/testsuite/.cvsignore
new file mode 100644 (file)
index 0000000..65e66e2
--- /dev/null
@@ -0,0 +1,10 @@
+Makefile.in
+Makefile
+.deps
+.libs
+*.o
+*.lo
+*.a
+*.la
+*.single
+*.multi