File indexing completed on 2024-04-28 16:01:32
0001 /****************************************************************************** 0002 * This file is part of the libqgit2 library 0003 * Copyright (c) 2011 Laszlo Papp <djszapi@archlinux.us> 0004 * Copyright (C) 2013 Leonardo Giordani 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 0021 #ifndef LIBQGIT2_OBJECT_H 0022 #define LIBQGIT2_OBJECT_H 0023 0024 #include <QtCore/QString> 0025 #include <QtCore/QDateTime> 0026 #include <QtCore/QSharedPointer> 0027 0028 #include "libqgit2_export.h" 0029 0030 #include "git2.h" 0031 0032 namespace LibQGit2 0033 { 0034 class Repository; 0035 class OId; 0036 class Commit; 0037 class Tag; 0038 class Tree; 0039 class Blob; 0040 0041 /** 0042 * @brief Wrapper class for git_object. 0043 * 0044 * This is the base class for every repository object, i.e. blob, commit, 0045 * tag and tree. Every object is identified with it's LibQGit2::OId. 0046 * 0047 * @ingroup LibQGit2 0048 * @{ 0049 */ 0050 class LIBQGIT2_EXPORT Object 0051 { 0052 public: 0053 /** 0054 * @brief The type of an \c Object. 0055 */ 0056 enum Type { 0057 BadType, ///< Not a valid Object type 0058 CommitType, 0059 TreeType, 0060 BlobType, 0061 TagType 0062 }; 0063 0064 /** 0065 * Create an Object. 0066 * 0067 * Creates an Object that points to the given object. 0068 * The pointer to the underlaying git_object is managed by this 0069 * Object, and is automatically freed when no more referenced. 0070 */ 0071 explicit Object(git_object *object = 0); 0072 0073 /** 0074 * Copy constructor. 0075 */ 0076 Object(const Object& other); 0077 0078 /** 0079 * Destroy the object. 0080 */ 0081 ~Object(); 0082 0083 /** 0084 * Gets the type of this \c Object. 0085 */ 0086 Type type() const; 0087 0088 /** 0089 * Convert into a commit object. 0090 * 0091 * If the underlaying git_object is a commit this returns a valid 0092 * Commit object, otherwise it returns an empty one. 0093 */ 0094 Commit toCommit() const; 0095 0096 /** 0097 * Convert into a tag object. 0098 * 0099 * If the underlaying git_object is a tag this returns a valid 0100 * Tag object, otherwise it returns an empty one. 0101 */ 0102 Tag toTag() const; 0103 0104 /** 0105 * Convert into a tree object. 0106 * 0107 * If the underlaying git_object is a tree this returns a valid 0108 * Tag object, otherwise it returns an empty one. 0109 */ 0110 Tree toTree() const; 0111 0112 /** 0113 * Convert into a blob object. 0114 * 0115 * If the underlaying git_object is a blob this returns a valid 0116 * Tag object, otherwise it returns an empty one. 0117 */ 0118 Blob toBlob() const; 0119 0120 /** 0121 * Check if the pointer is null. 0122 * 0123 * Returns true if the git_object pointer owned by this 0124 * instance is null. 0125 */ 0126 bool isNull() const; 0127 0128 /** 0129 * Get the OId (SHA1) of a repository object. 0130 * 0131 * This returns the OId of the object. 0132 * Remember that in-memory objects created by git_object_new() 0133 * do not have a SHA1 id until they are written on a repository. 0134 * 0135 * @return the OId of the object 0136 */ 0137 OId oid() const; 0138 0139 /** 0140 * Check if this is a commit. 0141 * 0142 * Returns true if the object represents a commit; false otherwise. 0143 */ 0144 bool isCommit() const; 0145 0146 /** 0147 * Check if this is a tag. 0148 * 0149 * Returns true if the object represents a tag; false otherwise. 0150 */ 0151 bool isTag() const; 0152 0153 /** 0154 * Check if this is a tree. 0155 * 0156 * Returns true if the object represents a tree; false otherwise. 0157 */ 0158 bool isTree() const; 0159 0160 /** 0161 * Check if this is a blob. 0162 * 0163 * Returns true if the object represents a blob; false otherwise. 0164 */ 0165 bool isBlob() const; 0166 0167 /** 0168 * Get the object type as a string. 0169 */ 0170 QString typeString() const; 0171 0172 /** 0173 * Get the repository that owns this object. 0174 */ 0175 Repository owner() const; 0176 0177 git_object* data() const; 0178 const git_object* constData() const; 0179 0180 private: 0181 QSharedPointer<git_object> d; 0182 0183 static Type resolveType(git_otype); 0184 0185 friend class TreeEntry; 0186 }; 0187 0188 /** 0189 * Compares two Objects. Objects are equal when their oid are equal. 0190 */ 0191 bool operator ==(const Object &o1, const Object &o2); 0192 0193 /** 0194 * Compares two Objects. Objects are different when their oid are different. 0195 */ 0196 bool operator !=(const Object &o1, const Object &o2); 0197 0198 /**@}*/ 0199 } 0200 0201 #endif // LIBQGIT2_OBJECT_H