File indexing completed on 2024-05-19 04:45:33
0001 /****************************************************************************** 0002 * This file is part of the libqgit2 library 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public 0015 * License along with this library; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0017 */ 0018 0019 #include "strarray.h" 0020 #include <QtCore/QByteArray> 0021 0022 namespace LibQGit2 { 0023 namespace internal { 0024 0025 static_assert(!std::is_copy_constructible<StrArray>::value, "StrArray must NOT be copy constructible"); 0026 static_assert(std::is_move_constructible<StrArray>::value, "StrArray must be move constructible"); 0027 static_assert(!std::is_copy_assignable<StrArray>::value, "StrArray must NOT be copy assignable"); 0028 static_assert(std::is_move_assignable<StrArray>::value, "StrArray must be move assignable"); 0029 0030 StrArray::StrArray(const QList<QByteArray> &list) : 0031 m_strings(list) 0032 { 0033 m_data.count = size_t(m_strings.size()); 0034 0035 if (m_data.count == 0) { 0036 return; 0037 } 0038 0039 m_data.strings = new char*[m_data.count]; 0040 for (size_t i = 0; i < m_data.count; ++i) { 0041 m_data.strings[i] = const_cast<char*>(m_strings.at(int(i)).data()); 0042 } 0043 } 0044 0045 StrArray::StrArray(StrArray &&other) : 0046 m_strings(std::move(other.m_strings)), 0047 m_data(other.m_data) 0048 { 0049 other.m_data = {nullptr, 0}; 0050 } 0051 0052 StrArray::~StrArray() 0053 { 0054 delete[] m_data.strings; 0055 } 0056 0057 StrArray &StrArray::operator=(StrArray &&rhs) 0058 { 0059 m_strings = std::move(rhs.m_strings); 0060 m_data = rhs.m_data; 0061 0062 rhs.m_data = {nullptr, 0}; 0063 0064 return *this; 0065 } 0066 0067 size_t StrArray::count() const 0068 { 0069 return m_data.count; 0070 } 0071 0072 const git_strarray& StrArray::data() const 0073 { 0074 return m_data; 0075 } 0076 0077 } 0078 }