version_operator.hh

Go to the documentation of this file.
00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
00005  *
00006  * This file is part of the Paludis package manager. Paludis is free software;
00007  * you can redistribute it and/or modify it under the terms of the GNU General
00008  * Public License version 2, as published by the Free Software Foundation.
00009  *
00010  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013  * details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef PALUDIS_GUARD_PALUDIS_VERSION_OPERATOR_HH
00021 #define PALUDIS_GUARD_PALUDIS_VERSION_OPERATOR_HH 1
00022 
00023 #include <paludis/util/instantiation_policy.hh>
00024 #include <paludis/util/operators.hh>
00025 #include <paludis/util/exception.hh>
00026 #include <paludis/version_operator-fwd.hh>
00027 #include <paludis/version_spec-fwd.hh>
00028 #include <string>
00029 
00030 /** \file
00031  * Declarations for VersionOperator classes.
00032  *
00033  * \ingroup g_names
00034  *
00035  * \section Examples
00036  *
00037  * - \ref example_version_operator.cc "example_version_operator.cc"
00038  * - \ref example_version_spec.cc "example_version_spec.cc"
00039  */
00040 
00041 namespace paludis
00042 {
00043     /**
00044      * An operator attached to a VersionSpec, validated.
00045      *
00046      * \ingroup g_names
00047      */
00048     class PALUDIS_VISIBLE VersionOperator :
00049         public equality_operators::HasEqualityOperators
00050     {
00051         friend std::ostream & operator<< (std::ostream &, const VersionOperator &);
00052 
00053         private:
00054             static VersionOperatorValue _decode(const std::string & v);
00055 
00056             VersionOperatorValue _v;
00057 
00058         public:
00059             ///\name Basic operations
00060             ///\{
00061 
00062             /**
00063              * Constructor.
00064              */
00065             VersionOperator(const VersionOperatorValue v) :
00066                 _v(v)
00067             {
00068             }
00069 
00070             /**
00071              * Copy constructor.
00072              */
00073             VersionOperator(const VersionOperator & other) :
00074                 _v(other._v)
00075             {
00076             }
00077 
00078             /**
00079              * Constructor, from a string.
00080              */
00081             explicit VersionOperator(const std::string & v) :
00082                 _v(_decode(v))
00083             {
00084             }
00085 
00086             /**
00087              * Assignment.
00088              */
00089             const VersionOperator & operator= (const VersionOperator & other)
00090             {
00091                 _v = other._v;
00092                 return *this;
00093             }
00094 
00095             ///\}
00096 
00097             /**
00098              * Return value.
00099              */
00100             VersionOperatorValue value() const
00101             {
00102                 return _v;
00103             }
00104 
00105             /**
00106              * A VersionSpec comparator function.
00107              */
00108             typedef bool (* VersionSpecComparator) (const VersionSpec &, const VersionSpec &);
00109 
00110             /**
00111              * Fetch a VersionSpecComparator.
00112              */
00113             VersionSpecComparator as_version_spec_comparator() const;
00114 
00115             ///\name Comparison operators
00116             ///\{
00117 
00118             bool operator== (const VersionOperator & other) const
00119             {
00120                 return _v == other._v;
00121             }
00122 
00123             ///\}
00124     };
00125 
00126     /**
00127      * Thrown if a bad version operator is encountered.
00128      *
00129      * \ingroup g_names
00130      * \ingroup g_exceptions
00131      */
00132     class PALUDIS_VISIBLE BadVersionOperatorError :
00133         public Exception
00134     {
00135         public:
00136             /**
00137              * Constructor.
00138              */
00139             BadVersionOperatorError(const std::string & msg) throw ();
00140     };
00141 }
00142 
00143 #endif

Generated on Mon Sep 21 10:36:08 2009 for paludis by  doxygen 1.5.4