• 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
asciistringdata.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 "asciistringdata.h"
25 #include "stringdatainformation.h"
26 #include "../topleveldatainformation.h"
27 
28 #include <abstractbytearraymodel.h>
29 
30 #include <KLocale>
31 #include <QVarLengthArray>
32 #include <KDebug> //TODO remove
33 
34 AsciiStringData::AsciiStringData(StringDataInformation* parent): StringData(parent)
35 {
36 }
37 
38 AsciiStringData::~AsciiStringData()
39 {
40 }
41 
42 qint64 AsciiStringData::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 
53  quint64 remaining = bitsRemaining;
54  Okteta::Address addr = address;
55  int count = 0;
56  mEofReached = false;
57  const int oldMax = mData.size();
58  if (((mMode & CharCount) && mLength.maxChars == 0) || ((mMode & ByteCount) && mLength.maxBytes == 0))
59  return 0; //nothing to read
60 
61  bool eofAtStart = false;
62  if (bitsRemaining < 8)
63  eofAtStart = true;
64 
65  while (true)
66  {
67  if (remaining < 8)
68  {
69  mEofReached = true;
70  break;
71  }
72  uchar val = input->byte(addr);
73  bool terminate = false;
74 
75  if (count < oldMax)
76  mData[count] = val;
77  else
78  mData.append(val);
79 
80  remaining -= 8;
81  addr++;
82  count++;
83 
84  //now check if we have to terminate
85  if (mMode & Sequence)
86  {
87  if ((quint32(val) & 0xff) == mTerminationCodePoint)
88  terminate = true;
89  }
90  if ((mMode & CharCount) || (mMode & ByteCount))
91  {
92  if ((unsigned)count >= mLength.maxChars)
93  terminate = true;
94  }
95  if (mMode == None) {
96  kDebug() << "no termination mode set!!";
97  Q_ASSERT(false);
98  }
99  if (terminate)
100  break;
101  }
102  mData.resize(count);
103  mParent->topLevelDataInformation()->_childCountAboutToChange(mParent, 0, count);
104  mParent->topLevelDataInformation()->_childCountChanged(mParent, 0, count);
105 
106  if (eofAtStart)
107  return -1;
108  return (addr - address) * 8;
109 }
110 
111 BitCount32 AsciiStringData::sizeAt(uint i) const
112 {
113  Q_ASSERT(i < count());
114  Q_UNUSED(i)
115  return 8;
116 }
117 
118 BitCount32 AsciiStringData::size() const
119 {
120  return mData.size() * 8;
121 }
122 
123 QString AsciiStringData::completeString(bool skipInvalid) const
124 {
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  if (val > ASCII_MAX)
130  {
131  if (skipInvalid) {
132  max--;
133  i--;
134  continue;
135  }
136  else
137  {
138  buf[i] = QChar::ReplacementCharacter;
139  }
140  }
141  else
142  {
143  buf[i] = QChar::fromLatin1(val);
144  }
145  }
146  return QString(buf.constData(), max);
147 }
148 
149 QString AsciiStringData::stringValue(int row) const
150 {
151  Q_ASSERT(row >= 0 && row < mData.size());
152  uchar val = mData.at(row);
153  if (val > ASCII_MAX)
154  return i18n("Non-ASCII char: 0x%1", val);
155  else
156  return QChar::fromLatin1(val);
157 }
158 
159 QString AsciiStringData::charType() const
160 {
161  return i18n("ASCII char");
162 }
163 
164 uint AsciiStringData::count() const
165 {
166  return mData.size();
167 }
168 
169 QString AsciiStringData::typeName() const
170 {
171  return i18n("ASCII string");
172 }
AsciiStringData::completeString
virtual QString completeString(bool skipInvalid=false) const
Definition: asciistringdata.cpp:123
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
AsciiStringData::charType
virtual QString charType() const
Definition: asciistringdata.cpp:159
AsciiStringData::typeName
virtual QString typeName() const
Definition: asciistringdata.cpp:169
DataInformation::topLevelDataInformation
TopLevelDataInformation * topLevelDataInformation() const
Definition: datainformation.cpp:240
TopLevelDataInformation::_childCountAboutToChange
void _childCountAboutToChange(DataInformation *sender, uint oldCount, uint newCount)
Definition: topleveldatainformation.h:184
AsciiStringData::size
virtual BitCount32 size() const
Definition: asciistringdata.cpp:118
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
AsciiStringData::sizeAt
virtual BitCount32 sizeAt(uint i) const
Definition: asciistringdata.cpp:111
BitCount32
quint32 BitCount32
Definition: datainformationbase.h:37
AsciiStringData::read
virtual qint64 read(Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining)
Definition: asciistringdata.cpp:42
AsciiStringData::stringValue
virtual QString stringValue(int row) const
Definition: asciistringdata.cpp:149
StringData::ASCII_MAX
static const char ASCII_MAX
Definition: stringdata.h:80
StringData::mTerminationCodePoint
quint32 mTerminationCodePoint
Definition: stringdata.h:87
AsciiStringData::~AsciiStringData
virtual ~AsciiStringData()
Definition: asciistringdata.cpp:38
StringData::Sequence
Definition: stringdata.h:43
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
StringData::mMode
uint mMode
Definition: stringdata.h:88
StringData::mParent
StringDataInformation * mParent
Definition: stringdata.h:82
asciistringdata.h
AsciiStringData::AsciiStringData
AsciiStringData(StringDataInformation *parent)
Definition: asciistringdata.cpp:34
StringData::None
Definition: stringdata.h:42
StringData::mEofReached
bool mEofReached
Definition: stringdata.h:90
AsciiStringData::count
virtual uint count() const
Definition: asciistringdata.cpp:164
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:06 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