schroot-base-option-action.cc

Go to the documentation of this file.
00001 /* Copyright © 2006-2007  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software: you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation, either version 3 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>.
00016  *
00017  *********************************************************************/
00018 
00019 #include <config.h>
00020 
00021 #include <sbuild/sbuild-i18n.h>
00022 
00023 #include "schroot-base-option-action.h"
00024 
00025 #include <iomanip>
00026 
00027 #include <boost/format.hpp>
00028 #include <boost/program_options.hpp>
00029 
00030 using std::endl;
00031 using boost::format;
00032 using sbuild::_;
00033 namespace opt = boost::program_options;
00034 using namespace schroot_base;
00035 
00036 option_action::option_action ():
00037   default_action(),
00038   current_action(),
00039   actions()
00040 {
00041 }
00042 
00043 option_action::~option_action ()
00044 {
00045 }
00046 
00047 void
00048 option_action::add (action_type const& action)
00049 {
00050   this->actions.insert(action);
00051 }
00052 
00053 option_action::action_type const&
00054 option_action::get_default ()
00055 {
00056   return this->default_action;
00057 }
00058 
00059 void
00060 option_action::set_default (action_type const& action)
00061 {
00062   if (valid(action))
00063     this->default_action = action;
00064   else
00065     throw std::logic_error((format(_("%1%: invalid action")) % action).str());
00066 }
00067 
00068 option_action::action_type const&
00069 option_action::get ()
00070 {
00071   if (this->current_action != "")
00072     return this->current_action;
00073   else
00074     return this->default_action;
00075 }
00076 
00077 void
00078 option_action::set (action_type const& action)
00079 {
00080   if (valid(action))
00081     {
00082       if (this->current_action == "")
00083         this->current_action = action;
00084       else
00085         throw opt::validation_error(_("Only one action may be specified"));
00086     }
00087   else
00088     throw std::logic_error((format(_("%1%: invalid action")) % action).str());
00089 }
00090 
00091 bool
00092 option_action::valid (action_type const& action)
00093 {
00094   return this->actions.find(action) != this->actions.end();
00095 }
00096 

Generated on Mon Jan 21 00:38:28 2008 for schroot by  doxygen 1.5.4