• 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
basicprimitivedatainformation.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 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 "basicprimitivedatainformation.h"
23 
24 #include "booldatainformation.h"
25 #include "chardatainformation.h"
26 #include "doubledatainformation.h"
27 #include "floatdatainformation.h"
28 #include "sintdatainformation.h"
29 #include "uintdatainformation.h"
30 #include "../topleveldatainformation.h"
31 #include "../../script/scripthandlerinfo.h"
32 #include "../../script/scriptlogger.h"
33 #include "../../script/classes/primitivescriptclass.h"
34 
35 #include <QScriptValue>
36 #include <QScriptEngine>
37 
38 #include <KLocalizedString>
39 
40 #include <abstractbytearraymodel.h>
41 
42 template<typename T, class C>
43 inline QScriptClass* BasicPrimitiveDataInformation<T, C>::scriptClass(ScriptHandlerInfo* handlerInfo) const
44 {
45  return handlerInfo->mPrimitiveClass.data();
46 }
47 
48 template<typename T, typename C>
49 QScriptValue BasicPrimitiveDataInformation<T, C>::valueAsQScriptValue() const
50 {
51  return C::asScriptValue(mValue, 0, 0);
52 }
53 
54 template<typename T, typename C>
55 bool BasicPrimitiveDataInformation<T, C>::setData(const QVariant& value,
56  Okteta::AbstractByteArrayModel* out, Okteta::Address address, BitCount64 bitsRemaining,
57  quint8 bitOffset)
58 {
59  T oldVal(this->mValue);
60  bool ok;
61  T valToWrite = C::fromVariant(value, &ok);
62  if (!ok)
63  {
64  logError() << "Failed to convert" << value << "to" << C::staticType();
65  return false;
66  }
67  AllPrimitiveTypes newVal(oldVal);
68  //this handles remaining < size() for us
69  bool wasAbleToWrite = newVal.writeBits(sizeof(T) * 8, valToWrite, out, effectiveByteOrder(), address,
70  bitsRemaining, &bitOffset);
71  return wasAbleToWrite;
72 }
73 
74 template<typename T, typename C>
75 qint64 BasicPrimitiveDataInformation<T, C>::readData(Okteta::AbstractByteArrayModel* input,
76  Okteta::Address address, BitCount64 bitsRemaining, quint8* bitOffset)
77 {
78  Q_ASSERT(mHasBeenUpdated); //update must have been called prior to reading except
79  const bool wasValid = mWasAbleToRead;
80  if (bitsRemaining < BitCount64(size()))
81  {
82  mWasAbleToRead = false;
83  mValue = 0;
84 
85  if (wasValid != mWasAbleToRead)
86  topLevelDataInformation()->setChildDataChanged();
87  return -1;
88  }
89  else
90  {
91  Q_ASSERT(BitCount64(input->size() - address) * 8 - *bitOffset >= bitsRemaining);
92  mWasAbleToRead = true;
93  const T oldVal = this->mValue;
94  //bit offset will always stay the same since type T uses a full number of bytes
95  mValue = AllPrimitiveTypes::readValue<T>(input, address, effectiveByteOrder(), *bitOffset);
96 
97  if (oldVal != mValue || wasValid != mWasAbleToRead)
98  topLevelDataInformation()->setChildDataChanged();
99  return size();
100  }
101 }
102 
103 //specify all the specializations so we can move code to the cpp file
104 template class BasicPrimitiveDataInformation<quint8, UIntDataInformationMethods<quint8> > ;
105 template class BasicPrimitiveDataInformation<quint16, UIntDataInformationMethods<quint16> > ;
106 template class BasicPrimitiveDataInformation<quint32, UIntDataInformationMethods<quint32> > ;
107 template class BasicPrimitiveDataInformation<quint64, UIntDataInformationMethods<quint64> > ;
108 template class BasicPrimitiveDataInformation<quint8, BoolDataInformationMethods<quint8> > ;
109 template class BasicPrimitiveDataInformation<quint16, BoolDataInformationMethods<quint16> > ;
110 template class BasicPrimitiveDataInformation<quint32, BoolDataInformationMethods<quint32> > ;
111 template class BasicPrimitiveDataInformation<quint64, BoolDataInformationMethods<quint64> > ;
112 template class BasicPrimitiveDataInformation<qint8, SIntDataInformationMethods<qint8> > ;
113 template class BasicPrimitiveDataInformation<qint16, SIntDataInformationMethods<qint16> > ;
114 template class BasicPrimitiveDataInformation<qint32, SIntDataInformationMethods<qint32> > ;
115 template class BasicPrimitiveDataInformation<qint64, SIntDataInformationMethods<qint64> > ;
116 template class BasicPrimitiveDataInformation<quint8, CharDataInformationMethods> ;
117 template class BasicPrimitiveDataInformation<float, FloatDataInformationMethods> ;
118 template class BasicPrimitiveDataInformation<double, DoubleDataInformationMethods> ;
booldatainformation.h
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
QScriptClass
BitCount64
quint64 BitCount64
Definition: datainformationbase.h:42
BasicPrimitiveDataInformation::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: basicprimitivedatainformation.cpp:75
Okteta::AbstractByteArrayModel::size
virtual Size size() const =0
sintdatainformation.h
doubledatainformation.h
floatdatainformation.h
uintdatainformation.h
ScriptHandlerInfo::mPrimitiveClass
QScopedPointer< PrimitiveScriptClass > mPrimitiveClass
Definition: scripthandlerinfo.h:51
BasicPrimitiveDataInformation::valueAsQScriptValue
virtual QScriptValue valueAsQScriptValue() const
Definition: basicprimitivedatainformation.cpp:49
ScriptHandlerInfo
Definition: scripthandlerinfo.h:39
AllPrimitiveTypes
This union holds the value of one primitive datatype.
Definition: allprimitivetypes.h:70
BasicPrimitiveDataInformation::setData
virtual bool setData(const QVariant &value, Okteta::AbstractByteArrayModel *out, Okteta::Address address, BitCount64 bitsRemaining, quint8 bitOffset)
Writes the current data contained in this object to out.
Definition: basicprimitivedatainformation.cpp:55
BasicPrimitiveDataInformation
A basic implementation for all primitive types.
Definition: basicprimitivedatainformation.h:33
basicprimitivedatainformation.h
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
chardatainformation.h
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