// Version: $Id: b7b0c5453d4380db32f87c3aabed88f5b25e1d0a $ // // // Commentary: // // // Change Log: // // // Code: #pragma once // ///////////////////////////////////////////////////////////////// // dtkContainerVector implementation // ///////////////////////////////////////////////////////////////// template dtkContainerVector::dtkContainerVector(void) : dtkAbstractContainerOrdered() { }; template dtkContainerVector::dtkContainerVector(qlonglong size) : dtkAbstractContainerOrdered(), m_vector(size) { }; template dtkContainerVector::dtkContainerVector(qlonglong size, const T& value) : dtkAbstractContainerOrdered(), m_vector(size, value) { }; template dtkContainerVector::dtkContainerVector(const dtkContainerVector& other) : dtkAbstractContainerOrdered(other), m_vector(other.m_vector) { }; template dtkContainerVector::~dtkContainerVector(void) { }; template QString dtkContainerVector::identifier(void) const { return QString("dtkContainerVector<%1>").arg(typeid(T).name()); }; template QString dtkContainerVector::description(void) const { QString string; string = "[ " ; // for (qlonglong i = 0; i < m_vector.count(); ++i) // { // if (i > 0) // string.append("; "); // QString string2 = QString("%1").arg(m_vector.at(i)); // string += string2; // } string.append(" ]"); return string; }; template void dtkContainerVector::clear(void) { m_vector.clear(); }; template void dtkContainerVector::append(const T& value) { m_vector.append(value); }; template void dtkContainerVector::append(const dtkAbstractContainer& values) { qlonglong size; const T *array = values.toArray(size); for (qlonglong i = 0; i < size; ++i) m_vector.append(array[i]); }; template void dtkContainerVector::append(const dtkContainerVector& values) { m_vector << values.m_vector; }; template void dtkContainerVector::prepend(const T& value) { m_vector.prepend(value); }; template void dtkContainerVector::prepend(const dtkAbstractContainer& values) { qlonglong size; const T *array = values.toArray(size); for (qlonglong i = 0; i < size; ++i) m_vector.prepend(array[i]); }; template void dtkContainerVector::prepend(const dtkContainerVector& values) { for (qlonglong i = 0; i < values.count(); ++i) m_vector.prepend(values.at(i)); }; template void dtkContainerVector::remove(const T& value) { qlonglong index = m_vector.indexOf(value); qlonglong i; while (index >= 0) { m_vector.remove(index); i = index; index = m_vector.indexOf(value, i); } }; template void dtkContainerVector::remove(const dtkAbstractContainer& values) { qlonglong size; const T *array = values.toArray(size); for (qlonglong i = 0; i < size; ++i) { this->remove(array[i]); } }; template void dtkContainerVector::remove(const dtkContainerVector& values) { for (qlonglong i = 0; i < values.count(); ++i) this->remove(values.at(i)); }; template void dtkContainerVector::insert(qlonglong index, const T& value) { m_vector.insert(index, value); }; template void dtkContainerVector::insert(qlonglong from, const dtkAbstractContainer& values) { this->insert(from, 1, values); }; template void dtkContainerVector::insert(qlonglong from, qlonglong step, const dtkAbstractContainer& values) { m_vector.reserve(m_vector.count() + values.count()); qlonglong size; const T *array = values.toArray(size); for (qlonglong i = 0; i < size; ++i) { m_vector.insert(i * step + from, array[i]); } m_vector.squeeze(); }; template void dtkContainerVector::insert(qlonglong *indices, const dtkAbstractContainer& values) { qlonglong size; const T *array = values.toArray(size); for (qlonglong i = 0; i < size; ++i) { m_vector.insert(indices[i], array[i]); } }; template void dtkContainerVector::insert(qlonglong from, const dtkContainerVector& values) { this->insert(from, 1, values); }; template void dtkContainerVector::insert(qlonglong from, qlonglong step, const dtkContainerVector& values) { m_vector.reserve(m_vector.count() + values.count()); for (qlonglong i = 0; i < values.count(); ++i) { m_vector.insert(i * step + from, values.at(i)); } m_vector.squeeze(); }; template void dtkContainerVector::insert(qlonglong *indices, const dtkContainerVector& values) { for (qlonglong i = 0; i < values.count(); ++i) m_vector.insert(indices[i], values.at(i)); }; template void dtkContainerVector::replace(qlonglong index, const T& value) { m_vector.replace(index, value); }; template void dtkContainerVector::replace(qlonglong from, const dtkAbstractContainer& values) { this->replace(from, 1, values); }; template void dtkContainerVector::replace(qlonglong from, qlonglong step, const dtkAbstractContainer& values) { qlonglong size; const T *array = values.toArray(size); for (qlonglong i = 0; i < size; ++i) { m_vector.replace(i * step + from, array[i]); } }; template void dtkContainerVector::replace(qlonglong *indices, const dtkAbstractContainer& values) { qlonglong size; const T *array = values.toArray(size); for (qlonglong i = 0; i < size; ++i) { m_vector.replace(indices[i], array[i]); } }; template void dtkContainerVector::replace(qlonglong from, const dtkContainerVector& values) { this->replace(from, 1, values); }; template void dtkContainerVector::replace(qlonglong from, qlonglong step, const dtkContainerVector& values) { for (qlonglong i = 0; i < values.count(); ++i) m_vector.replace(i * step + from, values.at(i)); }; template void dtkContainerVector::replace(qlonglong *indices, const dtkContainerVector& values) { for (qlonglong i = 0; i < values.count(); ++i) m_vector.replace(indices[i], values.at(i)); }; template void dtkContainerVector::removeAt(qlonglong index) { m_vector.remove(index); }; template void dtkContainerVector::removeAt(qlonglong from, qlonglong to, qlonglong step) { if (step <= 0) return; qlonglong size = (to - from) / step; qlonglong index = from; while (size != 0) { this->removeAt(index); index += (step - 1); --size; } }; template void dtkContainerVector::reserve(qlonglong value) { m_vector.reserve(value); }; template void dtkContainerVector::resize(qlonglong size) { m_vector.resize(size); }; template void dtkContainerVector::squeeze(void) { m_vector.squeeze(); }; template bool dtkContainerVector::isEmpty(void) const { return m_vector.isEmpty(); }; template bool dtkContainerVector::contains(const T& value) const { return m_vector.contains(value); }; template bool dtkContainerVector::contains(const dtkAbstractContainer& values) const { bool result = true; qlonglong size; const T *array = values.toArray(size); qlonglong i = 0; while (result && (i < size)) { result = m_vector.contains(array[i++]); } return result; }; template bool dtkContainerVector::contains(const dtkContainerVector& values) const { bool result = true; qlonglong size = values.count(); qlonglong i = 0; while (result && (i < size)) { result = m_vector.contains(values.at(i++)); } return result; }; template qlonglong dtkContainerVector::capacity(void) const { return m_vector.capacity(); }; template qlonglong dtkContainerVector::count(void) const { return m_vector.count(); }; template qlonglong dtkContainerVector::indexOf(const T& value, qlonglong from) const { return m_vector.indexOf(value, from); }; template qlonglong dtkContainerVector::lastIndexOf(const T& value, qlonglong from) const { return m_vector.lastIndexOf(value, from); }; template qlonglong *dtkContainerVector::indicesOf(const T& value, qlonglong from) const { dtkContainerVector indices; qlonglong index = m_vector.indexOf(value, from); while (index > 0 ) { indices << index; from = index + 1; index = m_vector.indexOf(value, from); } return indices.array(); }; template const T& dtkContainerVector::at(qlonglong index) const { return m_vector.at(index); }; template const T& dtkContainerVector::first(void) const { return m_vector.first(); }; template const T& dtkContainerVector::last(void) const { return m_vector.last(); }; template dtkContainerVector *dtkContainerVector::subContainer(const dtkAbstractContainerOrdered& indices) const { dtkContainerVector *result = new dtkContainerVector(); result->reserve(indices.count()); for (qlonglong i = 0; i < indices.count(); ++i) result->append(m_vector.at(indices.at(i))); return result; }; template dtkContainerVector *dtkContainerVector::subContainer(qlonglong from, qlonglong to, qlonglong step) const { qlonglong size = (to - from) / step; dtkContainerVector *result = new dtkContainerVector(); result->reserve(size); qlonglong index = from; while (size != 0) { result->append(m_vector.at(index)); index += step; --size; } return result; }; template const T *dtkContainerVector::toArray(qlonglong& count) const { count = m_vector.count(); return m_vector.data(); }; template T *dtkContainerVector::toArray(qlonglong& count) { count = m_vector.count(); return m_vector.data(); }; template T *dtkContainerVector::array(void) { return m_vector.data(); }; template const T *dtkContainerVector::array(void) const { return m_vector.data(); }; template const T *dtkContainerVector::constArray(void) const { return m_vector.constRawData(); }; template const T& dtkContainerVector::operator [] (qlonglong index) const { return m_vector.at(index); }; template T& dtkContainerVector::operator [] (qlonglong index) { return m_vector[index]; }; template dtkContainerVector& dtkContainerVector::operator = (const dtkContainerVector& other) { m_vector = other.m_vector; return (*this); }; template dtkContainerVector *dtkContainerVector::clone(void) const { return new dtkContainerVector(*this); }; template dtkContainerVector& dtkContainerVector::operator << (const T& value) { m_vector << value; return (*this); }; template dtkContainerVector& dtkContainerVector::operator << (const dtkContainerVector& values) { m_vector << values.m_vector; return (*this); }; template bool dtkContainerVector::operator == (const dtkContainerVector& other) const { return (m_vector == other.m_vector); }; template bool dtkContainerVector::operator != (const dtkContainerVector& other) const { return (m_vector != other.m_vector); }; template bool dtkContainerVector::isEqual(const dtkAbstractContainer& other) const { if (this == &other) return true; if (m_vector.count() != other.count()) return false; if (this->type() == other.type()) { dtkAbstractContainerOrdered *other_o = const_cast *>(reinterpret_cast *>(&other)); bool is_equal = true; qlonglong count = 0; while (is_equal && (count < m_vector.count())) { is_equal = (m_vector.at(count) == (*other_o)[count]); count++; } return is_equal; } else { return false; } return false; }; template dtkContainerVector dtkContainerVector::operator + (const dtkContainerVector& other) { dtkContainerVector vec; vec.m_vector = m_vector; vec.m_vector += other.m_vector; return vec; }; template dtkContainerVector& dtkContainerVector::operator += (const dtkContainerVector& other) { m_vector += other.m_vector; return (*this); }; template dtkContainerVector& dtkContainerVector::operator += (const T& value) { m_vector += value; return (*this); }; template inline dtkContainerVector dtkContainerVectorFromQVector(const QVector& vector) { dtkContainerVector result; result.m_vector.setWritableRawData(const_cast&>(vector).data(), vector.size()); return result; }; template inline QVector dtkContainerVectorToQVector(const dtkContainerVector& vector) { QVector result(vector.count()); for (int i = 0; i < vector.count(); ++i) result[i] = vector.m_vector[i]; return result; }; template inline dtkContainerVector dtkContainerVectorFromDtkArray(const dtkArray& vector) { dtkArray result; result.m_vector = vector; return result; }; template inline dtkArray dtkContainerVectorToDtkArray(const dtkContainerVector& vector) { dtkArray result(vector.m_vector); return result; }; // // dtkContainerVector.tpp ends here