sbuild-personality.h

Go to the documentation of this file.
00001 /* Copyright © 2006  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 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 /* SBUILD_PERSONALITY_H */
00191 
00192 /*
00193  * Local Variables:
00194  * mode:C++
00195  * End:
00196  */

Generated on Sat Jan 27 16:11:03 2007 for schroot by  doxygen 1.5.1