• 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
structuredatainformation.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 2009, 2010, 2012 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 #include "structuredatainformation.h"
23 
24 #include "topleveldatainformation.h"
25 
26 #include <KLocalizedString>
27 #include <limits>
28 
29 QString StructureDataInformation::typeNameImpl() const
30 {
31  return i18nc("data type in C/C++, then name", "struct %1", name());
32 }
33 
34 StructureDataInformation::~StructureDataInformation()
35 {
36 }
37 
38 StructureDataInformation::StructureDataInformation(const QString& name,
39  const QVector<DataInformation*>& children, DataInformation* parent)
40  : DataInformationWithChildren(name, children, parent)
41 {
42 }
43 
44 qint64 StructureDataInformation::readData(Okteta::AbstractByteArrayModel *input,
45  Okteta::Address address, BitCount64 bitsRemaining, quint8* bitOffset)
46 {
47  Q_ASSERT(mHasBeenUpdated); //update must have been called prior to reading
48  qint64 bitsRead = 0;
49  mWasAbleToRead = readChildren(mChildren, input, address, bitsRemaining, bitOffset, &bitsRead, topLevelDataInformation());
50  return bitsRead;
51 }
52 
53 BitCount64 StructureDataInformation::childPosition(const DataInformation* child, Okteta::Address start) const
54 {
55  BitCount64 offset = 0;
56  //sum size of elements up to index
57  for (int i = 0; i < mChildren.size(); ++i)
58  {
59  DataInformation* current = mChildren.at(i);
60  if (current == child)
61  break;
62  offset += current->size();
63  }
64 
65  if (mParent->isTopLevel())
66  return start * 8 + offset;
67  else
68  return mParent->asDataInformation()->childPosition(this, start) + offset;
69 }
70 
71 bool StructureDataInformation::readChildren(const QVector<DataInformation*> children,
72  Okteta::AbstractByteArrayModel* input, Okteta::Address address, BitCount64 bitsRemaining,
73  quint8* bitOffset, qint64* readBitsPtr, TopLevelDataInformation* top)
74 {
75  Q_CHECK_PTR(top);
76  Q_CHECK_PTR(readBitsPtr);
77  Q_ASSERT(*readBitsPtr >= 0); //otherwise we failed before
78  qint64 readBits = *readBitsPtr;
79  //prevent overflow
80  Q_ASSERT(sizeof(qint64) == sizeof(Okteta::Address) || readBits < (qint64(std::numeric_limits<qint32>::max()) * 8));
81  const quint8 origBitOffset = *bitOffset;
82  Okteta::Address readBytes = (readBits + origBitOffset) / 8;
83  for (int i = 0; i < children.size(); i++)
84  {
85  DataInformation* next = children.at(i);
86  top->scriptHandler()->updateDataInformation(next);
87  //next may be a dangling pointer now, reset it
88  DataInformation* newNext = children.at(i);
89  if (next != newNext)
90  {
91  //logInfo() << "Child at index " << i << " was replaced.";
92  top->setChildDataChanged();
93  }
94  qint64 currentReadBits = newNext->readData(input, address + readBytes,
95  bitsRemaining - readBits, bitOffset);
96  if (currentReadBits == -1)
97  {
98  *readBitsPtr = -1;
99  return false; //could not read one element -> whole structure could not be read
100  }
101  readBits += currentReadBits;
102  readBytes = (readBits + origBitOffset) / 8;
103  }
104  *readBitsPtr = readBits;
105  return true;
106 }
DataInformation
Interface that must be implemented by all datatypes.
Definition: datainformation.h:67
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
DataInformation::name
QString name() const
Definition: datainformation.h:258
DataInformation::topLevelDataInformation
TopLevelDataInformation * topLevelDataInformation() const
Definition: datainformation.cpp:240
BitCount64
quint64 BitCount64
Definition: datainformationbase.h:42
DataInformationWithChildren::mChildren
QVector< DataInformation * > mChildren
Definition: datainformationwithchildren.h:32
QVector< DataInformation * >
DataInformationWithChildren
Definition: datainformationwithchildren.h:29
DataInformation::mWasAbleToRead
bool mWasAbleToRead
Definition: datainformation.h:243
TopLevelDataInformation
Definition: topleveldatainformation.h:46
StructureDataInformation::readData
virtual qint64 readData(Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining, quint8 *bitOffset)
Reads the necessary data from input and returns the number of bytes read.
Definition: structuredatainformation.cpp:44
StructureDataInformation::childPosition
virtual BitCount64 childPosition(const DataInformation *child, Okteta::Address start) const
Definition: structuredatainformation.cpp:53
ScriptHandler::updateDataInformation
void updateDataInformation(DataInformation *data)
The pointer may be changed while updating, CHECK AS SOON AS FUNCTION RETURNS!
Definition: scripthandler.cpp:101
DataInformation::readData
virtual qint64 readData(Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining, quint8 *bitOffset)=0
Reads the necessary data from input and returns the number of bytes read.
DataInformation::mHasBeenUpdated
bool mHasBeenUpdated
Definition: datainformation.h:242
topleveldatainformation.h
DataInformationBase::isTopLevel
virtual bool isTopLevel() const =0
DataInformation::mParent
DataInformationBase * mParent
Definition: datainformation.h:238
StructureDataInformation::readChildren
static bool readChildren(const QVector< DataInformation * > children, Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining, quint8 *bitOffset, qint64 *readBitsPtr, TopLevelDataInformation *top)
Definition: structuredatainformation.cpp:71
DataInformationBase::asDataInformation
DataInformation * asDataInformation()
Definition: datainformationbase.h:107
StructureDataInformation::StructureDataInformation
StructureDataInformation(const QString &name, const QVector< DataInformation * > &children=QVector< DataInformation * >(), DataInformation *parent=0)
Definition: structuredatainformation.cpp:38
TopLevelDataInformation::scriptHandler
ScriptHandler * scriptHandler() const
Definition: topleveldatainformation.h:179
TopLevelDataInformation::setChildDataChanged
void setChildDataChanged()
Definition: topleveldatainformation.h:164
DataInformation::childPosition
virtual BitCount64 childPosition(const DataInformation *child, Okteta::Address start) const =0
StructureDataInformation::~StructureDataInformation
virtual ~StructureDataInformation()
Definition: structuredatainformation.cpp:34
DataInformation::size
virtual BitCount32 size() const =0
the size in bits of this element
structuredatainformation.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 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