File indexing completed on 2024-06-30 05:51:25
0001 /* 0002 This file is part of the Okteta Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2012 Alessandro Di Federico <ale@clearmind.me> 0005 SPDX-FileCopyrightText: 2012 Alex Richardson <alex.richardosn@gmx.de> 0006 0007 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0008 */ 0009 0010 #ifndef KASTEN_POINTERDATAINFORMATION_HPP 0011 #define KASTEN_POINTERDATAINFORMATION_HPP 0012 0013 #include "primitivedatainformation.hpp" 0014 // Std 0015 #include <memory> 0016 0017 class PointerDataInformation : public PrimitiveDataInformationWrapper 0018 { 0019 DATAINFORMATION_CLONE_DECL(PointerDataInformation, PrimitiveDataInformationWrapper); 0020 0021 public: 0022 /** creates a new pointer 0023 * takes ownership over @p childType and @p valueType 0024 */ 0025 PointerDataInformation(const QString& name, DataInformation* childType, 0026 PrimitiveDataInformation* valueType, DataInformation* parent, 0027 qint64 pointerScale, const QScriptValue& interpretFunction); 0028 ~PointerDataInformation() override; 0029 0030 uint childCount() const override; 0031 DataInformation* childAt(uint index) const override; 0032 bool isPointer() const override; 0033 BitCount64 childPosition(const DataInformation* child, Okteta::Address start) const override; 0034 int indexOf(const DataInformation* const data) const override; 0035 qint64 readData(const Okteta::AbstractByteArrayModel* input, Okteta::Address address, 0036 BitCount64 bitsRemaining, quint8* bitOffset) override; 0037 /** Called once the whole structure has been read. Now we can evaluate what we are pointing at. 0038 * @param input the input 0039 * @param address the address of the root structure start */ 0040 void delayedReadData(const Okteta::AbstractByteArrayModel* input, Okteta::Address address); 0041 0042 DataInformation* pointerTarget() const; 0043 /** Set a new pointer target 0044 * @param target the new target (ownership is taken) 0045 */ 0046 void setPointerTarget(DataInformation* target); 0047 0048 PrimitiveDataInformation* pointerType() const; 0049 /** Set a new pointer target 0050 * @param type the new pointer type (ownership is taken if return value is true) 0051 * @return true if type was set, false if not 0052 */ 0053 bool setPointerType(DataInformation* type); 0054 0055 qint64 pointerScale() const; 0056 /** Set a new pointer scale 0057 * @param scale the new pointer scale, in bytes. 0058 */ 0059 void setPointerScale(qint64 scale); 0060 0061 QScriptValue interpreterFunction() const; 0062 void setInterpreterFunction(const QScriptValue& newFunc); 0063 0064 quint64 interpret(Okteta::Address start) const; 0065 0066 private: 0067 QScriptClass* scriptClass(ScriptHandlerInfo* handlerInfo) const override; 0068 QString valueStringImpl() const override; 0069 QString typeNameImpl() const override; 0070 0071 protected: 0072 std::unique_ptr<DataInformation> mPointerTarget; 0073 qint64 mPointerScale; 0074 }; 0075 0076 inline DataInformation* PointerDataInformation::pointerTarget() const 0077 { 0078 return mPointerTarget.get(); 0079 } 0080 0081 inline void PointerDataInformation::setPointerTarget(DataInformation* target) 0082 { 0083 Q_CHECK_PTR(target); 0084 mPointerTarget.reset(target); 0085 mPointerTarget->setParent(this); 0086 } 0087 0088 inline PrimitiveDataInformation* PointerDataInformation::pointerType() const 0089 { 0090 return mValue.get(); 0091 } 0092 0093 inline void PointerDataInformation::setPointerScale(qint64 scale) 0094 { 0095 mPointerScale = scale; 0096 } 0097 0098 inline qint64 PointerDataInformation::pointerScale() const 0099 { 0100 return mPointerScale; 0101 } 0102 0103 inline QScriptValue PointerDataInformation::interpreterFunction() const 0104 { 0105 return mAdditionalData.get(AdditionalData::AdditionalDataType::PointerInterpreterFunction).value<QScriptValue>(); 0106 } 0107 0108 inline void PointerDataInformation::setInterpreterFunction(const QScriptValue& newFunc) 0109 { 0110 setAdditionalFunction(AdditionalData::AdditionalDataType::PointerInterpreterFunction, newFunc, "pointer interpreter function"); 0111 } 0112 0113 #endif // KASTEN_POINTERDATAINFORMATION_HPP