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