sbuild  1.6.10
sbuild-personality.h
1 /* Copyright © 2006-2007 Roger Leigh <rleigh@debian.org>
2  *
3  * schroot is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * schroot is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  *********************************************************************/
18 
19 #ifndef SBUILD_PERSONALITY_H
20 #define SBUILD_PERSONALITY_H
21 
22 #include <sbuild/sbuild-custom-error.h>
23 
24 #include <map>
25 #include <ostream>
26 #include <string>
27 
28 namespace sbuild
29 {
30 
41  {
42  public:
44  typedef unsigned long type;
45 
48  {
49  BAD,
50  SET
51  };
52 
55 
61  personality ();
62 
68  personality (std::string const& persona);
69 
71  ~personality ();
72 
78  std::string const& get_name () const;
79 
86  void set_name (std::string const& persona);
87 
93  type
94  get () const;
95 
101  void
102  set () const;
103 
109  static std::string
111 
119  template <class charT, class traits>
120  friend
121  std::basic_istream<charT,traits>&
122  operator >> (std::basic_istream<charT,traits>& stream,
123  personality& rhs)
124  {
125  std::string personality_name;
126 
127  if (std::getline(stream, personality_name))
128  {
129  rhs.set_name(personality_name);
130  }
131 
132  return stream;
133  }
134 
142  template <class charT, class traits>
143  friend
144  std::basic_ostream<charT,traits>&
145  operator << (std::basic_ostream<charT,traits>& stream,
146  personality const& rhs)
147  {
148  return stream << find_personality(rhs.persona);
149  }
150 
151  private:
160  static type
161  find_personality (std::string const& persona);
162 
170  static std::string const&
171  find_personality (type persona);
172 
174  std::string persona_name;
175 
177  type persona;
178 
180  static std::map<std::string,type> personalities;
181  };
182 
183 }
184 
185 #endif /* SBUILD_PERSONALITY_H */
186 
187 /*
188  * Local Variables:
189  * mode:C++
190  * End:
191  */
Could not set personality.
Definition: sbuild-personality.h:50
Personality is unknown.
Definition: sbuild-personality.h:49
Debian source builder components.
Definition: sbuild-auth-null.h:24
void set_name(std::string const &persona)
Set the name of the personality.
Definition: sbuild-personality.cc:156
std::string const & get_name() const
Get the name of the personality.
Definition: sbuild-personality.cc:150
Chroot personality.
Definition: sbuild-personality.h:40
custom_error< error_code > error
Exception type.
Definition: sbuild-personality.h:54
friend std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &stream, personality &rhs)
Get the personality name from a stream.
Definition: sbuild-personality.h:122
error_code
Error codes.
Definition: sbuild-personality.h:47
static std::map< std::string, type > personalities
Mapping between personality name and type.
Definition: sbuild-personality.h:180
personality()
The constructor.
Definition: sbuild-personality.cc:105
Custom error.
Definition: sbuild-custom-error.h:32
static type find_personality(std::string const &persona)
Find a personality by name.
Definition: sbuild-personality.cc:124
static std::string get_personalities()
Print a list of the available personalities.
Definition: sbuild-personality.cc:193
unsigned long type
Personality type.
Definition: sbuild-personality.h:44
type persona
The personality type.
Definition: sbuild-personality.h:177
~personality()
Definition: sbuild-personality.cc:119
std::string persona_name
The name of the current personality.
Definition: sbuild-personality.h:174