#ifndef _xbSTREAMITF_
#define _xbSTREAMITF_
/*<<<***************************************************************************
The MIT License (MIT)

Copyright(C) 2013 - 2015 Marc Mirti Mancinelli, Christophe Lardau and Philippe Pamart (xdcube.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.
////////////////////////////////////////////////////////////////////////////////
#Title: xbStreamItf
#Project: xdcBase
////////////////////////////////////////////////////////////////////////////////
#Author: Marc MIRTI MANCINELLI
#History:
<15/09/2013: creation.
12/02/2014: this notice inserted.
***************************************************************************>>>*/

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef _xbPTR_
#	include "xbPtr.h"
#endif

#ifndef _xbEXCEPTION_
#	include "xbException.h"
#endif

#ifndef _xbLOCK_
#	include "xbLock.h"
#endif

#ifndef _xbDATETIME_
#	include "xbDateTime.h"
#endif

#define xbSTREAM_LINEBUFSIZE	64
#define xbSTREAM_BUFSIZE		16384

class xbBSTR;

enum xbSeekMode 
{
	xbSeekSet = 0,
	xbSeekCur = 1,
	xbSeekEnd = 2
};

enum xbAccessMode 
{
	xbAccessR = 0,
	xbAccessW = 1,
	xbAccessRW = 2
};

enum xbOpenMode 
{
	xbOpen = 0,
	xbOpenCreate = 1,
	xbOpenAlways = 2,
	xbOpenCreateAlways = 3
};

enum xbWorkMode 
{
	xbWorkShared = 0,	//meme chose que xbWorkSharedRW
	xbWorkSharedRW = 0, //D'autres process pourront lire/écrire en même temps la même ressource
	xbWorkSharedR = 1,	//D'autres process pourront lire(uniquement) en même temps la même ressource
	xbWorkSharedW = 2,	//D'autres process pourront écrire(uniquement) en même temps la même ressource
	xbWorkExclusive = 3 //Aucun autre process ne pourra accéder à cette ressource
};

enum xbFormatMode
{
	xbFormatUndef,		//operator >> << en binary, WriteString et ReadString in text mode
	xbFormatBin,		//Format binaire, operator >> <<, WriteString et ReadString in binary mode
	xbFormatText		//Human readable, ascii or unicode, operator >> <<, WriteString et ReadString in text mode
};

//http://en.wikipedia.org/wiki/Byte_order_mark
enum xbTextBOMtype
{
	xbBOM_none = 0,		//no BOM
	xbBOM_utf8 = 1,		//utf 8 : EF BB BF
	xbBOM_utf16le = 2,	//utf 16 little endian: FF FE 
	xbBOM_utf16be = 3,	//utf 16 big endian: FE FF
	xbBOM_utf16leNoBOM = 4,
	xbBOM_utf16beNoBOM = 5,
#ifdef xbLITTLEENDIAN
	xbBOM_utf16 = xbBOM_utf16le,
	xbBOM_utf16noBOM = xbBOM_utf16leNoBOM,
#else
	xbBOM_utf16 = xbBOM_utf16be,
	xbBOM_utf16noBOM = xbBOM_utf16beNoBOM,
#endif
	xbTextBOM_default = xbBOM_utf8
};

#define xbTextBOM_maxLength	3
#define xbTextBOM_minLength 2
extern byte xbEXPORT s_textBOMbytes_utf8[3];
extern byte xbEXPORT s_textBOMbytes_utf16le[2];
extern byte xbEXPORT s_textBOMbytes_utf16be[2];

inline bool xbTextBOMisUtf16(xbTextBOMtype type)
{
	return type >= xbBOM_utf16le;
}

inline bool xbTextBOMutf16ToRevert(xbTextBOMtype type)
{
#ifdef xbLITTLEENDIAN
	return type == xbBOM_utf16be || type == xbBOM_utf16beNoBOM;
#else
	return type == xbBOM_utf16le || type == xbBOM_utf16leNoBOM;
#endif
}

//Read interface :
#define	IxbInputStreamHelpDcl(Type,Name) \
	virtual Type Read ## Name() \
	{ \
		Type _t; \
		Read((void*)&_t,sizeof(_t)); \
		return _t;\
	}
#define	IxbInputStreamHelpDclEx(RdFunc,Type,Name) \
	virtual Type Read ## Name() \
	{ \
		Type _t; \
		RdFunc((void*)&_t,sizeof(_t)); \
		return _t;\
	}

interface __declspec(uuid("{288BF3D5-F1C2-4cdd-BCEB-4B9C38E3EA52}")) 
	xbEXPORT IxbInputStream:public IxbObject
{
	virtual bool			CanRead() const = 0;
	virtual ulong			Read(void *pData,ulong DataLg,bool DataLg_Required = true) = 0;

	IxbInputStreamHelpDcl(uchar,Uchar);
	IxbInputStreamHelpDcl(char,Char);
	IxbInputStreamHelpDcl(wchar,CharW);
	IxbInputStreamHelpDcl(short,Short);
	IxbInputStreamHelpDcl(ushort,Ushort);
	IxbInputStreamHelpDcl(long,Long);
	IxbInputStreamHelpDcl(ulong,Ulong);
	IxbInputStreamHelpDcl(int64,Int64);
	IxbInputStreamHelpDcl(uint64,Uint64);
	IxbInputStreamHelpDcl(GUID,Guid);
	IxbInputStreamHelpDcl(double,Double);

	virtual IxbInputStream	&operator>>(sIxbStreamable *piObj);
	virtual IxbInputStream	&operator>>(xbStringA *pStr);
	virtual IxbInputStream	&operator>>(xbStringW *pStr);
	virtual IxbInputStream	&operator>>(xbBSTR *pStr);

	virtual ulong			ReadStringA(xbStringA *pStr,xbStringA *pStopStr = NULL,IxbStreamMode *pMode = NULL);
	virtual ulong			ReadStringW(xbStringW *pStr,xbStringW *pStopStr = NULL,IxbStreamMode *pMode = NULL);
	virtual ulong			ReadStringW(xbBSTR *pStr,xbBSTR *pStopStr = NULL,IxbStreamMode *pMode = NULL);
};

//Write interface :
#define	IxbOutputStreamHelpDcl(Type,Name) \
	virtual void Write ## Name(Type _t) \
	{ \
		Write((void*)&_t,sizeof(_t)); \
	}
#define	IxbOutputStreamHelpDclEx(WrFunc,Type,Name) \
	virtual void Write ## Name(Type _t) \
	{ \
		WrFunc((void*)&_t,sizeof(_t)); \
	}

interface __declspec(uuid("{D666E913-454C-4f41-91A8-955AA69BD2BC}")) 
	xbEXPORT IxbOutputStream:public IxbObject
{
	virtual bool			CanWrite() const = 0;
	virtual ulong			Write(const void *pData,ulong DataLg,bool DataLg_Required = true) = 0;
	virtual uint64			WriteStream(sIxbProgress *pCb,IxbInputStream *pstmSrc); 
								//Write entire stream, no seek needed on pstm, thread safe for pstm read (cf xbStream_WriteStream)
	virtual ulong			WriteStream(sIxbProgress *pCb,IxbInputStream *pstmSrc,ulong DataLg,bool DataLg_Required = true); 
								//Write stream pstm starting at its current position, NOT thread safe for pstm read (cf xbStream_WriteStream)

	IxbOutputStreamHelpDcl(uchar,Uchar);
	IxbOutputStreamHelpDcl(char,Char);
	IxbOutputStreamHelpDcl(wchar,CharW);
	IxbOutputStreamHelpDcl(short,Short);
	IxbOutputStreamHelpDcl(ushort,Ushort);
	IxbOutputStreamHelpDcl(long,Long);
	IxbOutputStreamHelpDcl(ulong,Ulong);
	IxbOutputStreamHelpDcl(int64,Int64);
	IxbOutputStreamHelpDcl(uint64,Uint64);
	IxbOutputStreamHelpDcl(GUID,Guid);
	IxbOutputStreamHelpDcl(double,Double);

	virtual IxbOutputStream	&operator<<(const sIxbStreamable &iobj);
	virtual IxbOutputStream	&operator<<(const char *pStr);
	virtual IxbOutputStream	&operator<<(const wchar *pStr);
	virtual IxbOutputStream	&operator<<(const xbStringA &str);
	virtual IxbOutputStream	&operator<<(const xbStringW &str);
	virtual IxbOutputStream	&operator<<(const xbBSTR &str);

	virtual ulong			WriteStringA(const xbStringA &str,bool bAddLf = false,IxbStreamMode *pMode = NULL);
	virtual ulong			WriteStringA(const char *pStr,ulong lgStr,bool bAddLf = false,IxbStreamMode *pMode = NULL);
	virtual ulong			WriteStringW(const xbStringW &str,bool bAddLf = false,IxbStreamMode *pMode = NULL);
	virtual ulong			WriteStringW(const xbBSTR &str,bool bAddLf = false,IxbStreamMode *pMode = NULL);
	virtual ulong			WriteStringW(const wchar *pStr,ulong lgStr,bool bAddLf = false,IxbStreamMode *pMode = NULL);
};

//Fonctions de positionnement :
interface __declspec(uuid("{E14F5FB6-3BA0-450d-B1EB-46FC1B705C75}")) 
	xbEXPORT IxbSeekStream:public IxbObject
{
	virtual bool		Eof() const = 0;
	virtual bool		Bof() const = 0;
	virtual ulong		Seek(long pos,xbSeekMode sk = xbSeekSet) = 0;
	virtual ulong		GetPosition() const = 0;
	virtual ulong		SetPosition(ulong pos) = 0;
	virtual ulong		GetLength() const = 0;
	virtual void		SetLength(ulong sz) = 0;
	virtual void		SetEof() = 0;

	xbPropertyRW(ulong,Length);
	xbPropertyRW(ulong,Position);
};

interface __declspec(uuid("{8BA10090-DA44-463e-A45C-E38937EEEF8B}"))
	xbEXPORT IxbLongSeekStream:public IxbObject
{
	virtual bool		Eof() const = 0;
	virtual bool		Bof() const = 0;
	virtual uint64		LongSeek(int64 pos,xbSeekMode sk = xbSeekSet) = 0;
	virtual uint64		GetLongPosition() const = 0;
	virtual uint64		SetLongPosition(uint64 pos) = 0;
	virtual uint64		GetLongLength() const = 0;
	virtual void		SetLongLength(uint64 sz) = 0;
	virtual void		SetEof() = 0;

	xbPropertyRW(uint64,LongLength);
	xbPropertyRW(uint64,LongPosition);
};

interface __declspec(uuid("{10EB24BF-47A0-4963-A38F-DE4C253905E9}"))
	xbEXPORT IxbStreamMode:public IxbObject
{
	virtual xbFormatMode	GetFormat() const = 0;
	virtual void			SetFormat(xbFormatMode mode) = 0;

	virtual bool			GetCRLFasLF() const = 0;
	virtual void			SetCRLFasLF(bool bFlg) = 0;

	virtual ulong			GetStreamTextCP() const = 0;
	virtual void			SetStreamTextCP(ulong cp) = 0;

	virtual ulong			GetAppTextCP() const = 0;
	virtual void			SetAppTextCP(ulong cp) = 0;

	virtual	ulong			FindLineSepA(ulong startpos,const char *pStr,ulong StrLg,long *pSepLg) const = 0;
	virtual	ulong			FindLineSepW(ulong startpos,const wchar *pStr,ulong StrLg,long *pSepLg) const = 0;

//BOM = byte order mode
	virtual void			ReadTextBOM(xbTextBOMtype *pbBOMtype = NULL) = 0;
	virtual void			WriteTextBOM(xbTextBOMtype BOMtype = xbTextBOM_default) = 0;
	virtual xbTextBOMtype	GetTextBOMtype() const = 0;
	virtual void			SetTextBOMtype(xbTextBOMtype BOMtype) = 0;

	xbPropertyRW(xbFormatMode,Format);
	xbPropertyRW(bool,CRLFasLF);
	xbPropertyRW(ulong,StreamTextCP);
	xbPropertyRW(ulong,AppTextCP);
	xbPropertyRW(xbTextBOMtype,TextBOMtype);
};

interface __declspec(uuid("{AB9DA62A-B78E-4fd7-A7FC-58951847BD2E}")) 
	xbEXPORT IxbStream:public IxbObject
{
	//IxbInputStream
	virtual bool			CanRead() const = 0;
	virtual ulong			Read(void *pData,ulong DataLg,bool DataLg_Required = true) = 0;

	IxbInputStreamHelpDcl(uchar,Uchar);
	IxbInputStreamHelpDcl(char,Char);
	IxbInputStreamHelpDcl(wchar,CharW);
	IxbInputStreamHelpDcl(short,Short);
	IxbInputStreamHelpDcl(ushort,Ushort);
	IxbInputStreamHelpDcl(long,Long);
	IxbInputStreamHelpDcl(ulong,Ulong);
	IxbInputStreamHelpDcl(int64,Int64);
	IxbInputStreamHelpDcl(uint64,Uint64);
	IxbInputStreamHelpDcl(GUID,Guid);
	IxbInputStreamHelpDcl(double,Double);

	virtual IxbInputStream	&operator>>(sIxbStreamable *piObj) = 0;
	virtual IxbInputStream	&operator>>(xbStringA *pStr) = 0;
	virtual IxbInputStream	&operator>>(xbStringW *pStr) = 0;
	virtual IxbInputStream	&operator>>(xbBSTR *pStr) = 0;

	virtual ulong			ReadStringA(xbStringA *pStr,xbStringA *pStopStr = NULL,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			ReadStringW(xbStringW *pStr,xbStringW *pStopStr = NULL,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			ReadStringW(xbBSTR *pStr,xbBSTR *pStopStr = NULL,IxbStreamMode *pMode = NULL) = 0;

	//IxbOutputStream
	virtual bool			CanWrite() const = 0;
	virtual ulong			Write(const void *pData,ulong DataLg,bool DataLg_Required = true) = 0;
	virtual uint64			WriteStream(sIxbProgress *pCb,IxbInputStream *pstmSrc) = 0; 
								//Write entire stream, no seek needed on pstm, thread safe for pstm read(cf xbStream_WriteStream)
	virtual ulong			WriteStream(sIxbProgress *pCb,IxbInputStream *pstmSrc,ulong DataLg,bool DataLg_Required = true) = 0; 
								//Write stream pstm starting at its current position, NOT thread safe for pstm read(cf xbStream_WriteStream)

	IxbOutputStreamHelpDcl(uchar,Uchar);
	IxbOutputStreamHelpDcl(char,Char);
	IxbOutputStreamHelpDcl(wchar,CharW);
	IxbOutputStreamHelpDcl(short,Short);
	IxbOutputStreamHelpDcl(ushort,Ushort);
	IxbOutputStreamHelpDcl(long,Long);
	IxbOutputStreamHelpDcl(ulong,Ulong);
	IxbOutputStreamHelpDcl(int64,Int64);
	IxbOutputStreamHelpDcl(uint64,Uint64);
	IxbOutputStreamHelpDcl(GUID,Guid);
	IxbOutputStreamHelpDcl(double,Double);

	virtual IxbOutputStream	&operator<<(const sIxbStreamable &iobj) = 0;
	virtual IxbOutputStream	&operator<<(const char *pStr) = 0;
	virtual IxbOutputStream	&operator<<(const wchar *pStr) = 0;
	virtual IxbOutputStream	&operator<<(const xbStringA &str) = 0;
	virtual IxbOutputStream	&operator<<(const xbStringW &str) = 0;
	virtual IxbOutputStream	&operator<<(const xbBSTR &str) = 0;

	virtual ulong			WriteStringA(const xbStringA &str,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			WriteStringA(const char *pStr,ulong lgStr,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			WriteStringW(const xbStringW &str,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			WriteStringW(const xbBSTR &str,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			WriteStringW(const wchar *pStr,ulong lgStr,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;

	// IxbSeekStream
	virtual bool		Eof() const = 0;
	virtual bool		Bof() const = 0;
	virtual ulong		Seek(long pos,xbSeekMode sk = xbSeekSet) = 0;
	virtual ulong		GetPosition() const = 0;
	virtual ulong		GetLength() const = 0;
	virtual void		SetLength(ulong sz) = 0;
	virtual void		SetEof() = 0;

	xbPropertyRW(ulong,Length);
	xbPropertyRW(ulong,Position);

	//Others
	virtual bool	Clone(xbAccessMode om,xbRefPtr<IxbStream> *pprStm, xbOpMode opm =xbOp_Required) = 0;
	virtual bool	Clone(xbRefPtr<IxbStream> *pprStm, xbOpMode opm =xbOp_Required) = 0;
};


interface __declspec(uuid("{50CFA1E3-8D38-43cc-B97A-79FA61799F9D}")) 
	xbEXPORT IxbLongStream:public IxbObject
{
	//IxbInputStream
	virtual bool			CanRead() const = 0;
	virtual ulong			Read(void *pData,ulong DataLg,bool DataLg_Required = true) = 0;

	IxbInputStreamHelpDcl(uchar,Uchar);
	IxbInputStreamHelpDcl(char,Char);
	IxbInputStreamHelpDcl(wchar,CharW);
	IxbInputStreamHelpDcl(short,Short);
	IxbInputStreamHelpDcl(ushort,Ushort);
	IxbInputStreamHelpDcl(long,Long);
	IxbInputStreamHelpDcl(ulong,Ulong);
	IxbInputStreamHelpDcl(int64,Int64);
	IxbInputStreamHelpDcl(uint64,Uint64);
	IxbInputStreamHelpDcl(GUID,Guid);
	IxbInputStreamHelpDcl(double,Double);

	virtual IxbInputStream	&operator>>(sIxbStreamable *piObj) = 0;
	virtual IxbInputStream	&operator>>(xbStringA *pStr) = 0;
	virtual IxbInputStream	&operator>>(xbStringW *pStr) = 0;
	virtual IxbInputStream	&operator>>(xbBSTR *pStr) = 0;

	virtual ulong			ReadStringA(xbStringA *pStr,xbStringA *pStopStr = NULL,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			ReadStringW(xbStringW *pStr,xbStringW *pStopStr = NULL,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			ReadStringW(xbBSTR *pStr,xbBSTR *pStopStr = NULL,IxbStreamMode *pMode = NULL) = 0;

	//IxbOutputStream
	virtual bool			CanWrite() const = 0;
	virtual ulong			Write(const void *pData,ulong DataLg,bool DataLg_Required = true) = 0;
	virtual uint64			WriteStream(sIxbProgress *pCb,IxbInputStream *pstmSrc) = 0; 
								//Write entire stream, no seek needed on pstm, thread safe for pstm read(cf xbStream_WriteStream)
	virtual ulong			WriteStream(sIxbProgress *pCb,IxbInputStream *pstmSrc,ulong DataLg,bool DataLg_Required = true) = 0; 
								//Write stream pstm starting at its current position, NOT thread safe for pstm read(cf xbStream_WriteStream)

	IxbOutputStreamHelpDcl(uchar,Uchar);
	IxbOutputStreamHelpDcl(char,Char);
	IxbOutputStreamHelpDcl(wchar,CharW);
	IxbOutputStreamHelpDcl(short,Short);
	IxbOutputStreamHelpDcl(ushort,Ushort);
	IxbOutputStreamHelpDcl(long,Long);
	IxbOutputStreamHelpDcl(ulong,Ulong);
	IxbOutputStreamHelpDcl(int64,Int64);
	IxbOutputStreamHelpDcl(uint64,Uint64);
	IxbOutputStreamHelpDcl(GUID,Guid);
	IxbOutputStreamHelpDcl(double,Double);

	virtual IxbOutputStream	&operator<<(const sIxbStreamable &iobj) = 0;
	virtual IxbOutputStream	&operator<<(const char *pStr) = 0;
	virtual IxbOutputStream	&operator<<(const wchar *pStr) = 0;
	virtual IxbOutputStream	&operator<<(const xbStringA &str) = 0;
	virtual IxbOutputStream	&operator<<(const xbStringW &str) = 0;
	virtual IxbOutputStream	&operator<<(const xbBSTR &str) = 0;

	virtual ulong			WriteStringA(const xbStringA &str,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			WriteStringA(const char *pStr,ulong lgStr,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			WriteStringW(const xbStringW &str,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			WriteStringW(const xbBSTR &str,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;
	virtual ulong			WriteStringW(const wchar *pStr,ulong lgStr,bool bAddLf = false,IxbStreamMode *pMode = NULL) = 0;

	// IxbLongSeekStream
	virtual bool		Eof() const = 0;
	virtual bool		Bof() const = 0;
	virtual uint64		LongSeek(int64 pos,xbSeekMode sk = xbSeekSet) = 0;
	virtual uint64		GetLongPosition() const = 0;
	virtual uint64		SetLongPosition(uint64 pos) = 0;
	virtual uint64		GetLongLength() const = 0;
	virtual void		SetLongLength(uint64 sz) = 0;
	virtual void		SetEof() = 0;

	xbPropertyRW(uint64,LongLength);
	xbPropertyRW(uint64,LongPosition);

	//Others
	virtual bool	Clone(xbAccessMode om,xbRefPtr<IxbStream> *pprStm, xbOpMode opm =xbOp_Required) = 0;
	virtual bool	Clone(xbRefPtr<IxbStream> *pprStm, xbOpMode opm =xbOp_Required) = 0;
};

interface __declspec(uuid("{6DD5FC28-622D-4772-8BBB-F66E99C2EE5D}")) 
	xbEXPORT IxbStreamInfo:public IxbObject
{
	virtual xbString		GetName() const = 0;
	virtual xbString		GetPhysicalName() const = 0;
	virtual bool GetFileTime(FILETIME *pCreationTime, FILETIME *pLastAccessTime, FILETIME *pLastWriteTime, xbOpMode opm =xbOp_Required) = 0;
	virtual bool SetFileTime(const FILETIME *pCreationTime, const FILETIME *pLastAccessTime, const FILETIME *pLastWriteTime, xbOpMode opm =xbOp_Required ) = 0;
	virtual bool GetFileTime(xbDateTime *pCreationTime, xbDateTime *pLastAccessTime, xbDateTime *pLastWriteTime, xbOpMode opm =xbOp_Required) = 0;
	virtual bool SetFileTime(const xbDateTime *pCreationTime, const xbDateTime *pLastAccessTime, const xbDateTime *pLastWriteTime, xbOpMode opm =xbOp_Required ) = 0;
	virtual xbString		GetStreamContentType() const = 0;
};

//Exception xbElib: to use by library for unclassified errors
xbEdclStart(xbEstream,xbEadv,{18CA41CD-AEEE-4adc-A659-0636EA4E6CDB},xbEXPORT)
	virtual xbMBiconType GetMBoxIcon() const {return xbMBicon_Stop;}
	virtual const char *GetMBoxTitle() const {return "Stream system error";} 

	xbEstream(const IxbStreamInfo *pStm,xbHR hr,const xbString &msg,xbEctorMode ctorMode = xbEctor_final);
    xbEstream(const IxbStreamInfo *pStm,const xbString &msg,xbEctorMode ctorMode = xbEctor_final);
	xbEstream(const xbString &strm,xbHR hr,const xbString &msg,xbEctorMode ctorMode = xbEctor_final);
xbEdclEnd(xbEstream);

//Helpers to implement streams
ulong xbEXPORT	xbStream_WriteStream(IxbOutputStream *pstmDst,IxbInputStream *pstmSrc,ulong DataLg,bool DataLg_Required, sIxbProgress *pCb);
ulong xbEXPORT	xbStream_WriteStream(IxbOutputStream *pstmDst,IxbInputStream *pstmSrc,sIxbLock *pLckSrc,IxbSeekStream *pSkSrc,sIxbProgress *pCb);
uint64 xbEXPORT xbStream_WriteLongStream(IxbOutputStream *pstmDst,IxbInputStream *pstmSrc,sIxbLock *pLckSrc,IxbLongSeekStream *pSkSrc,sIxbProgress *pCb);

ulong xbEXPORT	xbStream_FindLineSepA(ulong startpos,const char *pStr,ulong StrLg,long *pSepLg);
ulong xbEXPORT	xbStream_ReadStringA(xbFormatMode fmtDefault,IxbInputStream *pstmSrc,IxbStreamMode *pMode,IxbSeekStream *pSkSrc,sIxbLock *pStmLck,xbStringA *pStr,xbStringA *pStopStr);
ulong xbEXPORT	xbStream_WriteStringA(xbFormatMode fmtDefault,IxbOutputStream *pstmSrc,IxbStreamMode *pMode,sIxbLock *pStmLck,const char *pStr,ulong lgStr,bool bAddLf);

ulong xbEXPORT	xbStream_FindLineSepW(ulong startpos,const wchar *pStr,ulong StrLg,long *pSepLg);
ulong xbEXPORT	xbStream_ReadStringW(xbFormatMode fmtDefault,IxbInputStream *pstmSrc,IxbStreamMode *pMode,IxbSeekStream *pSkSrc,sIxbLock *pStmLck,xbStringW *pStr,xbStringW *pStopStr);
ulong xbEXPORT	xbStream_ReadStringW(xbFormatMode fmtDefault,IxbInputStream *pstmSrc,IxbStreamMode *pMode,IxbSeekStream *pSkSrc,sIxbLock *pStmLck,xbBSTR *pStr,xbBSTR *pStopStr);
ulong xbEXPORT	xbStream_WriteStringW(xbFormatMode fmtDefault,IxbOutputStream *pstmSrc,IxbStreamMode *pMode,sIxbLock *pStmLck,const wchar *pStr,ulong lgStr,bool bAddLf);

ulong xbEXPORT	xbStream_ReadStringTextA(IxbInputStream *pstmSrc,IxbSeekStream *pSkSrc,xbStringA *pStr,xbStringA *pStopStr,IxbStreamMode *pMode);
ulong xbEXPORT	xbStream_ReadStringTextW(IxbInputStream *pstmSrc,IxbSeekStream *pSkSrc,xbStringW *pStr,xbStringW *pStopStr,IxbStreamMode *pMode);
ulong xbEXPORT	xbStream_ReadStringTextW(IxbInputStream *pstmSrc,IxbSeekStream *pSkSrc,xbBSTR *pStr,xbBSTR *pStopStr,IxbStreamMode *pMode);

ulong xbEXPORT	xbStream_WriteStringTextA(IxbOutputStream *pstmSrc,const char *pStr,ulong lgStr,bool bAddLf,IxbStreamMode *pMode);
ulong xbEXPORT	xbStream_WriteStringTextW(IxbOutputStream *pstmSrc,const wchar *pStr,ulong lgStr,bool bAddLf,IxbStreamMode *pMode);

void xbEXPORT	xbTextBOMrevert(wchar *pstr,int cLen);
void xbEXPORT	xbTextBOMread(IxbInputStream *pstmSrc,IxbStreamMode *pMode,IxbSeekStream *pSkSrc,sIxbLock *pStmLck,xbTextBOMtype *pbBOMtype);
void xbEXPORT	xbTextBOMwrite(IxbOutputStream *pstmSrc,IxbStreamMode *pMode,sIxbLock *pStmLck,xbTextBOMtype BOMtype);

#endif
