aboutsummaryrefslogtreecommitdiff
path: root/0.8.0/paludis/repositories/cran/cran_description.hh
blob: 45f354effcf1001e8891c2a52acaa9198b59d1b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2006 Danny van Dyk <kugelfang@gentoo.org>
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef PALUDIS_GUARD_PALUDIS_CRAN_DESCRIPTION_HH
#define PALUDIS_GUARD_PALUDIS_CRAN_DESCRIPTION_HH 1

#include <paludis/version_metadata.hh>
#include <paludis/util/fs_entry.hh>

namespace paludis
{
    /**
     * CRANDescription as used by CRANRepository and CRANInstalledRepository
     */
    struct PALUDIS_VISIBLE CRANDescription
    {
        /// Our package name.
        QualifiedPackageName name;

        /// Our package version.
        VersionSpec version;

        /// Our metadata, may be zero.
        VersionMetadata::Pointer metadata;

        /// Turn a CRAN package name into a paludis package name.
        static void normalise_name(std::string & s)
        {
            std::replace_if(s.begin(), s.end(), std::bind2nd(std::equal_to<char>(), '.'), '-');
        }

        /// Turn a paludis package name into a CRAN package name.
        static void denormalise_name(std::string & s)
        {
            std::replace_if(s.begin(), s.end(), std::bind2nd(std::equal_to<char>(), '-'), '.');
        }

        /// Turn a CRAN package version into a paludis package version.
        static void normalise_version(std::string & s)
        {
            std::replace_if(s.begin(), s.end(), std::bind2nd(std::equal_to<char>(), '-'), '.');
        }

        /// Constructor
        CRANDescription(const std::string & n, const FSEntry & f);

        /// Comparison operator
        bool operator< (const CRANDescription & other) const
        {
            if (name < other.name)
                return true;
            if (name > other.name)
                return false;
            if (version < other.version)
                return true;
            return false;
        }

        /**
         * Compare a CRANDescription by name only.
         *
         * \ingroup grpcrandesc
         */
        struct PALUDIS_VISIBLE ComparePackage
        {
            bool operator() (const QualifiedPackageName & c, const CRANDescription & d) const
            {
                return c < d.name;
            }

            bool operator() (const CRANDescription & d, const QualifiedPackageName & c) const
            {
                return d.name < c;
            }
        };

        /**
         * Compare a CRANIDescription by name and version.
         *
         * \ingroup grpcrandesc
         */
        struct PALUDIS_VISIBLE CompareVersion
        {
            bool operator() (const std::pair<QualifiedPackageName, VersionSpec> & c,
                    const CRANDescription & d) const
            {
                if (c.first < d.name)
                    return true;
                else if (c.first > d.name)
                    return false;
                else if (c.second < d.version)
                    return true;
                else
                    return false;
            }

            bool operator() (const CRANDescription & d,
                    const std::pair<QualifiedPackageName, VersionSpec> & c) const
            {
                if (d.name < c.first)
                    return true;
                else if (d.name > c.first)
                    return false;
                else if (d.version < c.second)
                    return true;
                else
                    return false;
            }
        };
    };
}

#endif