Edition replaced by Edition of libzypp
[platform/upstream/libzypp.git] / zypp / solver / detail / Dependency.h
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* Dependency.h
3  * Copyright (C) 2000-2002 Ximian, Inc.
4  * Copyright (C) 2005 SUSE Linux Products GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20
21 #ifndef _Dependency_h
22 #define _Dependency_h
23
24 #include <list>
25 #include <iosfwd>
26 #include <string.h>
27
28 #include <y2util/Ustring.h>
29
30 #include <zypp/solver/detail/Channel.h>
31 #include <zypp/solver/detail/DependencyPtr.h>
32 #include <zypp/solver/detail/OrDependencyPtr.h>
33 #include <zypp/solver/detail/Spec.h>
34 #include <zypp/solver/detail/XmlNode.h>
35 #include <zypp/ResObject.h>
36
37 /////////////////////////////////////////////////////////////////////////
38 namespace zypp 
39 { ///////////////////////////////////////////////////////////////////////
40   ///////////////////////////////////////////////////////////////////////
41   namespace solver
42   { /////////////////////////////////////////////////////////////////////
43     /////////////////////////////////////////////////////////////////////
44     namespace detail
45     { ///////////////////////////////////////////////////////////////////
46
47       ///////////////////////////////////////////////////////////////////
48       //
49       //      CLASS NAME : Relation
50       /**
51        * A dependency relation
52        **/
53       
54       class Relation {
55       
56         private:
57       
58           int _op;
59       
60           Relation (int op) { _op = op; }
61       
62         public:
63       
64           virtual ~Relation() {}
65       
66           // ---------------------------------- I/O
67       
68           static std::string toString ( const Relation & relation );
69       
70           static std::string toWord ( const Relation & relation );
71       
72           virtual std::ostream & dumpOn( std::ostream & str ) const;
73       
74           friend std::ostream& operator<<( std::ostream & str, const Relation & relation );
75       
76           std::string asString ( void ) const;
77       
78           // ---------------------------------- consts
79       
80           static const Relation & Invalid;
81           static const Relation & Any;
82           static const Relation & Equal;
83           static const Relation & NotEqual;
84           static const Relation & Less;
85           static const Relation & LessEqual;
86           static const Relation & Greater;
87           static const Relation & GreaterEqual;
88           static const Relation & None;
89       
90           static const Relation & parse (const char *relation);
91       
92           // ---------------------------------- accessors
93       
94           int op (void) const { return _op; }
95       
96           bool isEqual () const;
97       
98           // equality operator
99           bool operator==( const Relation & rel ) const {
100         return (_op == rel.op());
101           }
102       
103           // inequality
104           bool operator!=( const Relation & rel ) const {
105         return !(*this == rel);
106           }
107       
108       };
109       
110       ///////////////////////////////////////////////////////////////////
111       
112       typedef std::list <DependencyPtr> DependencyList;
113       typedef std::list <constDependencyPtr> CDependencyList;
114       
115       ///////////////////////////////////////////////////////////////////
116       //
117       //        CLASS NAME : Dependency
118       /**
119        *
120        **/
121       
122       class Dependency : public Spec {
123           REP_BODY(Dependency);
124       
125         private:
126           Relation _relation;
127           constChannelPtr _channel;
128           bool _or_dep;
129           bool _pre_dep;
130       
131         public:
132
133           Dependency (const std::string & name,
134           const Relation & relation,
135           const Resolvable::Kind & kind = ResTraits<zypp::Package>::kind,
136           constChannelPtr channel = NULL,
137           int epoch = Edition::noepoch,
138           const std::string & version = "",
139           const std::string & release = "",
140           const zypp::Arch & arch = zypp::Arch(),
141           bool or_dep = false,
142           bool pre_dep = false);
143
144           Dependency (const std::string & name,
145           const Relation & relation,
146           const Resolvable::Kind & kind = ResTraits<zypp::Package>::kind,
147           constChannelPtr channel = NULL,
148           const zypp::Edition & edition = zypp::Edition(),
149           bool or_dep = false,
150           bool pre_dep = false);
151       
152           Dependency (OrDependencyPtr or_dep);  //RCResItemDep *rc_dep_or_new_provide (RCDepOr *dor);
153       
154           Dependency (constXmlNodePtr node);            //RCResItemDep *rc_xml_node_to_resItem_dep (const xmlNode *node);
155       
156           virtual ~Dependency();
157        
158           // ---------------------------------- I/O
159       
160           const xmlNodePtr asXmlNode (void) const;              // xmlNode *rc_resItem_dep_to_xml_node (RCResItemDep *dep_item);
161       
162           static std::string toString ( const Dependency & dep );
163       
164           static std::string toString ( const CDependencyList & deplist );
165       
166           virtual std::ostream & dumpOn( std::ostream & str ) const;
167       
168           friend std::ostream& operator<<( std::ostream & str, const Dependency & dep);
169       
170           std::string asString ( void ) const;
171       
172           // ---------------------------------- accessors
173       
174           const Relation & relation() const { return _relation; }
175           constChannelPtr channel (void) const { return _channel; }
176       
177           bool orDep (void) const { return _or_dep; }
178           void setOrDep (bool or_dep) { _or_dep = or_dep; }
179       
180           bool preDep (void) const { return _pre_dep; }
181           void setPreDep (bool pre_dep) { _pre_dep = pre_dep; }
182       
183           // ---------------------------------- methods
184       
185           DependencyPtr parseXml (constXmlNodePtr node);
186           bool verifyRelation (constDependencyPtr prov) const;
187       };
188       
189       // xmlNode *rc_resItem_dep_or_slist_to_xml_node (RCResItemDepSList *dep);
190       
191       ///////////////////////////////////////////////////////////////////
192     };// namespace detail
193     /////////////////////////////////////////////////////////////////////
194     /////////////////////////////////////////////////////////////////////
195   };// namespace solver
196   ///////////////////////////////////////////////////////////////////////
197   ///////////////////////////////////////////////////////////////////////
198 };// namespace zypp
199 /////////////////////////////////////////////////////////////////////////
200
201 #endif // _Dependency_h