'''
### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ###
                   308-304 - Object-Oriented Software Design
                                 ASSIGNMENT  1

   CCoord.py ---
      class CellCoordinate implementation.

   last modified: 01/24/02
                       ===============================
                             Copyright (c)  2002
                            Jean-Sébastien BOLDUC
                             (jseb@cs.mcgill.ca)

                        McGill University  (Montréal)
                       ===============================

### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ###
'''

import types

class CellCoordinate:
  '''
  Encapsulated coordinates of cells in a spreadsheet.

  Note: might in the future want to implement "coordinate arithmetic"
  by means of __add__ etc.
  '''

  ### -------------------------------------------------------------  API -- ###

  def __init__(self, row = 1, column = 1):
    ''' row:Integer, column:Integer -> 
    
    CellCoordinate constructor. Both arguments must be positive.
    A KeyError is raised on bad arguments.
    '''
    # Explicitly declare private variables to hold row & column indexes:
    self.__row = None
    self.__col = None
    
    self.setRow(row)
    self.setColumn(column)

  def getRow(self):
    ''' -> :Integer

    Return the row coordinate.
    '''
    return self.__row

  def getColumn(self):
    ''' -> :Integer

    Return the column coordinate.
    '''
    return self.__col

  def setRow(self, row = 1):
    '''row:Integer ->

    Change the row value. The argument must be a positive Integer. 
    A KeyError is raised on bad argument.
    '''
    # Validate row index:
    if not self.__validateIndex(row):
      raise KeyError, 'row must be a positive Integer'
    # Store the value in private variable.
    self.__row = row

  def setColumn(self, column = 1):
    '''column:Integer ->

    Change the column value. The argument must be a positive Integer. 
    A KeyError is raised on bad argument.
    '''
    # Validate column index:
    if not self.__validateIndex(column):
      raise KeyError, 'column must be a positive Integer'
    # Store the value in private variable.
    self.__col = column

  def __str__(self):
    ''' -> :String

    Return the string representation of the cell coordinate.
    Example: with row=2, column=88, __str__ will return <CellCoordinate:2,88>
    '''
    return "<CellCoordinate:%d,%d.>" % (self.__row, self.__col)

  ### -------------------------------------------------  PRIVATE METHODS -- ###

  def __validateIndex(self, index):
    ''' index: -> Boolean

    Return true if index is a positive Integer; false otherwise.
    '''
    if type(index) == types.IntType and index>0:
      return 1
    return 0