/*!
  @header FTVersionImpl
  @abstract Module of FT
 
  @availability OS X, GNUstep
  @copyright 2004, 2005, 2006 Free Software Foundation, Inc.
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA

  <pre>
  -------------------------------------------------------------------------
  Modification history

  04.10.05 ola     initial version
  23.08.06 ola     license changed
  -------------------------------------------------------------------------
  </pre>
*/

#include <FT/FTVersionImpl.h>

@implementation FTVersionImpl

- initWithMajor: (unsigned) aMajorNr withMinor: (unsigned) aMinorNr
  withBuild: (unsigned) aBuildNr asState: (ft_releaseState_t) aState {

  self = [super init];
  
  self->major = aMajorNr;
  self->minor = aMinorNr;
  self->build = aBuildNr;
  self->state = aState;
  
  self->versionString = [FTVersionImpl createVersionStringForMajor: aMajorNr
    forMinor: aMinorNr forBuild: aBuildNr forState: aState ];
  
  return self;
}


- (void) dealloc {
  if( nil != self->versionString ) {
    [self->versionString release];
  }
  
  [super dealloc];
}


- (unsigned) build {
  return self->build;
}


+ (char) characterForState: (ft_releaseState_t) aState {
  char toReturn;
  
  switch( aState ) {
    case FT_VERSION_SNAPSHOT: 
      toReturn = 'S';
      break;
    case FT_VERSION_ALPHA:
      toReturn = 'A';
      break;
    case FT_VERSION_BETA:
      toReturn = 'B';
      break;
    case FT_VERSION_RC:
      toReturn = 'C';
      break;
    case FT_VERSION_RELEASE:
      toReturn = 'R';
      break;
    default:
      toReturn = '?';
  }
  
  return toReturn;
}


+ (NSString *) createVersionStringForMajor: (unsigned) aMajorNr
  forMinor: (unsigned) aMinorNr forBuild: (unsigned) aBuildNr
  forState: (ft_releaseState_t) aState {
  
  return [[NSString alloc] 
    initWithFormat: @"%c-%u.%u.%u",
    [self characterForState: aState], aMajorNr, aMinorNr, aBuildNr];
}


- (NSString *) description {
  return self->versionString;
}


- (unsigned) hash {
  return [self->versionString hash];
}


- (BOOL) isEqual: (id) anObject {
  return [self->versionString isEqual: anObject];
}


- (unsigned) major {
  return self->major;
}


- (unsigned) minor {
  return self->minor;
}


- (ft_releaseState_t) releaseState {
  return self->state;
}


- (NSString *) versionString {
  return self->versionString;
}

@end
