fixed tribool bugs
[platform/upstream/libzypp.git] / zypp / RepoInfo.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/RepoInfo.cc
10  *
11 */
12 #include <iostream>
13 #include "zypp/base/Logger.h"
14
15 #include "zypp/RepoInfo.h"
16
17 using namespace std;
18 using namespace boost;
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24   ///////////////////////////////////////////////////////////////////
25   //
26   //    CLASS NAME : RepoInfo::Impl
27   //
28   /** RepoInfo implementation. */
29   struct RepoInfo::Impl
30   {
31
32     Impl()
33       : enabled (indeterminate),
34         autorefresh(indeterminate),
35         gpgcheck(indeterminate),
36         type(repo::RepoType::NONE_e)
37     {}
38
39     ~Impl()
40     {
41       //MIL << std::endl;
42     }
43   public:
44     boost::tribool enabled;
45     boost::tribool autorefresh;
46     boost::tribool gpgcheck;
47     Url gpgkey_url;
48     repo::RepoType type;
49     Url mirrorlist_url;
50     std::set<Url> baseUrls;
51     Pathname path;
52     std::string alias;
53     std::string name;
54     Pathname filepath;
55   public:
56
57   private:
58     friend Impl * rwcowClone<Impl>( const Impl * rhs );
59     /** clone for RWCOW_pointer */
60     Impl * clone() const
61     { return new Impl( *this ); }
62   };
63   ///////////////////////////////////////////////////////////////////
64
65   /** \relates RepoInfo::Impl Stream output */
66   inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
67   {
68     return str << "RepoInfo::Impl";
69   }
70
71   ///////////////////////////////////////////////////////////////////
72   //
73   //    CLASS NAME : RepoInfo
74   //
75   ///////////////////////////////////////////////////////////////////
76
77   ///////////////////////////////////////////////////////////////////
78   //
79   //    METHOD NAME : RepoInfo::RepoInfo
80   //    METHOD TYPE : Ctor
81   //
82   RepoInfo::RepoInfo()
83   : _pimpl( new Impl() )
84   {}
85
86   ///////////////////////////////////////////////////////////////////
87   //
88   //    METHOD NAME : RepoInfo::~RepoInfo
89   //    METHOD TYPE : Dtor
90   //
91   RepoInfo::~RepoInfo()
92   {
93     //MIL << std::endl;
94   }
95
96   RepoInfo & RepoInfo::setEnabled( boost::tribool enabled )
97   {
98     _pimpl->enabled = enabled;
99     return *this;
100   }
101
102   RepoInfo & RepoInfo::setAutorefresh( boost::tribool autorefresh )
103   {
104     _pimpl->autorefresh = autorefresh;
105     return *this;
106   }
107   
108   RepoInfo & RepoInfo::setGpgCheck( boost::tribool check )
109   {
110     _pimpl->gpgcheck = check;
111     return *this;
112   }
113
114   RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
115   {
116     _pimpl->mirrorlist_url = url;
117     return *this;
118   }
119   
120   RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
121   {
122     _pimpl->gpgkey_url = url;
123     return *this;
124   }
125
126   RepoInfo & RepoInfo::addBaseUrl( const Url &url )
127   {
128     _pimpl->baseUrls.insert(url);
129     return *this;
130   }
131
132   RepoInfo & RepoInfo::setBaseUrl( const Url &url )
133   {
134     _pimpl->baseUrls.clear();
135     addBaseUrl(url);
136     return *this;
137   }
138
139   RepoInfo & RepoInfo::setPath( const Pathname &path )
140   {
141     _pimpl->path = path;
142     return *this;
143   }
144   
145   RepoInfo & RepoInfo::setAlias( const std::string &alias )
146   {
147     _pimpl->alias = alias;
148     return *this;
149   }
150
151   RepoInfo & RepoInfo::setType( const repo::RepoType &t )
152   {
153     _pimpl->type = t;
154     return *this;
155   }
156
157   RepoInfo & RepoInfo::setName( const std::string &name )
158   {
159     _pimpl->name = name;
160     return *this;
161   }
162
163   RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
164   {
165     _pimpl->filepath = filepath;
166     return *this;
167   }
168
169   tribool RepoInfo::enabled() const
170   { return _pimpl->enabled; }
171
172   tribool RepoInfo::autorefresh() const
173   { return _pimpl->autorefresh; }
174   
175   tribool RepoInfo::gpgCheck() const
176   { return _pimpl->gpgcheck; }
177
178   std::string RepoInfo::alias() const
179   { return _pimpl->alias; }
180
181   std::string RepoInfo::name() const
182   { return _pimpl->name; }
183
184   Pathname RepoInfo::filepath() const
185   { return _pimpl->filepath; }
186
187   repo::RepoType RepoInfo::type() const
188   { return _pimpl->type; }
189
190   Url RepoInfo::mirrorListUrl() const
191   { return _pimpl->mirrorlist_url; }
192   
193   Url RepoInfo::gpgKeyUrl() const
194   { return _pimpl->gpgkey_url; }
195
196   std::set<Url> RepoInfo::baseUrls() const
197   { return _pimpl->baseUrls; }
198
199   Pathname RepoInfo::path() const
200   { return _pimpl->path; }
201   
202   RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
203   { return _pimpl->baseUrls.begin(); }
204
205   RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
206   { return _pimpl->baseUrls.end(); }
207
208   RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
209   { return _pimpl->baseUrls.size(); }
210
211   bool RepoInfo::baseUrlsEmpty() const
212   { return _pimpl->baseUrls.empty(); }
213
214   std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
215   {
216     str << "--------------------------------------" << std::endl;
217     str << "- alias       : " << alias() << std::endl;
218     std::set<Url> url_set(baseUrls());
219     for ( std::set<Url>::const_iterator it = url_set.begin();
220           it != url_set.end();
221           ++it )
222     {
223       str << "- url         : " << *it << std::endl;
224     }
225     str << "- path        : " << path() << std::endl;
226     str << "- type        : " << type() << std::endl;
227     str << "- enabled     : " << enabled() << std::endl;
228     
229     str << "- autorefresh : " << autorefresh() << std::endl;
230     str << "- gpgcheck : " << gpgCheck() << std::endl;
231     str << "- gpgkey : " << gpgKeyUrl() << std::endl;
232     
233     return str;
234   }
235
236   std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
237   {
238     str << "[" << alias() << "]" << endl;
239     str << "name=" << name() << endl;
240
241     if ( ! baseUrls().empty() )
242       str << "baseurl=";
243     for ( urls_const_iterator it = baseUrlsBegin();
244           it != baseUrlsEnd();
245           ++it )
246     {
247       str << *it << endl;
248     }
249     
250     if ( ! path().empty() )
251       str << "path="<< path() << endl;
252     
253     if ( ! (mirrorListUrl().asString().empty()) )
254       str << "mirrorlist=" << mirrorListUrl() << endl;
255     
256     str << "type=" << type().asString() << endl;
257     
258     if ( ! indeterminate(enabled()) )
259       str << "enabled=" << (enabled() ? "1" : "0") << endl;
260     if ( ! indeterminate(autorefresh()) )
261       str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
262     if ( ! indeterminate(gpgCheck()) )
263       str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
264     if ( ! (gpgKeyUrl().asString().empty()) )
265       str << "gpgkey=" <<gpgKeyUrl() << endl;
266
267     return str;
268   }
269
270   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
271   {
272     return obj.dumpOn(str);
273   }
274
275   /////////////////////////////////////////////////////////////////
276 } // namespace zypp
277 ///////////////////////////////////////////////////////////////////