File indexing completed on 2024-04-28 05:42:10
0001 0002 /*************************************************************************** 0003 * Copyright (C) 2006-2009 by Rajko Albrecht * 0004 * ral@alwins-world.de * 0005 * * 0006 * This program 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 program 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 program (in the file LGPL.txt); if not, * 0018 * write to the Free Software Foundation, Inc., 51 Franklin St, * 0019 * Fifth Floor, Boston, MA 02110-1301 USA * 0020 * * 0021 * This software consists of voluntary contributions made by many * 0022 * individuals. For exact contribution history, see the revision * 0023 * history and logs, available at https://commits.kde.org/kdesvn. * 0024 ***************************************************************************/ 0025 #ifndef SVNQT_HELPER_H 0026 #define SVNQT_HELPER_H 0027 0028 #include "pool.h" 0029 #include "revision.h" 0030 #include "svnqttypes.h" 0031 #include <svn_string.h> 0032 #include <svn_types.h> 0033 #include <svn_version.h> 0034 0035 #include <iostream> 0036 0037 #define SVN_VERSION_CHECK(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) 0038 #ifdef OVERRIDE_SVN_API_VERSION 0039 #define SVN_API_VERSION OVERRIDE_SVN_API_VERSION 0040 #else 0041 #define SVN_API_VERSION (SVN_VERSION_CHECK(SVN_VER_MAJOR, SVN_VER_MINOR, SVN_VER_PATCH)) 0042 #endif 0043 0044 namespace svn 0045 { 0046 namespace internal 0047 { 0048 class DepthToSvn 0049 { 0050 protected: 0051 svn_depth_t _value; 0052 0053 public: 0054 explicit DepthToSvn(const svn::Depth val) 0055 : _value(svn_depth_unknown) 0056 { 0057 switch (val) { 0058 case DepthUnknown: 0059 _value = svn_depth_unknown; 0060 break; 0061 case DepthExclude: 0062 _value = svn_depth_exclude; 0063 break; 0064 case DepthEmpty: 0065 _value = svn_depth_empty; 0066 break; 0067 case DepthFiles: 0068 _value = svn_depth_files; 0069 break; 0070 case DepthImmediates: 0071 _value = svn_depth_immediates; 0072 break; 0073 case DepthInfinity: 0074 _value = svn_depth_infinity; 0075 break; 0076 } 0077 } 0078 0079 operator svn_depth_t() const 0080 { 0081 return _value; 0082 } 0083 }; 0084 0085 class RevisionRangesToHash 0086 { 0087 protected: 0088 RevisionRanges m_ranges; 0089 0090 public: 0091 explicit RevisionRangesToHash(const RevisionRanges &_input) 0092 : m_ranges(_input) 0093 { 0094 } 0095 0096 apr_array_header_t *array(const Pool &pool) 0097 { 0098 apr_array_header_t *ranges = apr_array_make(pool, m_ranges.size(), sizeof(svn_opt_revision_range_t *)); 0099 svn_opt_revision_range_t *range; 0100 0101 for (const RevisionRange &rr : qAsConst(m_ranges)) { 0102 range = (svn_opt_revision_range_t *)apr_palloc(pool, sizeof(*range)); 0103 range->start = *rr.first.revision(); 0104 range->end = *rr.second.revision(); 0105 APR_ARRAY_PUSH(ranges, svn_opt_revision_range_t *) = range; 0106 } 0107 return ranges; 0108 } 0109 }; 0110 0111 class Map2Hash 0112 { 0113 PropertiesMap _map; 0114 0115 public: 0116 explicit Map2Hash(const PropertiesMap &aMap) 0117 : _map(aMap) 0118 { 0119 } 0120 0121 apr_hash_t *hash(const Pool &pool) const 0122 { 0123 if (_map.count() == 0) { 0124 return nullptr; 0125 } 0126 apr_hash_t *hash = apr_hash_make(pool); 0127 for (auto it = _map.begin(); it != _map.end(); ++it) { 0128 const QByteArray s = it.value().toUtf8(); 0129 const QByteArray n = it.key().toUtf8(); 0130 const char *propval = apr_pstrndup(pool, s, s.size()); 0131 const char *propname = apr_pstrndup(pool, n, n.size()); 0132 apr_hash_set(hash, propname, APR_HASH_KEY_STRING, propval); 0133 } 0134 return hash; 0135 } 0136 }; 0137 0138 class Hash2Map 0139 { 0140 PropertiesMap _map; 0141 0142 public: 0143 Hash2Map(apr_hash_t *hash, apr_pool_t *pool) 0144 : _map() 0145 { 0146 if (hash != nullptr) { 0147 apr_hash_index_t *hi; 0148 for (hi = apr_hash_first(pool, hash); hi; hi = apr_hash_next(hi)) { 0149 const void *key; 0150 void *val; 0151 0152 apr_hash_this(hi, &key, nullptr, &val); 0153 const char *_k = (const char *)key; 0154 const char *_v = ((const svn_string_t *)val)->data; 0155 0156 _map[QString::fromUtf8(_k)] = QString::fromUtf8(_v); 0157 } 0158 } 0159 } 0160 0161 operator const PropertiesMap &() const 0162 { 0163 return _map; 0164 } 0165 }; 0166 } 0167 } 0168 #endif