21 #ifndef CONTAINERACCESSOR_H
22 #define CONTAINERACCESSOR_H
24 #include <QtCore/QVariant>
35 template<
typename Container_>
52 template<
typename Container>
58 static typename Container::key_type
get(
const typename Container::const_iterator it ) {
71 template<
typename Container>
77 static typename Container::mapped_type
get(
const typename Container::const_iterator it ) {
83 template<
typename T,
typename U>
84 struct KeyGetter<std::map<T, U> > :
public Getter<std::map<T, U> >
86 static T
get(
typename std::map<T, U>::const_iterator it ) {
91 template<
typename T,
typename U>
92 struct MappedValueGetter<std::map<T, U> > :
public Getter<std::map<T, U> >
94 static U
get(
typename std::map<T, U>::const_iterator it ) {
99 template<
typename Container>
100 struct ValueGetter :
public Getter<Container>
102 static typename Container::value_type
get(
const typename Container::const_iterator it ) {
107 template<
typename Container,
typename T =
typename Container::key_type>
110 static typename Container::const_iterator find(
const Container &container,
const QString &nextPart )
114 static const QString s = QString::number( T() );
118 QVariant v = nextPart;
119 if ( !v.convert( QVariant::Double ) )
120 return container.end();
121 typename Container::key_type key = v.value<
typename Container::key_type>();
122 return container.find( key );
126 template<
typename Container>
127 struct Finder<Container, QString>
129 static typename Container::const_iterator find(
const Container &container,
const QString &nextPart )
131 return container.find( nextPart );
138 template<
typename Getter>
139 QVariantList getList(
const QVariant &obj )
142 typename Getter::Container::const_iterator it = c.begin();
143 const typename Getter::Container::const_iterator end = c.end();
145 #if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
146 list.reserve( static_cast<int>( std::distance( it, end ) ) );
148 for ( ; it != end; ++it ) {
149 list << QVariant::fromValue( Getter::get( it ) );
154 template<
typename Container>
155 struct SequentialContainerAccessor
157 static QVariantList doToList(
const QVariant &obj )
159 return getList<ValueGetter<Container> >( obj );
164 struct SequentialContainerAccessor<QVariantList>
166 static QVariantList doToList(
const QVariant &obj )
172 template<
typename Container>
173 struct AssociativeContainerAccessor
175 static QVariantList doToList(
const QVariant &obj )
177 return getList<KeyGetter<Container> >( obj );