paludis  Version 2.6.0
version_operator.hh
Go to the documentation of this file.
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 2005, 2006, 2007, 2010 Ciaran McCreesh
5  *
6  * This file is part of the Paludis package manager. Paludis is free software;
7  * you can redistribute it and/or modify it under the terms of the GNU General
8  * Public License version 2, as published by the Free Software Foundation.
9  *
10  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17  * Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #ifndef PALUDIS_GUARD_PALUDIS_VERSION_OPERATOR_HH
21 #define PALUDIS_GUARD_PALUDIS_VERSION_OPERATOR_HH 1
22 
23 #include <paludis/util/operators.hh>
27 #include <string>
28 
29 /** \file
30  * Declarations for VersionOperator classes.
31  *
32  * \ingroup g_names
33  *
34  * \section Examples
35  *
36  * - \ref example_version_operator.cc "example_version_operator.cc"
37  * - \ref example_version_spec.cc "example_version_spec.cc"
38  */
39 
40 namespace paludis
41 {
42  /**
43  * An operator attached to a VersionSpec, validated.
44  *
45  * \ingroup g_names
46  */
49  {
50  friend std::ostream & operator<< (std::ostream &, const VersionOperator &);
51 
52  private:
53  static VersionOperatorValue _decode(const std::string & v);
54 
56 
57  public:
58  ///\name Basic operations
59  ///\{
60 
61  /**
62  * Constructor.
63  */
65  _v(v)
66  {
67  }
68 
69  /**
70  * Copy constructor.
71  */
73  _v(other._v)
74  {
75  }
76 
77  /**
78  * Constructor, from a string.
79  */
80  explicit VersionOperator(const std::string & v) :
81  _v(_decode(v))
82  {
83  }
84 
85  /**
86  * Assignment.
87  */
88  const VersionOperator & operator= (const VersionOperator & other)
89  {
90  _v = other._v;
91  return *this;
92  }
93 
94  ///\}
95 
96  /**
97  * Return value.
98  */
100  {
101  return _v;
102  }
103 
104  /**
105  * A VersionSpec comparator function.
106  */
107  typedef bool (* VersionSpecComparator) (const VersionSpec &, const VersionSpec &);
108 
109  /**
110  * Fetch a VersionSpecComparator.
111  */
112  VersionSpecComparator as_version_spec_comparator() const;
113 
114  ///\name Comparison operators
115  ///\{
116 
117  bool operator== (const VersionOperator & other) const
118  {
119  return _v == other._v;
120  }
121 
122  ///\}
123  };
124 
125  /**
126  * Thrown if a bad version operator is encountered.
127  *
128  * \ingroup g_names
129  * \ingroup g_exceptions
130  */
132  public Exception
133  {
134  public:
135  /**
136  * Constructor.
137  */
138  BadVersionOperatorError(const std::string & msg) noexcept;
139  };
140 }
141 
142 #endif
Definition: about_metadata-fwd.hh:23
Definition: version_spec.hh:107
Definition: version_operator.hh:131
VersionOperator(const VersionOperatorValue v)
Definition: version_operator.hh:64
Definition: exception.hh:74
Definition: version_operator.hh:47
std::ostream & operator<<(std::ostream &, const WantPhase &) PALUDIS_VISIBLE
VersionOperatorValue
Definition: version_operator-fwd.hh:13
VersionOperatorValue value() const
Definition: version_operator.hh:99
VersionOperator(const std::string &v)
Definition: version_operator.hh:80
VersionOperator(const VersionOperator &other)
Definition: version_operator.hh:72
#define PALUDIS_VISIBLE
Definition: attributes.hh:59
bool operator==(const PackageID &, const PackageID &) PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE