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 2 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, write to the Free Software 00015 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00016 * MA 02111-1307 USA 00017 * 00018 *********************************************************************/ 00019 00020 #ifndef SCHROOT_BASE_OPTION_ACTION_H 00021 #define SCHROOT_BASE_OPTION_ACTION_H 00022 00023 #include <set> 00024 #include <string> 00025 00026 namespace schroot_base 00027 { 00028 00037 class option_action 00038 { 00039 public: 00040 typedef std::string action_type; 00041 00043 option_action (); 00044 00046 virtual ~option_action (); 00047 00053 void 00054 add (action_type const& action); 00055 00056 /* 00057 * Get the default action. 00058 * @returns the default action, or an empty string if no default 00059 * action has been set. 00060 */ 00061 action_type const& 00062 get_default (); 00063 00068 void 00069 set_default (action_type const& action); 00070 00071 /* 00072 * Get the action to perform. 00073 * @returns the action, or the default action if no action has 00074 * been set, or an empty string if no default action has been set. 00075 */ 00076 action_type const& 00077 get (); 00078 00086 void 00087 set (action_type const& action); 00088 00094 bool 00095 valid (action_type const& action); 00096 00097 option_action& operator = (action_type const& action) 00098 { 00099 set(action); 00100 return *this; 00101 } 00102 00103 bool operator == (action_type const& action) 00104 { 00105 if (get() == action) 00106 return true; 00107 else 00108 return false; 00109 } 00110 00111 bool operator != (action_type const& action) 00112 { 00113 return !(*this == action); 00114 } 00115 00116 private: 00118 typedef std::set<std::string> action_set; 00119 00121 std::string default_action; 00122 00124 std::string current_action; 00125 00127 action_set actions; 00128 }; 00129 00130 } 00131 00132 #endif /* SCHROOT_BASE_OPTION_ACTION_H */ 00133 00134 /* 00135 * Local Variables: 00136 * mode:C++ 00137 * End: 00138 */