/*========================================================================= Library: qCTK Copyright (c) Kitware Inc. All rights reserved. Distributed under a BSD License. See LICENSE.txt file. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ #include "ctkUtils.h" // STD includes #include //------------------------------------------------------------------------------ void ctkUtils::qListToSTLVector(const QStringList& list, std::vector& vector) { // Resize if required if (list.count() != static_cast(vector.size())) { vector.resize(list.count()); } for (int i = 0; i < list.count(); ++i) { // Allocate memory char* str = new char[list[i].size()+1]; strcpy(str, list[i].toLatin1()); vector[i] = str; } } //------------------------------------------------------------------------------ namespace { /// Convert QString to std::string static std::string qStringToSTLString(const QString& qstring) { return qstring.toStdString(); } } //------------------------------------------------------------------------------ void ctkUtils::qListToSTLVector(const QStringList& list, std::vector& vector) { // To avoid unnessesary relocations, let's reserve the required amount of space vector.reserve(list.size()); std::transform(list.begin(),list.end(),std::back_inserter(vector),&qStringToSTLString); } //------------------------------------------------------------------------------ void ctkUtils::stlVectorToQList(const std::vector& vector, QStringList& list) { std::transform(vector.begin(),vector.end(),std::back_inserter(list),&QString::fromStdString); }