/* 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/Long.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: Long.jlc,v 1.4 2003/09/27 08:10:28 florian Exp $ */ #include "jakelib2.h" #include "jakelib2/lang/Long.h" #include "jakelib2/lang/Integer.h" #include "jakelib2/lang/Character.h" using namespace jakelib::lang; JAKELIB_IMPLEMENT_CLASS_1("jakelib.lang.Long", Long, Number, Comparable) #if defined(MSVC) const jlong Long::MAX_VALUE = 0x7FFFFFFFFFFFFFFFL; const jlong Long::MIN_VALUE = 0x8000000000000000L; #else const jlong Long::MAX_VALUE = 0x7FFFFFFFFFFFFFFFLL; const jlong Long::MIN_VALUE = 0x8000000000000000LL; #endif /*****************************************************************************\ * Long | *****************************************************************************/ Long::Long(jlong value) { this->value = value; } Long::Long(String* s) { value = parseLong(s); } /*****************************************************************************\ * hashCode | *****************************************************************************/ jint Long::hashCode() { return (jint) value & 0xFFFFFFFF; } /*****************************************************************************\ * equals | *****************************************************************************/ jboolean Long::equals(Object* obj) { if (obj == null || !obj->getClass()->isInstance(this)) return false; Long* object = (Long*) obj; return ( value == object->value ); } /*****************************************************************************\ * toString | *****************************************************************************/ String* Long::toString() { return toString(value); } String* Long::toString(jlong value) { return toString(value, 10); } String* Long::toString(jlong value, int radix) { if (value == 0) return new String("0"); if (radix < Character::MIN_RADIX || radix > Character::MAX_RADIX) radix = 10; jchar buf[65]; int pos = 65; 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, 65-pos); } /*****************************************************************************\ * parseLong | *****************************************************************************/ jlong Long::parseLong(String* str) { return parseLong(str, 10); } jlong Long::parseLong(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::Long::parseLong"))); if (radix < Character::MIN_RADIX) throw new NumberFormatException(JAKELIB_ONDEMAND(jakelib2_strings[1], new jakelib::lang::String(chars_jakelib2_str_1, 0, 6)) ->plus( radix )->plus( JAKELIB_ONDEMAND(jakelib2_strings[2], new jakelib::lang::String(chars_jakelib2_str_2, 0, 31)) )->plus( JAKELIB_AT2("jakelib::lang::Long::parseLong"))); if (radix > Character::MAX_RADIX) throw new NumberFormatException(JAKELIB_ONDEMAND(jakelib2_strings[3], new jakelib::lang::String(chars_jakelib2_str_3, 0, 6)) ->plus( radix )->plus( JAKELIB_ONDEMAND(jakelib2_strings[4], new jakelib::lang::String(chars_jakelib2_str_4, 0, 34)) )->plus( JAKELIB_AT2("jakelib::lang::Long::parseLong"))); 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::Long::parseLong"))); return i; } /*****************************************************************************\ * xxxValue | *****************************************************************************/ jbyte Long::byteValue() { return (jbyte) value; }; jfloat Long::floatValue() { return (jfloat) value; }; jint Long::intValue() { return (jint) value; }; jlong Long::longValue() { return value; }; jdouble Long::doubleValue() { return (jdouble) value; }; jshort Long::shortValue() { return (jshort) value;} ; /*****************************************************************************\ * toUnsignedString | *****************************************************************************/ String* Long::toUnsignedString(jlong lin, int shift) { jlong l = lin; char buf[65]; int pos = 65; int radix = 1 << shift; int mask = radix - 1; buf[--pos] = '\0'; do { buf[--pos] = Integer::digits[l & mask]; l >>= shift; } while (l != 0); return new String(&buf[pos]); } String* Long::toHexString(jlong i) { return toUnsignedString(i, 4); } String* Long::toBinaryString(jlong i) { return toUnsignedString(i, 1); } String* Long::toOctalString(jlong i) { return toUnsignedString(i, 3); } /*****************************************************************************\ * valueOf | *****************************************************************************/ Long* Long::valueOf(String* str, int radix) { return new Long(parseLong(str, radix)); } Long* Long::valueOf(String* str) { return new Long(parseLong(str, 10)); } /*****************************************************************************\ * decode | *****************************************************************************/ // Long Long::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 = Long::parseInt(str.substring(index), radix); // if (negative) // result = -result; // return Long(result); // } // catch (NumberFormatException *e) { // // If number is Long.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 = Long::valueOf(constant, radix); // } // return result; // } // Long Long::decode(const char* str) // { // return decode(String(str)); // } /*****************************************************************************\ * compareTo | *****************************************************************************/ int Long::compareTo(Long* obj) { jlong otherValue = obj->value; return (value < otherValue ? -1 : (value > otherValue ? 1 : 0)); } int Long::compareTo(Object* obj) { return compareTo((Long*) obj); }