sbuild
1.5.4
|
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 SBUILD_PERSONALITY_H 00020 #define SBUILD_PERSONALITY_H 00021 00022 #include <sbuild/sbuild-custom-error.h> 00023 00024 #include <map> 00025 #include <ostream> 00026 #include <string> 00027 00028 namespace sbuild 00029 { 00030 00040 class personality 00041 { 00042 public: 00044 typedef unsigned long type; 00045 00047 enum error_code 00048 { 00049 BAD, 00050 SET 00051 }; 00052 00054 typedef custom_error<error_code> error; 00055 00061 personality (); 00062 00068 personality (std::string const& persona); 00069 00071 ~personality (); 00072 00078 std::string const& get_name () const; 00079 00086 void set_name (std::string const& persona); 00087 00093 type 00094 get () const; 00095 00101 void 00102 set () const; 00103 00109 static std::string 00110 get_personalities (); 00111 00119 template <class charT, class traits> 00120 friend 00121 std::basic_istream<charT,traits>& 00122 operator >> (std::basic_istream<charT,traits>& stream, 00123 personality& rhs) 00124 { 00125 std::string personality_name; 00126 00127 if (std::getline(stream, personality_name)) 00128 { 00129 rhs.set_name(personality_name); 00130 } 00131 00132 return stream; 00133 } 00134 00142 template <class charT, class traits> 00143 friend 00144 std::basic_ostream<charT,traits>& 00145 operator << (std::basic_ostream<charT,traits>& stream, 00146 personality const& rhs) 00147 { 00148 return stream << find_personality(rhs.persona); 00149 } 00150 00151 private: 00160 static type 00161 find_personality (std::string const& persona); 00162 00170 static std::string const& 00171 find_personality (type persona); 00172 00174 std::string persona_name; 00175 00177 type persona; 00178 00180 static std::map<std::string,type> personalities; 00181 }; 00182 00183 } 00184 00185 #endif /* SBUILD_PERSONALITY_H */ 00186 00187 /* 00188 * Local Variables: 00189 * mode:C++ 00190 * End: 00191 */