File indexing completed on 2024-05-12 17:16:25

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  * http://kdesvn.alwins-world.de
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 <QString>
0040 #include <QDateTime>
0041 #include <QTextStream>
0042 
0043 // subversion api
0044 #include <svn_types.h>
0045 #include <svn_opt.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
0060     init(const svn_opt_revision_t *revision);
0061 
0062     void
0063     assign(const QString &);
0064 
0065     void
0066     assign(const QDateTime &);
0067 
0068 public:
0069     /*!
0070      * \defgroup Predefinedrevisions Predefined revision
0071      *
0072      * defines some well-known revision and revision-types for easier use.
0073      */
0074     /*@{*/
0075     //! Describes the start revision
0076     static const svn_opt_revision_kind START;
0077     //! Describes the base revision (eg, last update of working copy)
0078     static const svn_opt_revision_kind BASE;
0079     //! Describes HEAD revision of repository, eg. latest commit into repository
0080     static const svn_opt_revision_kind HEAD;
0081     //! Describes current working state of working copy
0082     static const svn_opt_revision_kind WORKING;
0083     //! Describes not know revision
0084     static const svn_opt_revision_kind UNDEFINED;
0085     //! Defines the revision before current head.
0086     static const svn_opt_revision_kind PREV;
0087     //! the revision contains a date.
0088     /*!
0089      * When Revision is of this type the date() methode returns a valid value.
0090      * \sa date()
0091      */
0092     static const svn_opt_revision_kind DATE;
0093     //! Revision contains a revision number
0094     /*!
0095      * When revision is of this type revnum() returns a valid value.
0096      * @sa revnum()
0097      */
0098     static const svn_opt_revision_kind NUMBER;
0099     /*@}*/
0100 
0101     /**
0102      * Constructor
0103      *
0104      * @param revision revision information
0105      */
0106     Revision(const svn_opt_revision_t *revision);    //krazy:exclude=explicit
0107 
0108     /**
0109      * Constructor
0110      *
0111      * @param revnum revision number
0112      */
0113     Revision(const svn_revnum_t revnum);    //krazy:exclude=explicit
0114 
0115     /**
0116      * Constructor
0117      * @param revnum a revision number
0118      * @param revstring a revision string
0119      *
0120      * The revision string MUST uppercase, it may some of "WORKING", "BASE", "START", "PREV",
0121      * a svn revision number/range or a date in form {YYYY-MM-DD}.
0122      */
0123     Revision(const int revnum, const QString &revstring);
0124 
0125     /**
0126      * Constructor
0127      * @param revstring a revision string
0128      *
0129      * The revision string MUST uppercase, it may some of "WORKING", "BASE", "START", "PREV",
0130      * a svn revision number/range or a date in form {YYYY-MM-DD}.
0131      */
0132     Revision(const QString &revstring);    //krazy:exclude=explicit
0133 
0134     /**
0135      * Constructor
0136      *
0137      * @param kind
0138      */
0139     Revision(const svn_opt_revision_kind kind = svn_opt_revision_unspecified);    //krazy:exclude=explicit
0140 
0141     /**
0142      * Constructor
0143      *
0144      * @param dateTime QDateTime type
0145      */
0146     Revision(const QDateTime &dateTime);    //krazy:exclude=explicit
0147 
0148     /**
0149      * @return revision information
0150      */
0151     const svn_opt_revision_t *
0152     revision() const;
0153 
0154     /**
0155      * @see revision (). Same function
0156      * but with operator overloading
0157      */
0158     operator svn_opt_revision_t *()
0159     {
0160         return &m_revision;
0161     }
0162 
0163     /**
0164      * @see revision (). Same function
0165      * but with operator overloading
0166      */
0167     operator const svn_opt_revision_t *()const
0168     {
0169         return &m_revision;
0170     }
0171 
0172     /**
0173      * @return revision numver
0174      */
0175     svn_revnum_t
0176     revnum() const;
0177 
0178     /**
0179      * @return revision kind
0180      */
0181     svn_opt_revision_kind
0182     kind() const;
0183 
0184     operator QString()const;
0185     QString toString()const;
0186 
0187     bool isRemote()const;
0188     bool isValid()const;
0189 
0190     /**
0191      * @return valid date if kind is Revision::DATE
0192      */
0193     apr_time_t
0194     date() const;
0195 
0196     bool operator==(const Revision &)const;
0197     bool operator!=(const svn_opt_revision_kind)const;
0198     bool operator==(const svn_opt_revision_kind)const;
0199     bool operator==(int)const;
0200 
0201     bool operator!()const;
0202     bool operator!();
0203     operator bool()const;
0204     operator bool();
0205 
0206     /**
0207      * assignment operator
0208      * @param what a simple revision string (not s:e but s)
0209      * @return object itself
0210      */
0211     Revision &operator=(const QString &what);
0212 
0213 };
0214 }
0215 
0216 inline QTextStream &operator<<(QTextStream &s, svn::Revision &r)
0217 {
0218     s << r.toString();
0219     return s;
0220 }
0221 
0222 #endif
0223 /* -----------------------------------------------------------------
0224  * local variables:
0225  * eval: (load-file "../../rapidsvn-dev.el")
0226  * end:
0227  */