/* -*- mode: c++; indent-tabs-mode: nil; -*-
 *
 * This file is part of the Mango recipe management distribution.
 * Copyright (c) 2000-2003, Roland Jesse
 * All rights reserved.
 *
 * For license and copyright information see the file COPYRIGHT or 
 * <http://www.opensource.org/licenses/bsd-license.html>.
 *
 * $Id: AmbrosiaFingerprint.h,v 1.2 2003/03/17 22:34:48 rjesse Exp $
 */
 
#ifndef AMBROSIA_FINGERPRINT_H
#define AMBROSIA_FINGERPRINT_H

#include <qdatetime.h>
class Recipe;

/*!
  This class implements Ambrosia's fingerprint for a recipe.

  This id consists of two 32 bit parts as documented in
  <http://www.3lands.ch/zip_ambrosia/fp.txt>.

  - Part 1: coded date, bit 0..30
    # minute: 6 bit
    # hour: 5 bit
    # day: 5 bit
    # month: 4 bit
    # year-1980: 11 bit
  - Part 2:
    # serial id: 20 bit
    # creator id: 12 bit
*/
class AmbrosiaFingerprint {
   public:
      AmbrosiaFingerprint();
      AmbrosiaFingerprint( const Recipe&);
      AmbrosiaFingerprint( const QString&);

      AmbrosiaFingerprint operator=( const AmbrosiaFingerprint&);
      AmbrosiaFingerprint operator=( const QString&);

      AmbrosiaFingerprint& calculateFP( const Recipe&);
      void extractFP( const QString&);
      void update( const QDate& d = QDate( 1899, 12, 21), const QTime& t = QTime( 0, 0));

      QString asString() const;
      Q_INT32 part1() const;
      Q_INT32 part2() const;
      QDate date() const;
      Q_INT32 creatorId() const;
      Q_INT32 counter() const;

   private:
      Q_INT32 m_part1;          //!< Part1 of the id.
      Q_INT32 m_part2;          //!< Part2 of the id.
      Q_INT32 calculatePart1( const QDate&, const QTime&) const;
      Q_INT32 calculatePart2( const QString&) const;
      Q_INT32 getNextCounter() const;
};
#endif // AMBROSIA_FINGERPRINT_H
