Source: classlib/include/fixstring.h


Annotated List
Files
Globals
Hierarchy
Index
/***************************************************************************
                          fixstring.h  -  description
                             -------------------
    begin                : Mon Sep 9 2002
    copyright            : (C) 2002 by Nicola De Nisco
    email                : nicola@winada.it
 ***************************************************************************/

#ifndef __FixString_H__
#define __FixString_H__

#include 
#include 
#include 
#include 

/**

	class FixedString

	Implementazione semplicissima ma versatilissima di una stringa a lunghezza fissa.

*/

template 
class FixedString
{
public:
	FixedString() {s[0]=0;}
	FixedString(LPCSTR o) { copy(o); }
		
	virtual ~FixedString() {};

	int operator==(LPCSTR val) const {
		return !strcmp(s, val);
	}

	int operator<(LPCSTR val) const {
		return strcmp(s, val) < 0;
	}

	int operator>(LPCSTR val) const {
		return strcmp(s, val) > 0;
	}

	BOOL isEmpty() const {
		return strlen(s) == 0;
	}

	int length() const {
		return strlen(s);
	}

	int size() const {
		return Size;
	}

	LPSTR trim() {
		return ::trim(s);
	}

	LPSTR copy(LPCSTR t) {
		return strncpy(s, t, sizeof(s));
	}

	LPSTR append(LPCSTR t) {
		return strncat(s, t, sizeof(s));
	}

	LPSTR c_str() const {return (LPSTR)s;}
	
	operator char*() {return s;}
	operator const char*() const {return s;}

	LPSTR operator=(LPCSTR val) {
		return copy(val);
	}

	LPSTR operator +=(LPCSTR t) {
		return append(t);
	}

	int printf(LPCSTR fmt, ...)
	{
		va_list ap;
		va_start(ap, fmt);
		int rv = vsnprintf(s, sizeof(s), fmt, ap);
		va_end(ap);
		return rv;
	}
	
protected:
	char s[Size];
};

#define FIX_SIZE_STR 128

class FixString : public FixedString
{
	typedef FixedString Parent;

public:
	FixString() {}
	FixString(LPCSTR s) : Parent(s) {}
};

inline FixString operator +(LPCSTR sz, const FixString& s)
{
	return FixString(sz) += s;
}

#endif // __FixString_H__


Generated by: nicola on gulliver.wadahome.it on Sun May 25 13:54:34 2003, using kdoc 2.0a53.