File indexing completed on 2024-04-28 05:42:11

0001 /*
0002  * Port for usage with qt-framework and development for kdesvn
0003  * Copyright (C) 2005-2009 by Rajko Albrecht (ral@alwins-world.de)
0004  * https://kde.org/applications/development/org.kde.kdesvn
0005  */
0006 /*
0007  * ====================================================================
0008  * Copyright (c) 2002-2005 The RapidSvn Group.  All rights reserved.
0009  * dev@rapidsvn.tigris.org
0010  *
0011  * This library is free software; you can redistribute it and/or
0012  * modify it under the terms of the GNU Lesser General Public
0013  * License as published by the Free Software Foundation; either
0014  * version 2.1 of the License, or (at your option) any later version.
0015  *
0016  * This library is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019  * Lesser General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU Lesser General Public
0022  * License along with this library (in the file LGPL.txt); if not,
0023  * write to the Free Software Foundation, Inc., 51 Franklin St,
0024  * Fifth Floor, Boston, MA  02110-1301  USA
0025  *
0026  * This software consists of voluntary contributions made by many
0027  * individuals.  For exact contribution history, see the revision
0028  * history and logs, available at http://rapidsvn.tigris.org/.
0029  * ====================================================================
0030  */
0031 
0032 #ifndef SVNQT_REVISION_H
0033 #define SVNQT_REVISION_H
0034 
0035 // svncpp
0036 #include <svnqt/datetime.h>
0037 #include <svnqt/svnqt_defines.h>
0038 
0039 #include <QDateTime>
0040 #include <QString>
0041 #include <QTextStream>
0042 
0043 // subversion api
0044 #include <svn_opt.h>
0045 #include <svn_types.h>
0046 
0047 namespace svn
0048 {
0049 /**
0050  * Class that encapsulates svn_opt_revnum_t.
0051  *
0052  * @see svn_opt_revnum_t
0053  */
0054 class SVNQT_EXPORT Revision
0055 {
0056 private:
0057     svn_opt_revision_t m_revision;
0058 
0059     void init(const svn_opt_revision_t *revision);
0060 
0061     void assign(const QString &);
0062 
0063     void assign(const QDateTime &);
0064 
0065 public:
0066     /*!
0067      * \defgroup Predefinedrevisions Predefined revision
0068      *
0069      * defines some well-known revision and revision-types for easier use.
0070      */
0071     /*@{*/
0072     //! Describes the start revision
0073     static const svn_opt_revision_kind START;
0074     //! Describes the base revision (eg, last update of working copy)
0075     static const svn_opt_revision_kind BASE;
0076     //! Describes HEAD revision of repository, eg. latest commit into repository
0077     static const svn_opt_revision_kind HEAD;
0078     //! Describes current working state of working copy
0079     static const svn_opt_revision_kind WORKING;
0080     //! Describes not know revision
0081     static const svn_opt_revision_kind UNDEFINED;
0082     //! Defines the revision before current head.
0083     static const svn_opt_revision_kind PREV;
0084     //! the revision contains a date.
0085     /*!
0086      * When Revision is of this type the date() methode returns a valid value.
0087      * \sa date()
0088      */
0089     static const svn_opt_revision_kind DATE;
0090     //! Revision contains a revision number
0091     /*!
0092      * When revision is of this type revnum() returns a valid value.
0093      * @sa revnum()
0094      */
0095     static const svn_opt_revision_kind NUMBER;
0096     /*@}*/
0097 
0098     /**
0099      * Constructor
0100      *
0101      * @param revision revision information
0102      */
0103     Revision(const svn_opt_revision_t *revision); // krazy:exclude=explicit
0104 
0105     /**
0106      * Constructor
0107      *
0108      * @param revnum revision number
0109      */
0110     Revision(const svn_revnum_t revnum); // krazy:exclude=explicit
0111 
0112     /**
0113      * Constructor
0114      * @param revnum a revision number
0115      * @param revstring a revision string
0116      *
0117      * The revision string MUST uppercase, it may some of "WORKING", "BASE", "START", "PREV",
0118      * a svn revision number/range or a date in form {YYYY-MM-DD}.
0119      */
0120     Revision(const int revnum, const QString &revstring);
0121 
0122     /**
0123      * Constructor
0124      * @param revstring a revision string
0125      *
0126      * The revision string MUST uppercase, it may some of "WORKING", "BASE", "START", "PREV",
0127      * a svn revision number/range or a date in form {YYYY-MM-DD}.
0128      */
0129     Revision(const QString &revstring); // krazy:exclude=explicit
0130 
0131     /**
0132      * Constructor
0133      *
0134      * @param kind
0135      */
0136     Revision(const svn_opt_revision_kind kind = svn_opt_revision_unspecified); // krazy:exclude=explicit
0137 
0138     /**
0139      * Constructor
0140      *
0141      * @param dateTime QDateTime type
0142      */
0143     Revision(const QDateTime &dateTime); // krazy:exclude=explicit
0144 
0145     /**
0146      * @return revision information
0147      */
0148     const svn_opt_revision_t *revision() const;
0149 
0150     /**
0151      * @see revision (). Same function
0152      * but with operator overloading
0153      */
0154     operator svn_opt_revision_t *()
0155     {
0156         return &m_revision;
0157     }
0158 
0159     /**
0160      * @see revision (). Same function
0161      * but with operator overloading
0162      */
0163     operator const svn_opt_revision_t *() const
0164     {
0165         return &m_revision;
0166     }
0167 
0168     /**
0169      * @return revision numver
0170      */
0171     svn_revnum_t revnum() const;
0172 
0173     /**
0174      * @return revision kind
0175      */
0176     svn_opt_revision_kind kind() const;
0177 
0178     operator QString() const;
0179     QString toString() const;
0180 
0181     bool isRemote() const;
0182     bool isValid() const;
0183 
0184     /**
0185      * @return valid date if kind is Revision::DATE
0186      */
0187     apr_time_t date() const;
0188 
0189     bool operator==(const Revision &) const;
0190     bool operator!=(const svn_opt_revision_kind) const;
0191     bool operator==(const svn_opt_revision_kind) const;
0192     bool operator==(int) const;
0193 
0194     bool operator!() const;
0195     bool operator!();
0196     operator bool() const;
0197     operator bool();
0198 
0199     /**
0200      * assignment operator
0201      * @param what a simple revision string (not s:e but s)
0202      * @return object itself
0203      */
0204     Revision &operator=(const QString &what);
0205 };
0206 }
0207 
0208 inline QTextStream &operator<<(QTextStream &s, svn::Revision &r)
0209 {
0210     s << r.toString();
0211     return s;
0212 }
0213 
0214 #endif
0215 /* -----------------------------------------------------------------
0216  * local variables:
0217  * eval: (load-file "../../rapidsvn-dev.el")
0218  * end:
0219  */