3c2d7c94994c9347827e8e0f9684aa3cf5831e56
[platform/upstream/libzypp.git] / zypp / RepoInfo.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/RepoInfo.h
10  *
11 */
12 #ifndef ZYPP2_REPOSITORYINFO_H
13 #define ZYPP2_REPOSITORYINFO_H
14
15 #include <iosfwd>
16 #include <list>
17 #include <set>
18 #include "zypp/base/PtrTypes.h"
19
20 #include <boost/logic/tribool.hpp>
21 #include "zypp/Pathname.h"
22 #include "zypp/Url.h"
23 #include "zypp/repo/RepoType.h"
24
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29
30   ///////////////////////////////////////////////////////////////////
31   //
32   //    CLASS NAME : RepoInfo
33   //
34   /**
35    * \short What is known about a repository
36    *
37    * The class RepoInfo represents everything that
38    * is known about a software repository.
39    *
40    * It can be used to store information about known
41    * sources.
42    *
43    * This class tries to be compatible with the
44    * concept of a .repo file used by YUM and
45    * also available in the openSUSE build service.
46    * See <tt>man yum.conf</tt>.
47    *
48    * Example file
49    *
50    * \code
51    * [ruby]
52    * name=Ruby repository (openSUSE_10.2)
53    * type=rpm-md
54    * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
55    * gpgcheck=1
56    * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
57    * enabled=1
58    * \endcode
59    *
60    * \note A RepoInfo is a hint about how
61    * to create a Repository.
62    */
63   class RepoInfo
64   {
65     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
66     
67     public:
68     RepoInfo();
69     ~RepoInfo();
70     //RepoInfo( const Url & url, const Pathname & path, const std::string & alias = "", boost::tribool autorefresh = boost::indeterminate );
71     
72     /**
73      * unique identifier for this source. If not specified
74      * It should be generated from the base url.
75      *
76      * Normally, in a .repo file the section name is used
77      * ( [somerepo] )
78      */
79     std::string alias() const;
80     
81     /**
82      * A Url under which the metadata are located, or a set of mirrors.
83      *
84      * This can't be empty in order the repository to be valid
85      * unless the download of the mirror list succeeds and it
86      * contains a valid url.
87      */
88     std::set<Url> baseUrls() const;
89
90     /**
91      * Url of a file which contains a list of Urls
92      * If empty, the base url will be used.
93      */
94     Url mirrorListUrl() const;
95     
96     typedef std::set<Url>::const_iterator urls_const_iterator;
97     
98     /**
99      * iterator that points at begin of repository urls
100      */
101     urls_const_iterator baseUrlsBegin() const;
102     
103     /**
104      * iterator that points at end of repository urls
105      */
106     urls_const_iterator baseUrlsEnd() const;
107     
108     /**
109      * If enabled is false, then this repository must be ignored as if does
110      * not exists, except when checking for duplicate alias.
111      */
112     boost::tribool enabled() const;
113     
114     /**
115      * If true, the repostory must be refreshed before creating resolvables
116      * from it
117      */
118     boost::tribool autorefresh() const;
119     
120     /**
121      * Type of repository,
122      * 
123      */
124     repo::RepoType type() const;
125     
126     /**
127      * \short Repository short label
128      *
129      * Short label or description of the repository, to be used on
130      * the user interface.
131      * ie: "SUSE Linux 10.2 updates"
132      */
133     std::string name() const;
134
135     /**
136      * Add a base url. \see baseUrl
137      * \param url The base url for the repository.
138      */
139     RepoInfo & addBaseUrl( const Url &url );
140     
141     /**
142      * Set mirror list url. \see mirrorListUrl
143      * \param url The base url for the list
144      */
145     RepoInfo & setMirrorListUrl( const Url &url );
146     
147     /**
148      * enable or disable the repository \see enabled
149      * \param enabled
150      */
151     RepoInfo & setEnabled( boost::tribool enabled );
152     
153     /**
154      * enable or disable autorefresh \see autorefresh
155      * \param enabled
156      */
157     RepoInfo & setAutorefresh( boost::tribool autorefresh );
158     
159     /**
160      * set the repository alias \see alias
161      * \param alias
162      */
163     RepoInfo & setAlias( const std::string &alias );
164     
165     /**
166      * set the repository type \see type
167      * \param t
168      */
169     RepoInfo & setType( const repo::RepoType &t );
170     
171     /**
172      * set the repository name \see name
173      * \param name
174      */
175     RepoInfo & setName( const std::string &name );
176
177     std::ostream & dumpOn( std::ostream & str ) const;
178     
179     class Impl;
180   private:
181     /** Pointer to implementation */
182     RWCOW_pointer<Impl> _pimpl;
183   };
184   ///////////////////////////////////////////////////////////////////
185
186   /** \relates RepoInfo Stream output */
187   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
188
189   typedef std::list<RepoInfo> RepoInfoList;
190   
191   /////////////////////////////////////////////////////////////////
192 } // namespace zypp
193 ///////////////////////////////////////////////////////////////////
194 #endif // ZYPP2_REPOSITORYINFO_H