• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • services
  • filewatch
optimizedbytearray.h
Go to the documentation of this file.
1 /*
2  * This file is part of the KDE Nepomuk Project
3  * Copyright (C) 2012 Vishesh Handa <me@vhanda.in>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  */
20 
21 #ifndef OPTIMIZED_BYTE_ARRAY_H
22 #define OPTIMIZED_BYTE_ARRAY_H
23 
24 #include <QtCore/QHash>
25 #include <QtCore/QVector>
26 #include <QtCore/QByteArray>
27 #include <QDir>
28 #include <QSet>
29 #include <KDebug>
30 
44 class OptimizedByteArray {
45 public:
46  OptimizedByteArray() {}
47 
48  OptimizedByteArray(const QByteArray& array, QSet<QByteArray>& cache) {
49  QList<QByteArray> list = array.split( '/' );
50  QVector<QByteArray> vec;
51  vec.reserve( list.size() );
52  foreach( const QByteArray& ba, list ) {
53  if( !ba.isEmpty() )
54  vec << ba;
55  }
56 
57  m_data.reserve( vec.size() );
58  foreach(const QByteArray& arr, vec) {
59  QSet< QByteArray >::iterator it = cache.find( arr );
60  if( it != cache.end() )
61  m_data.append( *it );
62  else
63  m_data.append( *cache.insert( arr ) );
64  }
65  }
66 
67  QByteArray toByteArray() const {
68  int size = 0;
69  foreach(const QByteArray& arr, m_data)
70  size += arr.size() + 1;
71 
72  QByteArray array;
73  array.reserve( size );
74 
75  foreach(const QByteArray& arr, m_data) {
76  array.append( '/' );
77  array.append( arr );
78  }
79 
80  return array;
81  }
82 
83  bool operator==(const OptimizedByteArray& other) const {
84  return m_data == other.m_data;
85  }
86 
87 private:
88  QVector<QByteArray> m_data;
89 };
90 
91 uint qHash(const OptimizedByteArray& arr) {
92  return qHash(arr.toByteArray());
93 }
94 
95 Q_DECLARE_METATYPE(OptimizedByteArray)
96 Q_DECLARE_TYPEINFO(OptimizedByteArray, Q_MOVABLE_TYPE);
97 
98 #endif // OPTIMIZED_BYTE_ARRAY_H
OptimizedByteArray
This class holds a QByteArray which corresponds to a file url in a more memory efficient manner...
Definition: optimizedbytearray.h:44
qHash
uint qHash(const OptimizedByteArray &arr)
Definition: optimizedbytearray.h:91
Q_DECLARE_TYPEINFO
Q_DECLARE_TYPEINFO(OptimizedByteArray, Q_MOVABLE_TYPE)
OptimizedByteArray::toByteArray
QByteArray toByteArray() const
Definition: optimizedbytearray.h:67
OptimizedByteArray::OptimizedByteArray
OptimizedByteArray()
Definition: optimizedbytearray.h:46
OptimizedByteArray::operator==
bool operator==(const OptimizedByteArray &other) const
Definition: optimizedbytearray.h:83
OptimizedByteArray::OptimizedByteArray
OptimizedByteArray(const QByteArray &array, QSet< QByteArray > &cache)
Definition: optimizedbytearray.h:48
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal