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 #ifndef SCHROOT_BASE_OPTION_ACTION_H 00020 #define SCHROOT_BASE_OPTION_ACTION_H 00021 00022 #include <set> 00023 #include <string> 00024 00025 namespace schroot_base 00026 { 00027 00036 class option_action 00037 { 00038 public: 00039 typedef std::string action_type; 00040 00042 option_action (); 00043 00045 virtual ~option_action (); 00046 00052 void 00053 add (action_type const& action); 00054 00055 /* 00056 * Get the default action. 00057 * @returns the default action, or an empty string if no default 00058 * action has been set. 00059 */ 00060 action_type const& 00061 get_default (); 00062 00067 void 00068 set_default (action_type const& action); 00069 00070 /* 00071 * Get the action to perform. 00072 * @returns the action, or the default action if no action has 00073 * been set, or an empty string if no default action has been set. 00074 */ 00075 action_type const& 00076 get (); 00077 00085 void 00086 set (action_type const& action); 00087 00093 bool 00094 valid (action_type const& action); 00095 00096 option_action& operator = (action_type const& action) 00097 { 00098 set(action); 00099 return *this; 00100 } 00101 00102 bool operator == (action_type const& action) 00103 { 00104 if (get() == action) 00105 return true; 00106 else 00107 return false; 00108 } 00109 00110 bool operator != (action_type const& action) 00111 { 00112 return !(*this == action); 00113 } 00114 00115 private: 00117 typedef std::set<std::string> action_set; 00118 00120 std::string default_action; 00121 00123 std::string current_action; 00124 00126 action_set actions; 00127 }; 00128 00129 } 00130 00131 #endif /* SCHROOT_BASE_OPTION_ACTION_H */ 00132 00133 /* 00134 * Local Variables: 00135 * mode:C++ 00136 * End: 00137 */