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

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • structures
  • datatypes
  • strings
latin1stringdata.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Okteta Kasten Framework, made within the KDE community.
3  *
4  * Copyright 2011 Alex Richardson <alex.richardson@gmx.de>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) version 3, or any
10  * later version accepted by the membership of KDE e.V. (or its
11  * successor approved by the membership of KDE e.V.), which shall
12  * act as a proxy defined in Section 6 of version 3 of the license.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 
24 #include "latin1stringdata.h"
25 #include "../topleveldatainformation.h"
26 #include "stringdatainformation.h"
27 
28 #include <abstractbytearraymodel.h>
29 
30 #include <KLocale>
31 #include <QVarLengthArray>
32 #include <KDebug> //TODO remove
33 
34 Latin1StringData::Latin1StringData(StringDataInformation* parent): StringData(parent)
35 {
36 }
37 
38 Latin1StringData::~Latin1StringData()
39 {
40 }
41 
42 qint64 Latin1StringData::read(Okteta::AbstractByteArrayModel* input, Okteta::Address address, BitCount64 bitsRemaining)
43 {
44  const int oldSize = count();
45  if (mMode == CharCount || mMode == ByteCount) //same for ascii
46  {
47  mData.reserve(mLength.maxChars);
48  }
49  mParent->topLevelDataInformation()->_childCountAboutToChange(mParent, oldSize, 0);
50  mParent->topLevelDataInformation()->_childCountChanged(mParent, oldSize, 0);
51 
52  quint64 remaining = bitsRemaining;
53  Okteta::Address addr = address;
54  int count = 0;
55  mEofReached = false;
56  const int oldMax = mData.size();
57  if (((mMode & CharCount) && mLength.maxChars == 0) || ((mMode & ByteCount) && mLength.maxBytes == 0))
58  return 0; //nothing to read
59 
60  bool eofAtStart = false;
61  if (bitsRemaining < 8)
62  eofAtStart = true;
63 
64  while (true)
65  {
66  if (remaining < 8)
67  {
68  mEofReached = true;
69  break;
70  }
71  uchar val = input->byte(addr);
72  bool terminate = false;
73 
74  if (count < oldMax)
75  mData[count] = val;
76  else
77  mData.append(val);
78 
79  remaining -= 8;
80  addr++;
81  count++;
82 
83  //now check if we have to terminate
84  if (mMode & Sequence)
85  {
86  if ((quint32(val) & 0xff) == mTerminationCodePoint)
87  terminate = true;
88  }
89  if ((mMode & CharCount) || (mMode & ByteCount))
90  {
91  if ((unsigned)count >= mLength.maxChars)
92  terminate = true;
93  }
94  if (mMode == None) {
95  kDebug() << "no termination mode set!!";
96  Q_ASSERT(false);
97  }
98  if (terminate)
99  break;
100  }
101  mData.resize(count);
102  mParent->topLevelDataInformation()->_childCountAboutToChange(mParent, 0, count);
103  mParent->topLevelDataInformation()->_childCountChanged(mParent, 0, count);
104 
105  if (eofAtStart)
106  return -1;
107  return (addr - address) * 8;
108 }
109 
110 BitCount32 Latin1StringData::sizeAt(uint i) const
111 {
112  Q_ASSERT(i < count());
113  Q_UNUSED(i)
114  return 8;
115 }
116 
117 BitCount32 Latin1StringData::size() const
118 {
119  return mData.size() * 8;
120 }
121 
122 QString Latin1StringData::completeString(bool skipInvalid) const
123 {
124  Q_UNUSED(skipInvalid) // all are valid
125  int max = mData.size();
126  QVarLengthArray<QChar> buf(max);
127  for (int i = 0; i < max; ++i) {
128  uchar val = mData.at(i);
129  buf[i] = QChar::fromLatin1(val);
130  }
131  return QString(buf.constData(), max);
132 }
133 
134 QString Latin1StringData::stringValue(int row) const
135 {
136  Q_ASSERT(row >= 0 && row < mData.size());
137  uchar val = mData.at(row);
138  return QChar::fromLatin1(val);
139 }
140 
141 QString Latin1StringData::charType() const
142 {
143  return i18n("Latin1 char");
144 }
145 
146 uint Latin1StringData::count() const
147 {
148  return mData.size();
149 }
150 
151 QString Latin1StringData::typeName() const
152 {
153  return i18n("Latin1 string");
154 }
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
abstractbytearraymodel.h
StringData
Definition: stringdata.h:36
DataInformation::topLevelDataInformation
TopLevelDataInformation * topLevelDataInformation() const
Definition: datainformation.cpp:240
TopLevelDataInformation::_childCountAboutToChange
void _childCountAboutToChange(DataInformation *sender, uint oldCount, uint newCount)
Definition: topleveldatainformation.h:184
BitCount64
quint64 BitCount64
Definition: datainformationbase.h:42
TopLevelDataInformation::_childCountChanged
void _childCountChanged(DataInformation *sender, uint oldCount, uint newCount)
Definition: topleveldatainformation.h:192
StringData::ByteCount
Definition: stringdata.h:45
stringdatainformation.h
Latin1StringData::Latin1StringData
Latin1StringData(StringDataInformation *parent)
Definition: latin1stringdata.cpp:34
Latin1StringData::~Latin1StringData
virtual ~Latin1StringData()
Definition: latin1stringdata.cpp:38
Latin1StringData::stringValue
virtual QString stringValue(int row) const
Definition: latin1stringdata.cpp:134
BitCount32
quint32 BitCount32
Definition: datainformationbase.h:37
Latin1StringData::count
virtual uint count() const
Definition: latin1stringdata.cpp:146
StringData::mTerminationCodePoint
quint32 mTerminationCodePoint
Definition: stringdata.h:87
Latin1StringData::read
virtual qint64 read(Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining)
Definition: latin1stringdata.cpp:42
Latin1StringData::size
virtual BitCount32 size() const
Definition: latin1stringdata.cpp:117
StringData::Sequence
Definition: stringdata.h:43
latin1stringdata.h
Okteta::AbstractByteArrayModel::byte
virtual Byte byte(Address offset) const =0
locates working range The idea behind is to tell buffer which range will be requested in the followin...
StringData::mLength
union StringData::@5 mLength
Latin1StringData::typeName
virtual QString typeName() const
Definition: latin1stringdata.cpp:151
StringData::mMode
uint mMode
Definition: stringdata.h:88
Latin1StringData::charType
virtual QString charType() const
Definition: latin1stringdata.cpp:141
StringData::mParent
StringDataInformation * mParent
Definition: stringdata.h:82
StringData::None
Definition: stringdata.h:42
Latin1StringData::completeString
virtual QString completeString(bool skipInvalid=false) const
Definition: latin1stringdata.cpp:122
Latin1StringData::sizeAt
virtual BitCount32 sizeAt(uint i) const
Definition: latin1stringdata.cpp:110
StringData::mEofReached
bool mEofReached
Definition: stringdata.h:90
StringData::CharCount
Definition: stringdata.h:44
StringDataInformation
Definition: stringdatainformation.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

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