00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 (type persona);
00069
00075 personality (std::string const& persona);
00076
00078 ~personality ();
00079
00085 std::string const& get_name () const;
00086
00092 type
00093 get () const;
00094
00100 void
00101 set () const;
00102
00108 static std::string
00109 get_personalities ();
00110
00118 template <class charT, class traits>
00119 friend
00120 std::basic_istream<charT,traits>&
00121 operator >> (std::basic_istream<charT,traits>& stream,
00122 personality& rhs)
00123 {
00124 std::string personality_name;
00125
00126 if (std::getline(stream, personality_name))
00127 {
00128 rhs.persona = find_personality(personality_name);
00129
00130 if (rhs.get_name() == "undefined" &&
00131 rhs.get_name() != personality_name)
00132 {
00133 personality::error e(personality_name, personality::BAD);
00134 e.set_reason(personality::get_personalities());
00135 throw e;
00136 }
00137 }
00138
00139 return stream;
00140 }
00141
00149 template <class charT, class traits>
00150 friend
00151 std::basic_ostream<charT,traits>&
00152 operator << (std::basic_ostream<charT,traits>& stream,
00153 personality const& rhs)
00154 {
00155 return stream << find_personality(rhs.persona);
00156 }
00157
00158 private:
00167 static type
00168 find_personality (std::string const& persona);
00169
00177 static std::string const&
00178 find_personality (type persona);
00179
00181 type persona;
00182
00184 static std::map<std::string,type> personalities;
00185 };
00186
00187 }
00188
00189 #endif
00190
00191
00192
00193
00194
00195