/* Generated automatically by jlpp - do not edit. */ #include static jakelib::lang::String* jakelib2_strings[] = {null, null, null, null, null}; // "null" static jchar chars_jakelib2_str_0[] = {110,117,108,108}; // "radix " static jchar chars_jakelib2_str_1[] = {114,97,100,105,120,32}; // " less than Character::MIN_RADIX" static jchar chars_jakelib2_str_2[] = {32,108,101,115,115,32,116,104,97,110,32,67,104,97,114,97,99,116,101,114,58,58,77,73,78,95,82,65,68,73,88}; // "radix " static jchar chars_jakelib2_str_3[] = {114,97,100,105,120,32}; // " greater than Character::MAX_RADIX" static jchar chars_jakelib2_str_4[] = {32,103,114,101,97,116,101,114,32,116,104,97,110,32,67,104,97,114,97,99,116,101,114,58,58,77,65,88,95,82,65,68,73,88}; #line 1 "lang/Short.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: Short.jlc,v 1.4 2003/09/27 08:10:28 florian Exp $ */ #include "jakelib2.h" #include "jakelib2/lang/Short.h" #include "jakelib2/lang/Integer.h" #include "jakelib2/lang/Character.h" #ifdef HAVE_ERRNO_H # include #endif using namespace jakelib::lang; JAKELIB_IMPLEMENT_CLASS_1("jakelib.lang.Short", Short, Number, Comparable) const jshort Short::MAX_VALUE = 32767; const jshort Short::MIN_VALUE = -32768; /*****************************************************************************\ * Short | *****************************************************************************/ Short::Short(jshort value) { this->value = value; } Short::Short(String* s) { value = parseShort(s); } /*****************************************************************************\ * hashCode | *****************************************************************************/ jint Short::hashCode() { return value; } /*****************************************************************************\ * equals | *****************************************************************************/ jboolean Short::equals(Object* obj) { if (obj == null || !obj->getClass()->isInstance(this)) return false; Short* object = (Short*) obj; return ( value == object->value ); } /*****************************************************************************\ * toString | *****************************************************************************/ String* Short::toString() { return toString(value); } String* Short::toString(jshort value) { if (value == 0) return new String("0"); char buf[7]; int pos = 7; jboolean negative = (value < 0); buf[--pos] = '\0'; if (!negative) { value = -value; } while (value < 0) { buf[--pos] = Integer::digits[-(value % 10)]; value /= 10; } if (negative) buf[--pos] = '-'; return new String(&buf[pos]); } String* Short::toString(jshort value, int radix) { if (value == 0) return new String("0"); if (radix < Character::MIN_RADIX || radix > Character::MAX_RADIX) radix = 10; if (radix == 10) { return toString(value); }; jchar buf[17]; int pos = 17; jboolean negative = (value < 0); if (!negative) { value = -value; } while (value < 0) { buf[--pos] = Integer::digits[-(value % radix)]; value /= radix; } if (negative) buf[--pos] = '-'; return new String(buf, pos, 17-pos); } /*****************************************************************************\ * parseShort | *****************************************************************************/ jshort Short::parseShort(String* str) { return parseShort(str, 10); } jshort Short::parseShort(String* str, int radix) { if (str == null) throw new NumberFormatException(JAKELIB_ONDEMAND(jakelib2_strings[0], new jakelib::lang::String(chars_jakelib2_str_0, 0, 4)) ->plus( JAKELIB_AT2("jakelib.lang.Short.parseShort"))); if (radix < Character::MIN_RADIX) throw new NumberFormatException(JAKELIB_ONDEMAND(jakelib2_strings[1], new jakelib::lang::String(chars_jakelib2_str_1, 0, 6)) ->plus( (jlong) radix )->plus( JAKELIB_ONDEMAND(jakelib2_strings[2], new jakelib::lang::String(chars_jakelib2_str_2, 0, 31)) )->plus( JAKELIB_AT2("jakelib.lang.Short.parseShort"))); if (radix > Character::MAX_RADIX) throw new NumberFormatException(JAKELIB_ONDEMAND(jakelib2_strings[3], new jakelib::lang::String(chars_jakelib2_str_3, 0, 6)) ->plus( (jlong) radix )->plus( JAKELIB_ONDEMAND(jakelib2_strings[4], new jakelib::lang::String(chars_jakelib2_str_4, 0, 34)) )->plus( JAKELIB_AT2("jakelib.lang.Short.parseShort"))); if (str->charAt(0) == '\0') throw new NumberFormatException(); char* ptr; jint i = strtol(str->latin1(), &ptr, radix); if (*ptr != '\0') throw new NumberFormatException(str ->plus( JAKELIB_AT2("jakelib.lang.Short.parseShort"))); return i; } /*****************************************************************************\ * xxxValue | *****************************************************************************/ jbyte Short::byteValue() { return (jbyte) value; }; jfloat Short::floatValue() { return (jfloat) value; }; jint Short::intValue() { return (jint) value; }; jlong Short::longValue() { return (jlong) value; }; jdouble Short::doubleValue() { return (jdouble) value; }; jshort Short::shortValue() { return value;} ; /*****************************************************************************\ * valueOf | *****************************************************************************/ Short* Short::valueOf(String* str, int radix) { return new Short(parseShort(str, radix)); } Short* Short::valueOf(String* str) { return new Short(parseShort(str, 10)); } /*****************************************************************************\ * decode | *****************************************************************************/ // Short Short::decode(String& str) // { // int radix = 10; // int index = 0; // jboolean negative = false; // // Handle minus sign, if present // if (str.startsWith("-")) { // negative = true; // index++; // } // // Handle radix specifier, if present // if (str.startsWith("0x", index) || str.startsWith("0X", index)) { // index += 2; // radix = 16; // } // else if (str.startsWith("#", index)) { // index ++; // radix = 16; // } // else if (str.startsWith("0", index) && str.length() > 1 + index) { // index ++; // radix = 8; // } // if (str.startsWith("-", index)) // throw new NumberFormatException("Negative sign in wrong position"); // try { // int result = Short::parseInt(str.substring(index), radix); // if (negative) // result = -result; // return Short(result); // } // catch (NumberFormatException *e) { // // If number is Short.MIN_VALUE, we'll end up here. The next line // // handles this case, and causes any genuine format error to be // // rethrown. // String constant = negative ? String("-" + str.substring(index)) // : str.substring(index); // result = Short::valueOf(constant, radix); // } // return result; // } // Short Short::decode(const char* str) // { // return decode(String(str)); // } /*****************************************************************************\ * compareTo | *****************************************************************************/ int Short::compareTo(Short* obj) { jint otherValue = obj->value; return (value < otherValue ? -1 : (value > otherValue ? 1 : 0)); } int Short::compareTo(Object* obj) { return compareTo((Short*) obj); }