/// @file octaneclass.hpp
/// Root class for most derived Octane classes
///
/// @remarks
/// It defines some generic methods available to all octane derived
///  parsers, models, coders, etc.
///
/// @author mouser
/// @date   2003.07.29
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// recursive header protection
#ifndef OctaneClassH
#define OctaneClassH
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// application includes
#include "../bitio/bitio.hpp"
// system includes
#include <string>
// ATTN: note the old .h include - we only need this for bcc compilation
#include <stdlib.h>
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
/// Base class from which most octane classes derive (including parser,coder,modeler,etc).
///
/// @ingroup Core
///
class OctaneClass
{
public:
	//---------------------------------------------------------------------------
	/// constructor
	OctaneClass() {;};
	/// destructor
	virtual ~OctaneClass() {;};
	//---------------------------------------------------------------------------
public:
	//---------------------------------------------------------------------------
	// OCTANE PUBLIC API - RTTI AND HELP FUNCTIONS - these are supported by all derived classes
	/// provide a unique name for the coder, used in some cases to automatically register the object with a manager
	/// @return a short *unique* name
	virtual std::string GetName() {return "OctaneClass";}
	/// optionally provide a longer (maybe 20-60 characters) description
	/// @return a one line description
	virtual std::string GetDescription() {return "Base Octane Class";}
	/// optionally provide more information about the object on request for help
	/// @return a long string (can be multiple \n newlines)
	virtual std::string GetHelpInformation() { return ""; }
	//---------------------------------------------------------------------------
public:
	//---------------------------------------------------------------------------
	// OCTANE PUBLIC API - AUXILIARY FUNCTIONS - these are supported by all derived classes
	/// show any debugging info on request (used by various derived classes) [optional]
	virtual void ShowDebuggingInfo() {;};
	/// Report actual current memory usage (in bytes).
	virtual unsigned int GetMemoryUsed() {return sizeof(this);};
	/// Report disk space (in bytes) that would be used when saving state to file (in bytes).
	virtual unsigned int GetDiskspaceUsed(bool fortempdecompressiononly) {return 0;};
	/// Reports information about any parameters available.
	virtual std::string GetParametersInformation() {return "";};
	/// Reset any parameters to their default values.
	virtual void SetDefaultParameters() {;};
	/// This function is called to set a variable value
	/// @note this can be called with a variable not owned by this class, in which case the function should return false.
	/// @return true if the variable was found (whether it was set properly or not).
	virtual bool SetParameter(const std::string &parametername,const std::string &parametervalue) {return false;};
	/// Save state of object to output stream (if appropriate).
	/// @return true on success (or if no information needs to be saved).
	virtual bool SaveState(bitwriter &to,bool fortempdecompressiononly) {return DoProtectedSaveState(to,fortempdecompressiononly);};
	/// Load state of object from input stream (if appropriate).
	/// @return true on success (or if no information needs to be loaded).
	virtual bool LoadState(bitreader &from) {return DoProtectedLoadState(from);};
	//---------------------------------------------------------------------------
public:
	//---------------------------------------------------------------------------
	// OCTANE INTERNAL - STATIC HELPER FUNCTIONS - some general purpose helper functions for derived classes
	/// static helper to convert a raw binary string into a string which is displayable on screen
	static void NiceifyHighAsciiString(std::string &str);
	/// prefix a string (can contain newlines) with a header, IFF the string is non-empty
	static std::string PrefixNonEmptyString(const std::string headerstr, const std::string str);
	//---------------------------------------------------------------------------
protected:
	//---------------------------------------------------------------------------
	// OCTANE INTERNAL - STATIC PARAMETER HANDLING FUNCTIONS - some general purpose helper functions for derived classes
	// parameter setting helpers, for use by derived classes for use in parsing parameter values from SetParameter() method
	/// get value of an unsinged int parameter
	/// @return true on success
	static bool ParseParameter(const std::string &parametervalue,unsigned int &param) {param=(unsigned int)(atoi(parametervalue.c_str()));return true;}
	/// get value of an int parameter
	/// @return true on success
	static bool ParseParameter(const std::string &parametervalue,int &param) {param=(int)(atoi(parametervalue.c_str()));return true;}
	/// get value of an an unsigned char parameter
	/// @return true on success
	static bool ParseParameter(const std::string &parametervalue,unsigned char &param) {param=(unsigned char)(atoi(parametervalue.c_str()));return true;}
	/// get value of a char parameter
	/// @return true on success
	static bool ParseParameter(const std::string &parametervalue,char &param) {param=(char)(atoi(parametervalue.c_str()));return true;}
	/// get value of a bool parameter
	/// @return true on success
	static bool ParseParameter(const std::string &parametervalue,bool &param);
	//---------------------------------------------------------------------------
protected:
	//---------------------------------------------------------------------------
	// OCTANE PROTECTED DERIVED STATE LOADING AND SAVING
	// These are the functions that should be implemented in derived classes
	/// Save the state of the object - this is the virtual function that derived classes should override.
	/// It is wrapped by the non-virtual function SaveState() above which can perform some timing and size measurements.
	virtual bool DoProtectedSaveState(bitwriter &to,bool fortempdecompressiononly) {return true;};
	/// Load the state of the object - this is the virtual function that derived classes should override.
	/// It is wrapped by the non-virtual function LoadState() above which can perform some timing and size measurements.
	virtual bool DoProtectedLoadState(bitreader &from) {return true;};
	//---------------------------------------------------------------------------
};
//---------------------------------------------------------------------------














//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------

