sbuild  1.7.1
personality.h
1 /* Copyright © 2006-2013 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/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 (const std::string& persona);
69 
71  ~personality ();
72 
78  const std::string& get_name () const;
79 
86  void set_name (const std::string& 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  const personality& rhs)
147  {
148  return stream << find_personality(rhs.persona);
149  }
150 
151  private:
160  static type
161  find_personality (const std::string& persona);
162 
170  static std::string const&
172 
174  std::string persona_name;
175 
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  */