/*********************************************************************
** Copyright (c) 1992-2025 MAK Technologies, Inc
** All rights reserved.
*********************************************************************/

#ifndef mtlstream_H_
#define mtlstream_H_

//! \file mtlstream.h
//! \ingroup mtl
//! \brief This file declares DtlInputStream, DtlFileInputStream

#include <stdio.h>

#ifdef DtUSE_UTILITIES_NAMESPACE
namespace DtUSE_UTILITIES_NAMESPACE
{
#endif


//! Input stream
//! \ingroup mtl
class DT_DLL_MTL DtlInputStream
{
  public:
    DtlInputStream();
    virtual ~DtlInputStream() {} 

    virtual int peekc(void) = 0;
    virtual int ungetc(int c) = 0;
    virtual int fgetc(void) = 0;
    virtual int fgetc_past_whitespace(void) = 0;
    virtual int flush_until(char terminator) = 0;

    virtual int lineCount() { return lines;};
    virtual void incLineCount() { lines++;};
  protected:
    int lines;
};

//! File Input stream
//! \ingroup mtl
class DT_DLL_MTL DtlFileInputStream : public DtlInputStream
{
  public:

    //! takes a file pointer. The lifetime of this pointer must
    //! be greater than the lifetime of this class. 
    DtlFileInputStream(FILE *);
    virtual ~DtlFileInputStream();

    int peekc(void);
    int ungetc(int c);
    int fgetc(void);
    int fgetc_past_whitespace(void);
    int flush_until(char terminator);

  private:
    FILE *fp;
};

//! String Input stream
//! \ingroup mtl
class DT_DLL_MTL DtlStringInputStream : public DtlInputStream
{
  public:
    DtlStringInputStream(const char*);
    virtual ~DtlStringInputStream();

    int peekc(void);
    int ungetc(int c);
    int fgetc(void);
    int fgetc_past_whitespace(void);
    int flush_until(char terminator);

  private:
    const char* input_string;
    int index;
};

#ifdef DtUSE_UTILITIES_NAMESPACE
} //! end of namespace DtUSE_UTILITIES_NAMESPACE
#endif

#endif

