FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qvariant_utils.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "core.h"
19 #include <QtCore/QVariant>
20 
21 namespace qtcore {
22 
29 {
30 public:
31  template<typename T, template <typename> class CONTAINER>
32  static CONTAINER<T> toTypedContainer(const CONTAINER<QVariant>& variants);
33 
34  template<typename T, template <typename> class CONTAINER>
35  static CONTAINER<QVariant> toContainerOfVariants(const CONTAINER<T>& typeds);
36 };
37 
38 } // namespace qtcore
39 
40 // --
41 // -- Implementation
42 // --
43 
44 #include <algorithm>
45 #include <functional>
46 #include <iterator>
47 
48 namespace qtcore {
49 
58 template<typename T, template <typename> class CONTAINER>
59 CONTAINER<T> QVariantUtils::toTypedContainer(const CONTAINER<QVariant>& variants)
60 {
61  CONTAINER<T> typeds;
62  std::transform(variants.begin(), variants.end(),
63  std::back_inserter(typeds),
64  std::ptr_fun(&qVariantValue<T>));
65  return typeds;
66 }
67 
76 template<typename T, template <typename> class CONTAINER>
77 CONTAINER<QVariant> QVariantUtils::toContainerOfVariants(const CONTAINER<T>& typeds)
78 {
79  CONTAINER<QVariant> variants;
80  std::transform(typeds.begin(), typeds.end(),
81  std::back_inserter(variants),
82  std::ptr_fun(&QVariant::fromValue<T>));
83  return variants;
84 }
85 
86 } // namespace qtcore
Provides a collection of tools around QVariant.
Definition: qvariant_utils.h:28
#define QTTOOLS_CORE_EXPORT
Definition: core.h:27
Definition: grid_numbering.cpp:19
static CONTAINER< T > toTypedContainer(const CONTAINER< QVariant > &variants)
Converts a container of QVariant to a container of typed data (T)
Definition: qvariant_utils.h:59
static CONTAINER< QVariant > toContainerOfVariants(const CONTAINER< T > &typeds)
Converts a container of typed data (T) to a container of QVariant.
Definition: qvariant_utils.h:77