/*
 * Copyright (c) 2005-2006, Tom N Harris.
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     A copy of the GNU General Public License can be found at
 *     http://www.gnu.org/
 *
 * Written by Tom N Harris <telliamed@whoopdedo.org>
 *
 */

#ifndef SETUP_STRING_H
#define SETUP_STRING_H

#include <string>

#ifdef UNICODE
	#define STRING_BASE std::wstring
	#define STRING_CONV std::string
#else
	#define STRING_BASE std::string
	#define STRING_CONV std::wstring
#endif

namespace Setup
{

class String : public STRING_BASE
{
	typedef STRING_BASE base_string;
public:
	~String() { ::operator delete(_M_conv); }
	String() : STRING_BASE(), _M_conv(NULL) { }
	String(String const& __s) : STRING_BASE(__s), _M_conv(NULL) { }
	String(STRING_BASE const& __s) : STRING_BASE(__s), _M_conv(NULL) { }
	String(STRING_BASE const& __s, STRING_BASE::size_type __p, 
		   STRING_BASE::size_type __n = STRING_BASE::npos)
		: STRING_BASE(__s,__p,__n), _M_conv(NULL) { }
	String(STRING_BASE::value_type const* __s) : STRING_BASE(__s), _M_conv(NULL) { }
	String(STRING_BASE::value_type const* __s, STRING_BASE::size_type __n)
		: STRING_BASE(__s,__n), _M_conv(NULL) { }
	String(STRING_BASE::size_type __n, STRING_BASE::value_type __c)
		: STRING_BASE(__n,__c), _M_conv(NULL) { }

	String(STRING_CONV const& __s);
	String(STRING_CONV const& __s, STRING_CONV::size_type __p, 
		   STRING_CONV::size_type __n = STRING_CONV::npos);
	String(STRING_CONV::value_type const* __s);
	String(STRING_CONV::value_type const* __s, STRING_CONV::size_type __n);
	String(STRING_BASE::size_type __n, STRING_CONV::value_type __c);

	String& operator=(STRING_CONV const& __s);
	String& operator=(STRING_CONV::value_type const* __s);
	String& operator=(STRING_CONV::value_type __c);

#ifdef UNICODE
	wchar_t const* to_ucs2() { return c_str(); }
	char const* to_utf8();

	operator std::string () { return std::string(to_utf8()); }
#else
	wchar_t const* to_ucs2();
	char const* to_utf8() { return c_str(); }

	operator std::wstring () { return std::wstring(to_ucs2()); }
#endif

	static String Format(LPCTSTR f, ...);
	static String Format(unsigned int i, ...);
	static String Load(unsigned int i);

private:
	STRING_CONV::value_type* _M_conv;
};

};

#endif /* SETUP_STRING_H */
