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