/*
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *         (C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#ifndef __SIZE_H
#define __SIZE_H

/* daddr_t */
#include <sys/types.h>

class QString;

/** @brief Class storing a size value.
  *
  * This class stores a size value and supports
  * conversions to other units. The default unit
  * used for all operations is Size::Byte.
  */
class Size {
public:
   enum Unit {
      Byte,
      Blocks,  /**< Harddisk blocks */
      KB,
      MB,
      GB,
      TB
   };

   Size(daddr_t = 0, Unit = Byte);

   void  setDefaultUnit(Unit);

   bool  operator== (const Size&)  const;
   bool  operator<  (const Size&)  const;
	bool  operator<= (const Size&)  const;
   bool  operator>  (const Size&)  const;
	bool  operator>= (const Size&)  const;

   Size&  operator=(daddr_t);
   Size&  operator=(const Size&);
   Size&  operator+=(daddr_t);
   Size&  operator+=(const Size&);

   void  set(daddr_t value);
   void  set(daddr_t value, Unit);

   daddr_t  get()        const;
   daddr_t  get(Unit u)  const;

   QString  toString()      const;
   QString  toString(Unit)  const;

   operator daddr_t()  const;

private:
   daddr_t  value;       /**< value is the size in bytes. */

 /**
  * By changing this, all operations use the new
  * unit rather than Size::Byte. It's only
  * overridden when a size unit is specified
  * when calling a method.
  *
  * @sa setDefaultUnit()
  */
  Unit     defaultUnit;
};

#endif /* __SIZE_H */
