• 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
  • primitive
  • bitfield
abstractbitfielddatainformation.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 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 "abstractbitfielddatainformation.h"
23 
24 #include <KLocalizedString>
25 
26 #include "../../topleveldatainformation.h"
27 
28 #include "../../../script/classes/bitfieldscriptclass.h"
29 #include "../../../script/scripthandlerinfo.h"
30 
31 QString AbstractBitfieldDataInformation::sizeString() const
32 {
33  return i18np("%1 bit", "%1 bits", width());
34 }
35 
36 AllPrimitiveTypes AbstractBitfieldDataInformation::value() const
37 {
38  return mValue;
39 }
40 
41 void AbstractBitfieldDataInformation::setValue(AllPrimitiveTypes newVal)
42 {
43  Q_ASSERT((newVal.value<quint64>() & mask()) == newVal.value<quint64>());
44  mValue = newVal.value<quint64>() & mask();
45 }
46 
47 PrimitiveDataType AbstractBitfieldDataInformation::type() const
48 {
49  return Type_Bitfield;
50 }
51 
52 AbstractBitfieldDataInformation::AbstractBitfieldDataInformation(const QString& name, BitCount32 width,
53  DataInformation* parent)
54  : PrimitiveDataInformation(name, parent), mValue(0), mWidth(qMin(width, 64u))
55 {
56  Q_ASSERT(width <= 64);
57 }
58 
59 AbstractBitfieldDataInformation::~AbstractBitfieldDataInformation()
60 {
61 }
62 
63 AbstractBitfieldDataInformation::AbstractBitfieldDataInformation(const AbstractBitfieldDataInformation& d)
64  : PrimitiveDataInformation(d), mValue(d.mValue), mWidth(d.mWidth)
65 {
66 }
67 
68 qint64 AbstractBitfieldDataInformation::readData(Okteta::AbstractByteArrayModel *input,
69  Okteta::Address address, BitCount64 bitsRemaining, quint8* bitOffset)
70 {
71  Q_ASSERT(mHasBeenUpdated); //update must have been called prior to reading
72  if (bitsRemaining < BitCount64(width()))
73  {
74  mWasAbleToRead = false;
75  mValue = 0;
76  return -1;
77  }
78  bool wasValid = mWasAbleToRead;
79  AllPrimitiveTypes oldVal(mValue);
80  AllPrimitiveTypes newVal(mValue);
81 
82  mWasAbleToRead = newVal.readBits(size(), input, effectiveByteOrder(), address, bitsRemaining,
83  bitOffset);
84 
85  if (oldVal != newVal || wasValid != mWasAbleToRead)
86  {
87  topLevelDataInformation()->setChildDataChanged();
88  mValue = newVal;
89  }
90  return width();
91 }
92 
93 bool AbstractBitfieldDataInformation::setData(const QVariant& valueVariant,
94  Okteta::AbstractByteArrayModel *out, Okteta::Address address, BitCount64 bitsRemaining,
95  quint8 bitOffset)
96 {
97  AllPrimitiveTypes oldVal(mValue);
98  bool ok;
99  AllPrimitiveTypes valToWrite = valueVariant.toULongLong(&ok);
100  Q_ASSERT(ok);
101  if (!ok)
102  return false;
103  AllPrimitiveTypes newVal(oldVal);
104  //this handles remaining < size() for us
105  bool wasAbleToWrite = newVal.writeBits(width(), valToWrite, out, effectiveByteOrder(), address,
106  bitsRemaining, &bitOffset);
107  return wasAbleToWrite;
108 }
109 
110 AllPrimitiveTypes AbstractBitfieldDataInformation::fromVariant(const QVariant& variant, bool* ok) const
111 {
112  return AllPrimitiveTypes(variant.toULongLong(ok));
113 }
114 
115 QScriptClass* AbstractBitfieldDataInformation::scriptClass(ScriptHandlerInfo* handlerInfo) const
116 {
117  return handlerInfo->mBitfieldClass.data();
118 }
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::effectiveByteOrder
QSysInfo::Endian effectiveByteOrder() const
Definition: datainformation.h:389
AbstractBitfieldDataInformation::sizeString
virtual QString sizeString() const
needs to be virtual for bitfields
Definition: abstractbitfielddatainformation.cpp:31
AbstractBitfieldDataInformation::width
BitCount32 width() const
Definition: abstractbitfielddatainformation.h:86
DataInformation::topLevelDataInformation
TopLevelDataInformation * topLevelDataInformation() const
Definition: datainformation.cpp:240
QScriptClass
AllPrimitiveTypes::readBits
bool readBits(quint8 bitCount, const Okteta::AbstractByteArrayModel *input, QSysInfo::Endian byteOrder, Okteta::Address address, BitCount64 bitsRemaining, quint8 *const bitOffset)
Reads given number of bits from input and sets value of this union to the new value.
Definition: allprimitivetypes.cpp:79
AbstractBitfieldDataInformation::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: abstractbitfielddatainformation.cpp:68
BitCount64
quint64 BitCount64
Definition: datainformationbase.h:42
AbstractBitfieldDataInformation::fromVariant
virtual AllPrimitiveTypes fromVariant(const QVariant &variant, bool *ok) const
Definition: abstractbitfielddatainformation.cpp:110
BitCount32
quint32 BitCount32
Definition: datainformationbase.h:37
AbstractBitfieldDataInformation::value
virtual AllPrimitiveTypes value() const
Definition: abstractbitfielddatainformation.cpp:36
AbstractBitfieldDataInformation::~AbstractBitfieldDataInformation
virtual ~AbstractBitfieldDataInformation()
Definition: abstractbitfielddatainformation.cpp:59
PrimitiveDataType
Definition: primitivedatatype.h:54
DataInformation::mWasAbleToRead
bool mWasAbleToRead
Definition: datainformation.h:243
ScriptHandlerInfo::mBitfieldClass
QScopedPointer< BitfieldScriptClass > mBitfieldClass
Definition: scripthandlerinfo.h:55
DataInformation::mHasBeenUpdated
bool mHasBeenUpdated
Definition: datainformation.h:242
AbstractBitfieldDataInformation::size
virtual BitCount32 size() const
the size in bits of this element
Definition: abstractbitfielddatainformation.h:81
abstractbitfielddatainformation.h
Type_Bitfield
Definition: primitivedatatype.h:48
AbstractBitfieldDataInformation::AbstractBitfieldDataInformation
AbstractBitfieldDataInformation(const QString &name, BitCount32 width, DataInformation *parent=0)
Definition: abstractbitfielddatainformation.cpp:52
AllPrimitiveTypes::value
T value() const
ScriptHandlerInfo
Definition: scripthandlerinfo.h:39
TopLevelDataInformation::setChildDataChanged
void setChildDataChanged()
Definition: topleveldatainformation.h:164
AbstractBitfieldDataInformation::type
virtual PrimitiveDataType type() const
Definition: abstractbitfielddatainformation.cpp:47
AbstractBitfieldDataInformation::mask
quint64 mask() const
Definition: abstractbitfielddatainformation.h:67
AllPrimitiveTypes
This union holds the value of one primitive datatype.
Definition: allprimitivetypes.h:70
AbstractBitfieldDataInformation::mValue
AllPrimitiveTypes mValue
Definition: abstractbitfielddatainformation.h:55
AbstractBitfieldDataInformation::setData
bool setData(const QVariant &valueVariant, Okteta::AbstractByteArrayModel *out, Okteta::Address address, BitCount64 bitsRemaining, quint8 bitOffset)
Writes the current data contained in this object to out.
Definition: abstractbitfielddatainformation.cpp:93
AbstractBitfieldDataInformation
Definition: abstractbitfielddatainformation.h:28
PrimitiveDataInformation
A base class for all primitive data elements (e.g.
Definition: primitivedatainformation.h:34
AllPrimitiveTypes::writeBits
bool writeBits(quint8 bitCount, AllPrimitiveTypes newValue, Okteta::AbstractByteArrayModel *out, QSysInfo::Endian byteOrder, Okteta::Address address, BitCount64 bitsRemaining, quint8 *const bitOffset)
Writes given number of bits to out.
Definition: allprimitivetypes.cpp:38
AbstractBitfieldDataInformation::setValue
virtual void setValue(AllPrimitiveTypes newVal)
Definition: abstractbitfielddatainformation.cpp:41
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