view anagram/agcore/configparam.h @ 21:1c9dac05d040

Add lint-style FALLTHROUGH annotations to fallthrough cases. (in the parse engine and thus the output code) Document this, because the old output causes warnings with gcc10.
author David A. Holland
date Mon, 13 Jun 2022 00:04:38 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * configparam.h - configuration parameter mechanism
 */

#ifndef CONFIGPARAM_H
#define CONFIGPARAM_H

class ConfigParam {
public:

  class ErrorHandler {
  public:
    ErrorHandler() {}
    virtual ~ErrorHandler() {}
    virtual void badParam(const char *) = 0;
  };

  const char *name;

  ConfigParam(const char *n);
  virtual ~ConfigParam() {}

  virtual void setIntegerValue(const int, ErrorHandler &);
  virtual void setStringValue(const AgString, ErrorHandler &);
  virtual void init() {}
  virtual void reset() = 0;
  virtual AgString asString() = 0;

  static ConfigParam *table[];
  static int paramCount;

  static void initAll();
  static void resetAll();
  static void set(int, ErrorHandler &);
  static void set(ErrorHandler &);
};

template <class T>
class Param : public ConfigParam {
protected:
  T &parameter;
  T defaultValue;
public:
  Param(const char *, T &);
  virtual void init();
  void reset();
};

template <class T>
void Param<T>::init() {
  defaultValue = parameter;
}

template <class T>
Param<T>::Param(const char *n, T &p)
  : ConfigParam(n), parameter(p), defaultValue(p)
{}

template <class T>
void Param<T>::reset() {
  parameter = defaultValue;
}

class IntegerParam : public Param<int> {
public:
  IntegerParam(const char *n, int &p) : Param<int>(n, p) {}
  virtual void setIntegerValue(const int, ErrorHandler &);
  virtual AgString asString();
};

class StringParam : public Param<AgString> {
public:
  StringParam(const char *n, AgString &p) : Param<AgString>(n, p) {}
  virtual void setStringValue(const AgString, ErrorHandler &);
  virtual AgString asString();
};

class ConfigSwitch : public Param<int> {
public:
  ConfigSwitch(const char *n, int &p) : Param<int>(n, p) {}
  virtual void setIntegerValue(const int, ErrorHandler &);
  virtual void setStringValue(const AgString, ErrorHandler &);
  virtual AgString asString();
};

class TextParam : public Param<AgString> {
public:
  TextParam(const char *n, AgString &p) : Param<AgString>(n, p) {}
  virtual void setStringValue(const AgString, ErrorHandler &);
  virtual AgString asString();
};

class CastParam : public Param<int> {
public:
  CastParam(const char *, int &);
  virtual void setStringValue(const AgString, ErrorHandler &e);
  virtual AgString asString();
};

class TokenParam : public Param<int> {
public:
  TokenParam(const char *, int &);
  virtual void setStringValue(const AgString, ErrorHandler &e);
  virtual AgString asString();
};

#endif /* CONFIGPARAM_H */