/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/include/sgx/filesystem/file.hpp

*/

#ifndef SGX_FILESYSTEM_FILE_HPP
#define SGX_FILESYSTEM_FILE_HPP	1

class CHardwarePlatform;

class CSGXFile
{
public:
	CSGXFile(CSGXFileEntry *pFileEntry, const sgxString &access="r");
    CSGXFile(const sgxString &filename, const sgxString &access="r");
    ~CSGXFile();

    tBOOL               isEOF();
	tBOOL   			exists();
    tBOOL               open();
    tBOOL               create(const tBOOL bCreateDirectories=FALSE);
    void                close();
    tMEM_SIZE           read(tBYTE *pDest, tMEM_SIZE size);
	tBOOL 				readLine(sgxString &str);
    tMEM_SIZE           write(const tBYTE *pDest, tMEM_SIZE size);
    tBOOL               seek(tINT32 offset, CSGXDeviceBlockState::tSeekFrom from);
    tDISC_SIZE          getSeekPos() { return getSeekPosition(); }
    tDISC_SIZE          getSeekPosition();

	tDISC_SIZE 			getFileSize() const;
	tBOOL				getFileModifiedDate(UTCDate &date) const;

    void                setTargetPlatform(CHardwarePlatform *pPlatform);
    CHardwarePlatform * getTargetPlatform(void) { return m_pPlatform; }
    tBOOL               isSaving()  { return m_bValid ? m_bSaving : FALSE; }
    tBOOL               isLoading() { return m_bValid ? !m_bSaving : FALSE; }
    tBOOL               isValid()   { return m_bValid; }

    tBOOL               swapEndian()   { return m_bSwapEndian; }

    void                writeString(const sgxString &str);
	void				writeAsciiString(const sgxString &str);
	void				writeAsciiStringCR(const sgxString &str);
	
    void                writeConstant(tMEM_SIZE val);
    void                readString(sgxString &str);
    tMEM_SIZE           readConstant();

	tBOOL				slerp(sgxVector<sgxString> &list);
	tBOOL				slerp(sgxString &str);

protected:
    CSGXFile() {}

private:
    CSGXFileEntry        *m_pFileEntry;
    CSGXDeviceBlockState *m_pDevState;
	tBOOL                 m_bValid;
    tBOOL                 m_bSwapEndian;
    tBOOL                 m_bSaving;
    CHardwarePlatform    *m_pPlatform;

	sgxString				m_Filename;		// used only when creating a new file

	friend class CSGXFileSystem;
};

#endif /* SGX_FILESYSTEM_FILE_HPP */
