• 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
uniondatainformation.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 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 "uniondatainformation.h"
23 #include "topleveldatainformation.h"
24 
25 #include <KLocale>
26 
27 QString UnionDataInformation::typeNameImpl() const
28 {
29  return i18nc("data type in C/C++, then name", "union %1", name());
30 }
31 
32 BitCount32 UnionDataInformation::size() const
33 {
34  //since this is a union return size of biggest element
35  BitCount32 size = 0;
36  for (int i = 0; i < mChildren.size(); i++)
37  {
38  size = qMax(size, mChildren.at(i)->size());
39  }
40  return size;
41 }
42 
43 qint64 UnionDataInformation::readData(Okteta::AbstractByteArrayModel *input,
44  Okteta::Address address, BitCount64 bitsRemaining, quint8* bitOffset)
45 {
46  Q_ASSERT(mHasBeenUpdated); //update must have been called prior to reading
47  TopLevelDataInformation* top = topLevelDataInformation();
48  Q_CHECK_PTR(top);
49 
50  qint64 readBits = 0;
51  const quint8 originalBitOffset = *bitOffset;
52  quint8 bitOffsetAfterUnion = originalBitOffset;
53  bool reachedEOF = false;
54  for (int i = 0; i < mChildren.size(); i++)
55  {
56  DataInformation* next = mChildren.at(i);
57  //first of all update the structure:
58  top->scriptHandler()->updateDataInformation(next);
59  DataInformation* newNext = mChildren.at(i);
60  if (next != newNext)
61  {
62  logInfo() << "Child at index " << i << " was replaced.";
63  top->setChildDataChanged();
64  }
65  //bit offset always has to be reset to original value
66  qint64 currentReadBits = newNext->readData(input, address, bitsRemaining, bitOffset);
67  if (currentReadBits == -1)
68  {
69  //since this is a union, try to read all values and not abort as soon as one is too large
70  reachedEOF = true;
71  }
72  else if (currentReadBits > readBits)
73  {
74  //this is the largest element, so the bit offset after the union is the one after this element
75  readBits = currentReadBits;
76  bitOffsetAfterUnion = *bitOffset;
77  }
78  *bitOffset = originalBitOffset; // start at beginning
79  }
80  *bitOffset = bitOffsetAfterUnion;
81  mWasAbleToRead = !reachedEOF;
82  return reachedEOF ? -1 : readBits;
83 }
84 
85 UnionDataInformation::~UnionDataInformation()
86 {
87 }
88 
89 UnionDataInformation::UnionDataInformation(const QString& name, const QVector<DataInformation*>& children,
90  DataInformation* parent)
91  : DataInformationWithChildren(name, children, parent)
92 {
93 }
94 
95 BitCount64 UnionDataInformation::childPosition(const DataInformation* child, Okteta::Address start) const
96 {
97  //all elements start at offset zero
98  Q_UNUSED(child)
99  if (mParent->isTopLevel())
100  return start * 8;
101  else
102  return mParent->asDataInformation()->childPosition(this, start);
103 }
104 
DataInformation
Interface that must be implemented by all datatypes.
Definition: datainformation.h:67
UnionDataInformation::UnionDataInformation
UnionDataInformation(const QString &name, const QVector< DataInformation * > &children=QVector< DataInformation * >(), DataInformation *parent=0)
Definition: uniondatainformation.cpp:89
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
UnionDataInformation::childPosition
virtual BitCount64 childPosition(const DataInformation *child, Okteta::Address start) const
Definition: uniondatainformation.cpp:95
DataInformationWithChildren::mChildren
QVector< DataInformation * > mChildren
Definition: datainformationwithchildren.h:32
QVector< DataInformation * >
BitCount32
quint32 BitCount32
Definition: datainformationbase.h:37
DataInformationWithChildren
Definition: datainformationwithchildren.h:29
DataInformation::mWasAbleToRead
bool mWasAbleToRead
Definition: datainformation.h:243
TopLevelDataInformation
Definition: topleveldatainformation.h:46
DataInformation::logInfo
QDebug logInfo() const
just a shorthand for logger->info(this)
Definition: datainformation.h:314
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
UnionDataInformation::~UnionDataInformation
virtual ~UnionDataInformation()
Definition: uniondatainformation.cpp:85
DataInformationBase::asDataInformation
DataInformation * asDataInformation()
Definition: datainformationbase.h:107
TopLevelDataInformation::scriptHandler
ScriptHandler * scriptHandler() const
Definition: topleveldatainformation.h:179
UnionDataInformation::size
virtual BitCount32 size() const
the size in bits of this element
Definition: uniondatainformation.cpp:32
TopLevelDataInformation::setChildDataChanged
void setChildDataChanged()
Definition: topleveldatainformation.h:164
DataInformation::childPosition
virtual BitCount64 childPosition(const DataInformation *child, Okteta::Address start) const =0
uniondatainformation.h
UnionDataInformation::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: uniondatainformation.cpp:43
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