/* $Id: Object,v 1.1.1.1 2008/09/21 21:30:13 kiesling Exp $ -*-C-*-*/

/*
  This file is part of ctalk.
  Copyright  2005-2008  Robert Kiesling, ctalk@ctalklang.org.
  Permission is granted to copy this software provided that this copyright
  notice is included in all source code modules.

  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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

/*
 *   Object methods.  The Object class is defined by default.  All 
 *   other classes are subclasses of Object.  
 */

#ifndef NULL
#define NULL ((void *)0)
#endif

#ifndef MAXLABEL
#define MAXLABEL 256
#endif

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE (!(FALSE))
#endif



/* 
 *    value (void) 
 *      Return the object's value instance variable.
 */

Object instanceMethod value (void) {
  OBJECT *val_obj;
  if (!strcmp (__ctalk_self_internal () -> __o_name, "value"))
    return __ctalk_self_internal ();
  val_obj = __ctalkGetInstanceVariable (self, "value", 1);
  return val_obj;
}

/*
 *    className (void)
 *      Return a String containing the class of the receiver.
 */
Object instanceMethod className (void) {

  returnObjectClass String;

  methodReturnString(self->__o_classname)
}

/*
 *    name (void)
 *      Return the name of the receiver as a String object.
 */

Object instanceMethod name (void) {

  returnObjectClass String;

  methodReturnString(self->__o_name)
}

/*
 *    is (char *classname)
 *      Return True of the receiver is a member of class, 
 *      "classNameArg," False otherwise.
 *
 *    TO DO - In the next release, make sure we can use 
 *     "if (strcmp (self class, self name))..., "
 *     and avoid problems with the class library not being
 *     loaded.
 */

Object instanceMethod is (char *classNameArg) {

  returnObjectClass Integer;

  if (self className == classNameArg name) {
    methodReturnTrue
  } else {
    methodReturnFalse
  }
}

/*
 *    addInstanceVariable (char *name, OBJECT *value)
 *      Add an instance variable object "name" to the receiver,
 *      or set an existing variable.
 *
 *    
 */
Object instanceMethod addInstanceVariable (char *name, OBJECT *value) {
  __ctalkAddInstanceVariable (self, __ctalk_to_c_char_ptr (name), value);
  methodReturnSelf
}

/* 
 *   delete (void)
 *   Delete the receiver object.
 */

Object instanceMethod delete (void) {
  __ctalkDeleteObject (self);
  methodReturnNULL
}


