/*------------------------------------------------------------------------------
 src/lib/dj/djAppBase.h
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

#ifndef DJ_APP_BASE_H
#define DJ_APP_BASE_H
#include <djBase.h>

namespace dj {

// Application base.
//
class AppBase {
public:

  AppBase(const Str & name, int & argc, char ** argv);
  virtual ~AppBase() = 0;

  // Information.
  //
  const Str & name() const { return _name; }
  const StrList & searchPathList() const { return _searchPathList; }
  virtual int terminalWidth() const { return _terminalWidth; }
  virtual void about();
  const Str aboutStr() const;
  
  // Execution.
  //
  static AppBase * instance() { return _instance; }
  virtual int exec() { return exitValue(); }
  virtual void exitValue(int);
  int exitValue() const { return _exitValue; }
  
  // Messages.
  //
  virtual void error(const Str &) const;
  virtual void print(const Str &) const;
  virtual void printFormatted(const Str &) const;
  virtual void printSeparator() const;
  
private:

  void searchPathList(const Str & appName);
  void updateTerminalWidth();

  Str _name;
  StrList _searchPathList;
  int _terminalWidth;
  static AppBase * _instance;
  int _exitValue;
  bool _printSeparator;
};

// Global application pointer.
//
#define djAppBase (dj::AppBase::instance())

}

#endif
