//
//	MiscStorage.m -- a Storage subclass with a cursor
//		Written by Doug McClure (c) 1994 by Doug McClure.
//				Version 1.0.  All rights reserved.
//
//		This notice may not be removed from this source code.
//
//	This object is included in the MiscKit by permission from the author
//	and its use is governed by the MiscKit license, found in the file
//	"LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
//	for a list of all applicable permissions and restrictions.
//	

/*
 * $RCSfile$
 *
 * $Author$
 *
 * $Revision$
 *
 * $Date$
 *
*/

#import <misckit/MiscStorage.h>

#define MiscStorageVersion	100

@implementation MiscStorage

- (unsigned int)currentPosition
{
  return cursor;
}


- (void *)setFirstElement
{
  if ( [self count] )
    {
      cursor = 0;
      return [self elementAt:cursor];
    }
  
  return nil;
}


- (void *)setLastElement
{
  if ( [self count] )
    {
      cursor = [self count] - 1;
      return [self elementAt:cursor];
    }
  
  return nil;
}


- (void *)setNextElement
{
  if ( (cursor+1) < [self count] )
    {
      return [self elementAt:(++cursor)];
    }
  
  return nil;
}


- (void *)setPreviousElement
{
  if ( cursor != 0 )
    {
      return [self elementAt:(--cursor)];
    }

  return nil;
}


- (void *)setTo:(unsigned int)aPosition
{
  if ( aPosition < [self count] )
    {
      cursor = aPosition;
      return [self elementAt:cursor];
    }

  return nil;
}

@end
