// CodeGear C++Builder
// Copyright (c) 1995, 2020 by Embarcadero Technologies, Inc.
// All rights reserved

// (DO NOT EDIT: machine generated header) 'QImport3CSVClasses.pas' rev: 34.00 (Windows)

#ifndef Qimport3csvclassesHPP
#define Qimport3csvclassesHPP

#pragma delphiheader begin
#pragma option push
#pragma option -w-      // All warnings off
#pragma option -Vx      // Zero-length empty class member 
#pragma pack(push,8)
#include <System.hpp>
#include <SysInit.hpp>
#include <System.WideStrings.hpp>
#include <Winapi.Windows.hpp>
#include <System.Classes.hpp>
#include <System.Contnrs.hpp>
#include <System.SysUtils.hpp>
#include <QImport3StrTypes.hpp>
#include <QImport3StrIDs.hpp>
#include <QImport3Common.hpp>
#include <QImport3Encoding.hpp>

//-- user supplied -----------------------------------------------------------

namespace Qimport3csvclasses
{
//-- forward type declarations -----------------------------------------------
class DELPHICLASS TCSVColumn;
class DELPHICLASS TCSVReader;
class DELPHICLASS TCSVFileReader;
//-- type declarations -------------------------------------------------------
enum DECLSPEC_DENUM TCSVParserState : unsigned char { psChkBegOfLine, psChkBegOfColumn, psNotQuoted, psQuoted, psChkIntrnQuote, psChkAfterCR };

#pragma pack(push,4)
class PASCALIMPLEMENTATION TCSVColumn : public System::TObject
{
	typedef System::TObject inherited;
	
private:
	System::WideString FValue;
	System::WideString FName;
	
public:
	__fastcall virtual TCSVColumn();
	__property System::WideString Value = {read=FValue, write=FValue};
	__property System::WideString Name = {read=FName, write=FName};
public:
	/* TObject.Destroy */ inline __fastcall virtual ~TCSVColumn() { }
	
};

#pragma pack(pop)

class PASCALIMPLEMENTATION TCSVReader : public System::TObject
{
	typedef System::TObject inherited;
	
	
private:
	typedef System::DynamicArray<System::WideChar> _TCSVReader__1;
	
	typedef System::DynamicArray<System::WideChar> _TCSVReader__2;
	
	
private:
	bool FActive;
	System::Contnrs::TObjectList* FColumns;
	bool FBof;
	bool FEof;
	bool FHeaderPresent;
	bool FReadingHeader;
	bool FFlagExitMainLoop;
	int FIndexOfLastProcessedColumn;
	int FIndexOfLastProcessedLine;
	_TCSVReader__1 FBufferColumnValue;
	int FBufFldValCapacity;
	int FBufFldValContentLength;
	TCSVParserState FParserState;
	System::WideChar FBufferReadFromFile;
	bool FIgnoreSpecialCharacters;
	bool FUseColumnQuoting;
	bool FIgnoreEmptyLines;
	bool FColumnCountAutoDetect;
	bool FColumnCountAutoDetectInProgress;
	System::WideChar FColumnSeparatorChar;
	System::WideChar FQuoteChar;
	bool FASCIIonly;
	System::Classes::TNotifyEvent FOnColumnCountAutoDetectComplete;
	_TCSVReader__2 FBufferReadFromStream;
	int FBufferReadFromStreamCapacity;
	int FBufferReadFromStreamContentLength;
	int FBufferReadFromStreamNextCharIndex;
	void __fastcall DoOpen();
	void __fastcall DoClose();
	void __fastcall OpenCSVSourceAndCreateStream();
	void __fastcall CloseCSVSourceAndDestroyStream();
	void __fastcall ParsingLoopMain();
	void __fastcall ClearColumnDataInaccessibleWhileFileClosed();
	void __fastcall ClearColumnDataInaccessibleWhileEof();
	void __fastcall ResetForClose();
	void __fastcall ResetForEndOfFile();
	void __fastcall ResetForNextLine();
	void __fastcall ResetForNextColumn();
	void __fastcall DoEndOfFile();
	void __fastcall AddToColumnValueBuffer();
	void __fastcall HandleQuoteAtBegOfValue(TCSVParserState &ASwitchToState);
	void __fastcall HandleEndOfLine();
	void __fastcall HandleEmptyLine();
	void __fastcall HandleEndOfFileAtBegOfLine();
	void __fastcall HandleEndOfFileAfterLastColumnInLine();
	void __fastcall SetColumnCountAutoDetectInProgress(const bool Value);
	void __fastcall SetHeaderPresent(const bool Value);
	void __fastcall SetColumnCountAutoDetect(const bool Value);
	int __fastcall GetColumnCount();
	void __fastcall SetColumnCount(const int Value);
	int __fastcall GetColumnSeparatorCharCode();
	void __fastcall SetColumnSeparatorCharCode(const int Value);
	void __fastcall SetUseColumnQuoting(const bool Value);
	int __fastcall GetQuoteCharCode();
	void __fastcall SetQuoteCharCode(const int Value);
	void __fastcall SetIgnoreEmptyLines(const bool Value);
	void __fastcall SetASCIIonly(const bool Value);
	void __fastcall SetIgnoreSpecialCharacters(const bool Value);
	void __fastcall SetActive(const bool Value);
	TCSVColumn* __fastcall GetColumns(int Index);
	int __fastcall GetLineCountProcessedSoFar();
	System::WideString __fastcall GetCurrentLine();
	__property bool ColumnCountAutoDetectInProgress = {read=FColumnCountAutoDetectInProgress, write=SetColumnCountAutoDetectInProgress, nodefault};
	
protected:
	System::Classes::TStream* FCSVTextStream;
	virtual System::Classes::TStream* __fastcall CreateDataSourceStream() = 0 ;
	virtual void __fastcall DoEndOfColumn();
	virtual void __fastcall DoEndOfLine();
	virtual bool __fastcall AllowColumnCountChangeEvenInOpenState();
	virtual void __fastcall OnColumnCountAutoDetectCompleted();
	void __fastcall ThrowErrorWithNoParam(System::WideString AMsg);
	void __fastcall ThrowErrorWithLineAndColumnNum(System::WideString AMsg);
	
public:
	__fastcall virtual TCSVReader(int ABufferReadFromStreamCapacityInChars);
	__fastcall virtual ~TCSVReader();
	void __fastcall Open();
	void __fastcall Close();
	void __fastcall Next();
	__property bool HeaderPresent = {read=FHeaderPresent, write=SetHeaderPresent, nodefault};
	__property bool ColumnCountAutoDetect = {read=FColumnCountAutoDetect, write=SetColumnCountAutoDetect, nodefault};
	__property int ColumnCount = {read=GetColumnCount, write=SetColumnCount, nodefault};
	__property int ColumnSeparatorCharCode = {read=GetColumnSeparatorCharCode, write=SetColumnSeparatorCharCode, nodefault};
	__property bool UseColumnQuoting = {read=FUseColumnQuoting, write=SetUseColumnQuoting, nodefault};
	__property int QuoteCharCode = {read=GetQuoteCharCode, write=SetQuoteCharCode, nodefault};
	__property bool IgnoreEmptyLines = {read=FIgnoreEmptyLines, write=SetIgnoreEmptyLines, nodefault};
	__property bool ASCIIonly = {read=FASCIIonly, write=SetASCIIonly, nodefault};
	__property bool IgnoreSpecialCharacters = {read=FIgnoreSpecialCharacters, write=SetIgnoreSpecialCharacters, nodefault};
	__property bool Active = {read=FActive, write=SetActive, nodefault};
	__property bool Bof = {read=FBof, nodefault};
	__property bool Eof = {read=FEof, nodefault};
	__property TCSVColumn* Columns[int Index] = {read=GetColumns};
	__property int LineCountProcessedSoFar = {read=GetLineCountProcessedSoFar, nodefault};
	__property System::WideString CurrentLine = {read=GetCurrentLine};
	__property System::Classes::TNotifyEvent OnColumnCountAutoDetectComplete = {read=FOnColumnCountAutoDetectComplete, write=FOnColumnCountAutoDetectComplete};
};


class PASCALIMPLEMENTATION TCSVFileReader : public TCSVReader
{
	typedef TCSVReader inherited;
	
private:
	System::UnicodeString FFileName;
	Qimport3encoding::TQICharsetType FCharset;
	Qimport3encoding::TQICharsetType __fastcall GetCharset();
	void __fastcall SetCharset(const Qimport3encoding::TQICharsetType Value);
	
protected:
	virtual System::Classes::TStream* __fastcall CreateDataSourceStream();
	virtual void __fastcall DoEndOfColumn();
	virtual void __fastcall DoEndOfLine();
	
public:
	__fastcall virtual TCSVFileReader(int ABufferReadFromStreamCapacityInChars);
	void __fastcall SetFile(const System::UnicodeString AFileName);
	__property System::UnicodeString FileName = {read=FFileName};
	__property Qimport3encoding::TQICharsetType Charset = {read=GetCharset, write=SetCharset, nodefault};
public:
	/* TCSVReader.Destroy */ inline __fastcall virtual ~TCSVFileReader() { }
	
};


//-- var, const, procedure ---------------------------------------------------
static const System::Word DefBufferSize = System::Word(0x200);
}	/* namespace Qimport3csvclasses */
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_QIMPORT3CSVCLASSES)
using namespace Qimport3csvclasses;
#endif
#pragma pack(pop)
#pragma option pop

#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif	// Qimport3csvclassesHPP
