/*	XString.h
 *
 *		This is my implementation of a string class. I did this
 *	'cause I needed a string class, and the compilers I have access
 *	to don't include the standard C++ string classes.
 */

/**********************************************************************

  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#ifndef PandaWave_XSTRING
#define PandaWave_XSTRING

#include <XConfig.h>
#include <string.h>

/************************************************************************/
/*																		*/
/*	Standard Classes													*/
/*																		*/
/************************************************************************/

/*$	XGString
 *
 *		This manages a variable-length C string. This class is depreciated,
 *	and will probably be replaced with something slightly more sensable.
 *	(At one point I needed this class, but I don't think I need it anymore.)
 */

class XGString {
	public:
								XGString();					// create me
								XGString(const XGString &);	// copy create me
								XGString(const char *);		// copy create me
		virtual					~XGString();				// delete me
		
		/*$	XGString::operator =
		 *
		 *		This copies the XGString object from one to another.
		 */
		
		XGString				&operator = (const XGString  &x)
									{
										return operator = (x.Get());
									}
		XGString				&operator = (const char *);	// copy C string
		
		bool					operator == (const XGString &x) const
									{ return strcmp( this->Get(), x.Get() ) == 0; }
		bool					operator != (const XGString &x) const
									{ return strcmp( this->Get(), x.Get() ) != 0; }
		bool					operator < (const XGString &x) const
									{ return strcmp( this->Get(), x.Get() ) < 0; }
		bool					operator <= (const XGString &x) const
									{ return strcmp( this->Get(), x.Get() ) <= 0; }
		bool					operator > (const XGString &x) const
									{ return strcmp( this->Get(), x.Get() ) > 0; }
		bool					operator >= (const XGString &x) const
									{ return strcmp( this->Get(), x.Get() ) >= 0; }
		
		/*
		 *	String get/fetch
		 */
		
		/*$	XGString::Get
		 *
		 *		Gets the contents of this string as a C string. This
		 *	returns a pointer to the string data itself, or to an empty
		 *	string if no string array has been allocated.
		 */
		
		const char				*Get(void) const
									{
										return fData ? fData : "";
									}
									
		int GetLength(void) const;
		
	private:
		short					fAlloc;
		short					fLength;
		char					*fData;
};


#endif
