fix exception
[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     repo::RepoType type;
46     Url mirrorlist_url;
47     std::set<Url> baseUrls;
48     std::string alias;
49     std::string name;
50     Pathname filepath;
51   public:
52
53   private:
54     friend Impl * rwcowClone<Impl>( const Impl * rhs );
55     /** clone for RWCOW_pointer */
56     Impl * clone() const
57     { return new Impl( *this ); }
58   };
59   ///////////////////////////////////////////////////////////////////
60
61   /** \relates RepoInfo::Impl Stream output */
62   inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
63   {
64     return str << "RepoInfo::Impl";
65   }
66
67   ///////////////////////////////////////////////////////////////////
68   //
69   //    CLASS NAME : RepoInfo
70   //
71   ///////////////////////////////////////////////////////////////////
72
73   ///////////////////////////////////////////////////////////////////
74   //
75   //    METHOD NAME : RepoInfo::RepoInfo
76   //    METHOD TYPE : Ctor
77   //
78   RepoInfo::RepoInfo()
79   : _pimpl( new Impl() )
80   {}
81
82   ///////////////////////////////////////////////////////////////////
83   //
84   //    METHOD NAME : RepoInfo::~RepoInfo
85   //    METHOD TYPE : Dtor
86   //
87   RepoInfo::~RepoInfo()
88   {
89     //MIL << std::endl;
90   }
91
92   
93   
94   RepoInfo & RepoInfo::setEnabled( boost::tribool enabled )
95   {
96     _pimpl->enabled = enabled;
97     return *this;
98   }
99
100   RepoInfo & RepoInfo::setAutorefresh( boost::tribool autorefresh )
101   {
102     _pimpl->autorefresh = autorefresh;
103     return *this;
104   }
105
106   RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
107   {
108     _pimpl->mirrorlist_url = url;
109     return *this;
110   }
111
112   RepoInfo & RepoInfo::addBaseUrl( const Url &url )
113   {
114     _pimpl->baseUrls.insert(url);
115     return *this;
116   }
117
118   RepoInfo & RepoInfo::setAlias( const std::string &alias )
119   {
120     _pimpl->alias = alias;
121     return *this;
122   }
123
124   RepoInfo & RepoInfo::setType( const repo::RepoType &t )
125   {
126     _pimpl->type = t;
127     return *this;
128   }
129
130   RepoInfo & RepoInfo::setName( const std::string &name )
131   {
132     _pimpl->name = name;
133     return *this;
134   }
135
136   RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
137   {
138     _pimpl->filepath = filepath;
139     return *this;
140   }
141   
142   tribool RepoInfo::enabled() const
143   { return _pimpl->enabled; }
144
145   tribool RepoInfo::autorefresh() const
146   { return _pimpl->autorefresh; }
147
148   std::string RepoInfo::alias() const
149   { return _pimpl->alias; }
150
151   std::string RepoInfo::name() const
152   { return _pimpl->name; }
153
154   Pathname RepoInfo::filepath() const
155   { return _pimpl->filepath; }
156   
157   repo::RepoType RepoInfo::type() const
158   { return _pimpl->type; }
159
160   Url RepoInfo::mirrorListUrl() const
161   { return _pimpl->mirrorlist_url; }
162
163   std::set<Url> RepoInfo::baseUrls() const
164   { return _pimpl->baseUrls; }
165     
166   RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
167   { return _pimpl->baseUrls.begin(); }
168     
169   RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
170   { return _pimpl->baseUrls.end(); }
171   
172   std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
173   {
174     str << "--------------------------------------" << std::endl;
175     str << "- alias       : " << alias() << std::endl;
176     std::set<Url> url_set(baseUrls());
177     for ( std::set<Url>::const_iterator it = url_set.begin();
178           it != url_set.end();
179           ++it )
180     {
181       str << "- url         : " << *it << std::endl;
182     }
183     
184     str << "- type        : " << type() << std::endl;
185     str << "- enabled     : " << enabled() << std::endl;
186     str << "- autorefresh : " << autorefresh() << std::endl;
187     //str << "- path        : " << path() << std::endl;
188     return str;
189   }
190
191   std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
192   {
193     str << "[" << alias() << "]" << endl;
194     str << "name = " << name() << endl;
195
196     if ( ! baseUrls().empty() )
197       str << "baseurl = ";
198     for ( urls_const_iterator it = baseUrlsBegin();
199           it != baseUrlsEnd();
200           ++it )
201     {
202       str << *it << endl;
203     }
204     str << "mirrorlist = " << mirrorListUrl() << endl;
205     str << "type = " << type().asString() << endl;
206     str << "enabled = " << (enabled() ? "1" : "0") << endl;
207     return str;
208   }
209
210   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
211   {
212     return obj.dumpOn(str);
213   }
214   
215   /////////////////////////////////////////////////////////////////
216 } // namespace zypp
217 ///////////////////////////////////////////////////////////////////