00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SBUILD_PERSONALITY_H
00021 #define SBUILD_PERSONALITY_H
00022
00023 #include <sbuild/sbuild-custom-error.h>
00024
00025 #include <map>
00026 #include <ostream>
00027 #include <string>
00028
00029 namespace sbuild
00030 {
00031
00041 class personality
00042 {
00043 public:
00045 typedef unsigned long type;
00046
00048 enum error_code
00049 {
00050 BAD,
00051 SET
00052 };
00053
00055 typedef custom_error<error_code> error;
00056
00062 personality ();
00063
00069 personality (type persona);
00070
00076 personality (std::string const& persona);
00077
00079 ~personality ();
00080
00086 std::string const& get_name () const;
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.persona = find_personality(personality_name);
00130
00131 if (rhs.get_name() == "undefined" &&
00132 rhs.get_name() != personality_name)
00133 {
00134 personality::error e(personality_name, personality::BAD);
00135 e.set_reason(personality::get_personalities());
00136 throw e;
00137 }
00138 }
00139
00140 return stream;
00141 }
00142
00150 template <class charT, class traits>
00151 friend
00152 std::basic_ostream<charT,traits>&
00153 operator << (std::basic_ostream<charT,traits>& stream,
00154 personality const& rhs)
00155 {
00156 return stream << find_personality(rhs.persona);
00157 }
00158
00159 private:
00168 static type
00169 find_personality (std::string const& persona);
00170
00178 static std::string const&
00179 find_personality (type persona);
00180
00182 type persona;
00183
00185 static std::map<std::string,type> personalities;
00186 };
00187
00188 }
00189
00190 #endif
00191
00192
00193
00194
00195
00196