// This file is part of AspectC++.
// Copyright (C) 1999-2015  The AspectC++ developer team.
//                                                                
// This program is free software;  you can redistribute it and/or 
// modify it under the terms of the GNU General Public License as 
// published by the Free Software Foundation; either version 2 of 
// the License, or (at your option) any later version.            
//                                                                
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
// GNU General Public License for more details.                   
//                                                                
// You should have received a copy of the GNU General Public      
// License along with this program; if not, write to the Free     
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
// MA  02111-1307  USA                                            

#ifndef ACBASE_ConfOption_H
#define ACBASE_ConfOption_H

/** \file
 * Configuration option abstraction. */

#include <vector>
#include <string>

namespace ACBase {

/** \class ConfOption ConfOption.h Puma/ConfOption.h
 * Configuration option abstraction. A configuration option has
 * a name and an optional list of arguments. System priority
 * configuration options have a lower priority than non-system
 * options.
 * \ingroup common */
class ConfOption {
  std::string name_;
  std::vector<std::string> args_;
  bool system_;

public:
  /** Constructor.
   * \param option The full name of the option.
   * \param system Has system priority or not. */
  ConfOption(const std::string &option, bool system = false);
  /** Constructor.
   * \param option The full name of the option.
   * \param arg The argument value of the option.
   * \param system Has system priority or not. */
  ConfOption(const std::string &option, const std::string &arg, bool system = false);
  /** Constructor.
   * \param option The full name of the option.
   * \param arg1 The first argument value of the option.
   * \param arg2 The second argument value of the option.
   * \param system Has system priority or not. */
  ConfOption(const std::string &option, const std::string &arg1, const std::string &arg2, bool system = false);

  /** Check if the option is an system priority option.
   * \return True if a system priority option. */
  bool is_system() const;

  /** Get the name of the option.
   * \return The full name of the option. */
  const std::string &name() const;

  /** Get the number of option arguments.
   * \return The number of arguments. */
  unsigned arguments() const;
  /** Get the n-th option argument.
   * \param n The index of the argument to get.
   * \return The n-th argument. */
  const std::string &argument(unsigned n) const;
  /** Add a further option argument.
   * \param arg The argument value. */
  void add_argument(const std::string &arg);
};

inline ConfOption::ConfOption(const std::string &n, bool system) : system_(system) {
  name_ = n;
}
inline ConfOption::ConfOption(const std::string &n, const std::string &a1, bool system) : system_(system) {
  name_ = n;
  add_argument(a1);
}
inline ConfOption::ConfOption(const std::string &n, const std::string &a1, const std::string &a2, bool system) :
    system_(system) {
  name_ = n;
  add_argument(a1);
  add_argument(a2);
}

inline bool ConfOption::is_system() const {
  return system_;
}
inline const std::string &ConfOption::name() const {
  return name_;
}
inline unsigned ConfOption::arguments() const {
  return args_.size();
}
inline const std::string &ConfOption::argument(unsigned i) const {
  return args_[i];
}

inline void ConfOption::add_argument(const std::string &arg) {
  if (!arg.empty())
    args_.push_back(arg);
}

} // namespace ACBase

#endif /* ACBASE_ConfOption_H */
