#ifndef KSGTFile_H
#define KSGTFile_H

#include "Array.h"

namespace Framework
{
    class Text;

    //! Manages a file where data is stored in tabular form
    class KSGTFile : public virtual ReferenceCounter
    {
    private:
        Text* pfad;
        RCArray<RCArray<Text>>* data;

    public:
        //! Constructor
        DLLEXPORT KSGTFile();
        //! Constructor
        //! \param pfad The path to the file
        DLLEXPORT KSGTFile(const char* pfad);
        //! Constructor
        //! \param pfad The path to the file
        DLLEXPORT KSGTFile(Text* pfad);
        //! Destructor
        DLLEXPORT ~KSGTFile();
        //! Sets the path to the file
        //! \param pfad The path to the file
        DLLEXPORT void setPfad(const char* pfad);
        //! Sets the path to the file
        //! \param pfad The path to the file
        DLLEXPORT void setPfad(Text* pfad);
        //! Loads all data from the specified file
        //! \return 1 if loading was successful. 0 if an error occurred
        //! during loading
        DLLEXPORT bool load();
        //! Adds a row to the table
        //! \param fieldCount The number of fields in the row
        //! \param zValue A pointer to the values in the row without increased
        //! reference counter \return 1 if no error occurred
        DLLEXPORT bool addRow(int fieldCount, RCArray<Text>* zValue);
        //! Replaces an existing row
        //! \param zeile The index of the row to replace
        //! \param fieldCount The number of fields in the row
        //! \param zValue A pointer to the values in the row without increased
        //! reference counter \return 1 if the row existed and was replaced.
        //! 0 if the specified row did not exist
        DLLEXPORT bool setRow(
            int zeile, int fieldCount, RCArray<Text>* zValue);
        //! Deletes a row
        //! \param zeile The index of the row to delete
        //! \return 1 if the row was deleted. 0 if the row was not found
        DLLEXPORT bool removeRow(int zeile);
        //! Adds a value to a specific row
        //! \param zeile The index of the row to add a value to
        //! \param pos The position in the row where the value should be added
        //! \param wert The value to store
        //! \return 1 if the value was successfully added. 0 if the row
        //! does not exist or pos is too large
        DLLEXPORT bool addField(int zeile, int pos, Text* wert);
        //! Adds a value to a specific row
        //! \param zeile The index of the row to add a value to
        //! \param pos The position in the row where the value should be added
        //! \param wert The value to store
        //! \return 1 if the value was successfully added. 0 if the row
        //! does not exist or pos is too large
        DLLEXPORT bool addField(int zeile, int pos, const char* wert);
        //! Adds a value at the end of a specific row
        //! \param zeile The index of the row to add a value to
        //! \param wert The value to store \return 1 if the value was
        //! successfully added. 0 if the row does not exist
        DLLEXPORT bool addField(int zeile, Text* wert);
        //! Adds a value at the end of a specific row
        //! \param zeile The index of the row to add a value to
        //! \param wert The value to store \return 1 if the value was
        //! successfully added. 0 if the row does not exist
        DLLEXPORT bool addField(int zeile, const char* wert);
        //! Sets a specific value in a row
        //! \param zeile The index of the row where a value should be changed
        //! \param feld The position in the row where the value should be set
        //! \param wert The value to store
        //! \return 1 if the value was successfully replaced. 0 if the row
        //! or the value does not exist
        DLLEXPORT bool setField(int zeile, int feld, Text* wert);
        //! Sets a specific value in a row
        //! \param zeile The index of the row where a value should be changed
        //! \param feld The position in the row where the value should be set
        //! \param wert The value to store
        //! \return 1 if the value was successfully replaced. 0 if the row
        //! or the value does not exist
        DLLEXPORT bool setField(int zeile, int feld, const char* wert);
        //! Removes a specific value
        //! \param zeile The index of the row from which a value should be deleted
        //! \param feld The position in the row where the value should be deleted
        //! \return 1 if the value was successfully deleted. 0 if the row
        //! or the value does not exist
        DLLEXPORT bool removeField(int zeile, int feld);
        //! Saves the table to the file
        //! \return 1 if the table was successfully saved
        DLLEXPORT bool save();
        //! Returns the number of rows
        DLLEXPORT int getRowCount() const;
        //! Returns the number of values (columns) in a row
        //! \param zeile The index of the row whose value count should be determined
        DLLEXPORT int getFieldCount(int zeile) const;
        //! Returns a specific stored value
        //! \param zeile The index of the row where the value is stored
        //! \param feld The index of the value in the row
        //! \return The stored value with increased reference counter
        DLLEXPORT Text* getField(int zeile, int feld) const;
        //! Returns a specific stored value
        //! \param zeile The index of the row where the value is stored
        //! \param feld The index of the value in the row
        //! \return The stored value without increased reference counter
        DLLEXPORT Text* zField(int zeile, int feld) const;
    };
} // namespace Framework

#endif