/* Generated automatically by jlpp - do not edit. */ #include static jakelib::lang::String* jakelib2_strings[] = {null, null, null}; // "jakelib.lang.Class.isInstance" static jchar chars_jakelib2_str_0[] = {106,97,107,101,108,105,98,46,108,97,110,103,46,67,108,97,115,115,46,105,115,73,110,115,116,97,110,99,101}; // "class " static jchar chars_jakelib2_str_1[] = {99,108,97,115,115,32}; // "[]" static jchar chars_jakelib2_str_2[] = {91,93}; #line 1 "lang/Class.jlc" // -*- c++ -*- /* * Jakelib2 - General purpose C++ library * Copyright (C) 2001 Florian Wolff (florian@donuz.de) * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: Class.jlc,v 1.11 2003/09/27 08:10:28 florian Exp $ */ #include "jakelib2.h" #include #include using namespace jakelib::lang; JAKELIB_IMPLEMENT_CLASS("jakelib.lang.Class", Class, Object); JAKELIB_IMPLEMENT_ARRAY(Class); /*****************************************************************************\ * Class | *****************************************************************************/ Class::Class(classtype type, char* name, Class* superClass, ...) { // !WARNING! // // Don't access any of superClass's members in constructor! // // Don't create (new) any gc-able Objects here! (This will cause problems // with static initializers on certain platforms, namely MinGW.) // // !WARNING! //printf("Class:Class(,%s,)\n", name); int idx = 0; va_list ptr; this->name_cstr = name; this->type = type; this->arrayElementClass = null; this->numInterfaces = 0; this->interfaces = null; switch(type) { case CLASS: this->superClass = superClass; // Count the number of interfaces this class implements: va_start(ptr, superClass); while (va_arg(ptr, Class*) != null) { numInterfaces ++; } // Put all interfaces's Class objects in an array: interfaces_carray = (Class**) malloc(sizeof(Class*) * numInterfaces); va_start(ptr, superClass); for (idx = 0; idx < numInterfaces; idx++) { interfaces_carray[idx] = va_arg(ptr, Class*); //printf("Class::Class(%s) - Class, implements an interface\n", name); } break; case INTERFACE: //printf("Class::Class(%s) - Interface\n", name); break; } } Class::Class(Class *elementClass) { //printf("Class:Class()\n"); this->name = null; this->arrayElementClass = elementClass; this->superClass = &Object::_Object_Class; this->type = ARRAY; this->numInterfaces = 0; this->interfaces_carray = null; this->interfaces = null; } Class::Class(char *name) { //printf("Class:Class(%s)\n", name); this->name_cstr = name; this->arrayElementClass = null; this->superClass = &Object::_Object_Class; this->type = PRIMITIVE; this->numInterfaces = 0; this->interfaces_carray = null; this->interfaces = null; } /*****************************************************************************\ * isInstance | *****************************************************************************/ jboolean Class::isInstance(Object* obj) { if (obj == null) throw new NullPointerException(JAKELIB_AT2(JAKELIB_ONDEMAND(jakelib2_strings[0], new jakelib::lang::String(chars_jakelib2_str_0, 0, 29)))); return (obj->getClass() == this || (superClass != null && superClass->isInstance(obj))); } /*****************************************************************************\ * instanceOf | *****************************************************************************/ jboolean Class::instanceOf(String* name) { if (getName()->equals(name)) return true; Classs *interf = getInterfaces(); for (int idx = 0; idx < interf->length(); idx++) { if (interf->get(idx)->getName()->equals(name)) return true; } return (superClass != null && superClass->instanceOf(name)); } /*****************************************************************************\ * toString | *****************************************************************************/ String* Class::toString() { return JAKELIB_ONDEMAND(jakelib2_strings[1], new jakelib::lang::String(chars_jakelib2_str_1, 0, 6)) ->plus( getName()); } /*****************************************************************************\ * getName | *****************************************************************************/ String* Class::getName() { switch(type) { case CLASS: case INTERFACE: case PRIMITIVE: if (name == null) { name = new String(name_cstr); } return name; case ARRAY: if (name == null) { name = arrayElementClass->getName() ->plus( JAKELIB_ONDEMAND(jakelib2_strings[2], new jakelib::lang::String(chars_jakelib2_str_2, 0, 2))); } return name; } return name;//suppress MSVC warning } /*****************************************************************************\ * getSuperclass | *****************************************************************************/ Class* Class::getSuperclass() { return superClass; } /*****************************************************************************\ * isInterface | *****************************************************************************/ jboolean Class::isInterface() { return (type == INTERFACE); } /*****************************************************************************\ * isArray | *****************************************************************************/ jboolean Class::isArray() { return (type == ARRAY); } /*****************************************************************************\ * isPrimitive | *****************************************************************************/ jboolean Class::isPrimitive() { return (type == PRIMITIVE); } /*****************************************************************************\ * getInterfaces | *****************************************************************************/ Classs* Class::getInterfaces() { if (interfaces == null) { Classs *tmp = new Classs(numInterfaces); for (int idx = 0; idx < numInterfaces; idx++) { tmp->set(idx, interfaces_carray[idx]); } interfaces = tmp; } return interfaces; } /*****************************************************************************\ * getComponentType | *****************************************************************************/ Class* Class::getComponentType() { return arrayElementClass; }