//DRS_Setting.h
#ifndef DRS_SETTING_H
#define DRS_SETTING_H

#include <memory>
#include <Windows.h>

//#include <string>

//#include <stdlib>
#include "drs_type.h"
#include "base/at_error.h"


class DRS_Setting
{
  public:
  DRS_Setting()
    { sContents[0] = 0;};
  DRS_Setting( char const *sNew);
  DRS_Setting( DRS_Setting const &c)
    {
    strcpy_s( (char *)sContents, sizeof(sContents), (const char *)*c);
    };

  uint Read( DRS_Setting const &thisfile, DRS_Setting const &thissection, uint def = MAX_UINT)
    {
    return GetPrivateProfileIntA( (const char *)*thissection, (char *)sContents, def, (const char *)*thisfile);
    };
  DRS_Setting Read( DRS_Setting const &thisfile, DRS_Setting const &thissection, byte * def = (byte *)"")
    {
    byte s[64];
    GetPrivateProfileStringA( (const char *)*thissection, (const char *)**this, (const char *)def, (char *)s, 64, (const char *)*thisfile);
    return DRS_Setting((char *)s);
    };

  DRS_Setting const & operator =( char *s)
    {
    sContents[0] = 0;
    AssertAddition( (byte const *)s);
    strcpy_s( (char *)sContents, sizeof(sContents), s);
    return *this;
    };
  DRS_Setting const & operator =( byte *s)
    {
    sContents[0] = 0;
    AssertAddition(s);
    strcpy_s( (char *)sContents, sizeof(sContents), (const char *)s);
    return *this;
    };

  DRS_Setting operator +( char const *s)
    {
    DRS_Setting n( *this);
    n += s;
    return n;
    };
  void operator+=( char const *s)
    { *this += (byte const *) s;};
  void operator+=( byte const *s);
  void operator+=( uint i);
  inline const byte * operator*() const
    { return &sContents[0];};

  static DRS_Setting DRS_Setting::null;
  private:
  inline void AssertAddition( byte const *s) const
    {
    if(std::strlen((const char *)sContents) + std::strlen((const char *)s) > 63) 
  		throw AT_Bounds_Err( *this, "Addition", -1);
    };
  byte sContents[128];
};

#endif