/*
 * HnString.hh
 *
 * DO NOT EDIT THIS FILE!
 *
 * This file is automatically generated by obj2ptr.
 * 2006/08/03 17:37:29
 */

#ifndef _HnString_hh
#define _HnString_hh

#ifndef _HNSRTIMP
#ifdef _MSC_VER
#define _HNSRTIMP _declspec(dllimport)
#else
#define _HNSRTIMP
#endif
#endif

#include "HnSRTree/HnPointer.hh"

#include <string.h>
class HnStringVector;
class HnString;

/*
 * HnString
 */

class HnStringObj;

class _HNSRTIMP HnString: public HnPointer {
private:
    friend class HnStringObj;
    HnString(const HnStringObj *ptr) {
	HnPointer::assign((HnObject *)ptr);
    }
    HnStringObj *getObject(void) const {
	return (HnStringObj *)HnPointer::getObject();
    }
public:
    static const HnString null;
    HnString(void) {}
public:
    HnString(const HnString &string): HnPointer(string) {};
    HnString(const char *ptr);
    operator char *(void) const;
    HnString operator + (const char *ptr) const;
    HnString operator + (int value) const;
    HnString operator + (double value) const;
    HnString &operator += (const char *ptr);
    HnString &operator += (const HnString &value);
    HnString &operator += (char c);
    HnString &operator += (int value);
    HnString &operator += (double value);
    void append(const char *ptr, int n);
    void append(const char *ptr);
    void append(const HnString &string);
    HnBool equals(const char *ptr, int n) const;
    HnBool equals(const char *ptr) const;
    static HnString format(const char *format, ... )
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6)
__attribute__ ((format (printf, 1, 2)))
#endif
    ;

    /* constructor and destructor */
    _HNSRTIMP friend HnString
    new_HnString(void);
    _HNSRTIMP friend HnString
    new_HnString(const char *ptr, int n);
    _HNSRTIMP friend HnString
    new_HnString(const HnString &string);

    /* chars and length */
    const char *chars(void) const;
    const char &get(int i) const;
    const char &operator[](int i) const;
    int length(void) const;
    HnString toString(void) const;

    /* concat */
    /*
     * NOTE:
     *	The current implementation copies the entire string on concat.
     */
    HnString concat(const char *ptr, int n) const;
    HnString concat(const char *ptr) const;
    HnString concat(const HnString &string) const;

    /* utilities */
    HnBool equals(const HnString &string) const;
    int compareTo(const HnString &string) const;

    HnBool startsWith(const char *prefix, int n) const;
    HnBool startsWith(const char *prefix) const;
    HnBool startsWith(const HnString &string) const;
    HnBool endsWith(const char *suffix, int n) const;
    HnBool endsWith(const char *suffix) const;
    HnBool endsWith(const HnString &string) const;

    int indexOf(int ch, int fromIndex) const;
    int indexOf(int ch) const;
    int lastIndexOf(int ch, int fromIndex) const;
    int lastIndexOf(int ch) const;

    HnString substring(int beginIndex, int endIndex) const;
    HnString substring(int beginIndex) const;
    HnString trim(void) const;

    static HnString getString(FILE *fp);
    static HnStringVector sort(const HnStringVector &strings);

    /*
     * valueOf
     */

    static HnString valueOf(double value);
    static HnString valueOf(double value, int ndigit, int trailing);

    static int parseInt(const HnString &string);
    static double parseDouble(const HnString &string);

    /*
     * pack and unpack
     */

    static void escape(const char *ptr, HnString *string_return);
    static void unescape(const char *ptr, HnString *string_return);
    static void pack(const HnStringVector &strings,
		     HnString *string_return);
    static void unpack(const char *ptr, HnStringVector *strings_return);

    /*
     * variants of pack() and unpack()
     */

    static void pack(const char *array[], int length,
		     HnString *string_return);

    static void pack(const char *ptr1, HnString *string_return);
    static void unpack(const char *ptr, HnString *string1_return);

    static void pack(const char *ptr1, const char *ptr2,
		     HnString *string_return);
    static void unpack(const char *ptr,
		       HnString *string1_return, HnString *string2_return);

    static void pack(const char *ptr1, const char *ptr2, const char *ptr3,
		     HnString *string_return);
    static void unpack(const char *ptr,
		       HnString *string1_return, HnString *string2_return,
		       HnString *string3_return);

    static void pack(const char *ptr1, const char *ptr2, const char *ptr3,
		     const char *ptr4, HnString *string_return);
    static void unpack(const char *ptr,
		       HnString *string1_return, HnString *string2_return,
		       HnString *string3_return, HnString *string4_return);
};

    _HNSRTIMP HnString
    new_HnString(void);
    _HNSRTIMP HnString
    new_HnString(const char *ptr, int n);
    _HNSRTIMP HnString
    new_HnString(const HnString &string);

#define HnClass HnString
#include "HnSRTree/HnClassArray.hh"

#include "HnSRTree/HnStringObj.hh"

inline const char *
HnString::chars(void) const
{
    return getObject()->chars();
}

inline const char &
HnString::get(int i) const
{
    return getObject()->get(i);
}

inline const char &
HnString::operator[](int i) const
{
    return getObject()->operator[](i);
}

inline int
HnString::length(void) const
{
    return getObject()->length();
}

inline HnString
HnString::toString(void) const {
    if ( isInvalid() ) {
	return "HnString::null";
    }
    else {
	return getObject()->toString();
    }
}

inline HnString
HnString::concat(const char *ptr, int n) const
{
    return getObject()->concat(ptr, n);
}

inline HnString
HnString::concat(const char *ptr) const
{
    return getObject()->concat(ptr);
}

inline HnString
HnString::concat(const HnString &string) const
{
    return getObject()->concat(string);
}

inline HnBool
HnString::equals(const HnString &ptr) const {
    if ( isInvalid() ) {
	if ( ptr.isInvalid() ) {
	    return HnTRUE;
	}
	else {
	    return HnFALSE;
	}
    }
    else {
	if ( ptr.isInvalid() ) {
	    return HnFALSE;
	}
	else {
	    return getObject()->equals(ptr);
	}
    }
}

inline int
HnString::compareTo(const HnString &string) const
{
    return getObject()->compareTo(string);
}

inline HnBool
HnString::startsWith(const char *prefix, int n) const
{
    return getObject()->startsWith(prefix, n);
}

inline HnBool
HnString::startsWith(const char *prefix) const
{
    return getObject()->startsWith(prefix);
}

inline HnBool
HnString::startsWith(const HnString &string) const
{
    return getObject()->startsWith(string);
}

inline HnBool
HnString::endsWith(const char *suffix, int n) const
{
    return getObject()->endsWith(suffix, n);
}

inline HnBool
HnString::endsWith(const char *suffix) const
{
    return getObject()->endsWith(suffix);
}

inline HnBool
HnString::endsWith(const HnString &string) const
{
    return getObject()->endsWith(string);
}

inline int
HnString::indexOf(int ch, int fromIndex) const
{
    return getObject()->indexOf(ch, fromIndex);
}

inline int
HnString::indexOf(int ch) const
{
    return getObject()->indexOf(ch);
}

inline int
HnString::lastIndexOf(int ch, int fromIndex) const
{
    return getObject()->lastIndexOf(ch, fromIndex);
}

inline int
HnString::lastIndexOf(int ch) const
{
    return getObject()->lastIndexOf(ch);
}

inline HnString
HnString::substring(int beginIndex, int endIndex) const
{
    return getObject()->substring(beginIndex, endIndex);
}

inline HnString
HnString::substring(int beginIndex) const
{
    return getObject()->substring(beginIndex);
}

inline HnString
HnString::trim(void) const
{
    return getObject()->trim();
}

inline HnString
HnString::getString(FILE *fp)
{
    return HnStringObj::getString(fp);
}

inline HnStringVector
HnString::sort(const HnStringVector &strings)
{
    return HnStringObj::sort(strings);
}

inline HnString
HnString::valueOf(double value)
{
    return HnStringObj::valueOf(value);
}

inline HnString
HnString::valueOf(double value, int ndigit, int trailing)
{
    return HnStringObj::valueOf(value, ndigit, trailing);
}

inline int
HnString::parseInt(const HnString &string)
{
    return HnStringObj::parseInt(string);
}

inline double
HnString::parseDouble(const HnString &string)
{
    return HnStringObj::parseDouble(string);
}

inline void
HnString::escape(const char *ptr, HnString *string_return)
{
    HnStringObj::escape(ptr, string_return);
}

inline void
HnString::unescape(const char *ptr, HnString *string_return)
{
    HnStringObj::unescape(ptr, string_return);
}

inline void
HnString::pack(const HnStringVector &strings, HnString *string_return)
{
    HnStringObj::pack(strings, string_return);
}

inline void
HnString::unpack(const char *ptr, HnStringVector *strings_return)
{
    HnStringObj::unpack(ptr, strings_return);
}

inline void
HnString::pack(const char *array[], int length, HnString *string_return)
{
    HnStringObj::pack(array, length, string_return);
}

inline void
HnString::pack(const char *ptr1, HnString *string_return)
{
    HnStringObj::pack(ptr1, string_return);
}

inline void
HnString::unpack(const char *ptr, HnString *string1_return)
{
    HnStringObj::unpack(ptr, string1_return);
}

inline void
HnString::pack(const char *ptr1, const char *ptr2, HnString *string_return)
{
    HnStringObj::pack(ptr1, ptr2, string_return);
}

inline void
HnString::unpack(const char *ptr, HnString *string1_return, HnString *string2_return)
{
    HnStringObj::unpack(ptr, string1_return, string2_return);
}

inline void
HnString::pack(const char *ptr1, const char *ptr2, const char *ptr3, HnString *string_return)
{
    HnStringObj::pack(ptr1, ptr2, ptr3, string_return);
}

inline void
HnString::unpack(const char *ptr, HnString *string1_return, HnString *string2_return, HnString *string3_return)
{
    HnStringObj::unpack(ptr, string1_return, string2_return, string3_return);
}

inline void
HnString::pack(const char *ptr1, const char *ptr2, const char *ptr3, const char *ptr4, HnString *string_return)
{
    HnStringObj::pack(ptr1, ptr2, ptr3, ptr4, string_return);
}

inline void
HnString::unpack(const char *ptr, HnString *string1_return, HnString *string2_return, HnString *string3_return, HnString *string4_return)
{
    HnStringObj::unpack(ptr, string1_return, string2_return, string3_return, string4_return);
}

inline
HnString::operator char *(void) const {
    if ( isInvalid() ) {
	return NULL;
    }
    else {
	return (char *)chars();
    }
}

inline HnString
HnString::operator + (const char *ptr) const {
    return concat(ptr);
}

inline HnString
HnString::operator + (int value) const
{
    return concat(valueOf(value));
}

inline HnString
HnString::operator + (double value) const
{
    return concat(valueOf(value));
}

inline HnBool
HnString::equals(const char *ptr, int n) const
{
    if ( getObject() == NULL ) {
	if ( ptr == NULL ) {
	    return HnTRUE;
	}
	else {
	    return HnFALSE;
	}
    }
    else {
	if ( ptr == NULL ) {
	    return HnFALSE;
	}
	else {
	    return (length() == n && strncmp(chars(), ptr, n) == 0);
	}
    }
}

inline HnBool
HnString::equals(const char *ptr) const
{
    return equals(ptr, ((ptr == NULL) ? 0 : strlen(ptr)));
}


#endif /* _HnString_hh */
