sbuild-personality.h

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

Generated on Sun May 17 18:38:55 2009 for sbuild by  doxygen 1.5.9