WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZByteArray.cpp
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2013, 2014 Bob Dinitto
4  *
5  * Filename: ZByteArray.cpp
6  * Created on: 11/9/2014
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
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, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include "ZByteArray.h"
26 #include <QtQml>
27 
28 
29 namespace Zbl
30 {
31 
32 ZByteArray::ZByteArray(QObject *parent) :
33  QObject(parent), m_ba(new QByteArray())
34 {
35  qDebug("ZByteArray::ZByteArray");
36 
37 }
38 
39 ZByteArray::ZByteArray(const QByteArray& byteArray, QObject *parent) :
40  QObject(parent), m_ba(new QByteArray(byteArray))
41 {
42  qDebug("ZByteArray::ZByteArray");
43 
44  //m_ba.reset(new QByteArray(byteArray));
45 }
46 
47 ZByteArray::ZByteArray(ZqByteArrayPtr byteArray, QObject *parent) :
48  QObject(parent), m_ba(byteArray)
49 {
50  qDebug("ZByteArray::ZByteArray");
51 }
52 
53 
55 {
56  qmlRegisterType<ZByteArray>("org.zuble.qml", 1, 0, "ZByteArray");
57 }
58 
59 
61 {
63  ZBL_SLOT_END_RETURN(m_ba->size(), 0,
65 }
66 
68 {
70  ZBL_SLOT_END_RETURN(m_ba->isEmpty(), 0,
72 }
73 
74 int ZByteArray::at(int index) const
75 {
77  ZBL_SLOT_END_RETURN(m_ba->at(index), 0,
78  Z_FAC_JS, ZByteArray::at, at failed)
79 }
80 
82 {
84  m_ba.clear();
86  ZByteArray::clear, clear failed)
87 }
88 
89 QString ZByteArray::toHexString() const
90 {
91  QString hex;
93  #if 0
94  char buff[25];
95  const int size = m_ba->size();
96  for(int i = 0; i < size; i++)
97  {
98  snprintf(buff, sizeof(buff), "%x", static_cast<int>(m_ba.at(i)));
99  if(i)
100  hex += ' ';
101 
102  hex += buff;
103  }
104 #endif
105  ZBL_SLOT_END_RETURN(m_ba->toHex(), QString("conversion failed"),
107 }
108 
109 
110 void ZByteArray::jAppend(QList<int> data)
111 {
113  const int size = data.size();
114  for(int i = 0; i < size; i++)
115  m_ba->append(static_cast<char>(data.at(i)));
117 }
118 
119 void ZByteArray::stringAppend(const QString& text)
120 {
122  m_ba->append(text);
124 }
125 
126 
128 {
129  QList<int> array;
131  const int size = m_ba->size();
132  for(int i = 0; i < size; i++)
133  array.append(m_ba->at(i));
134  ZBL_SLOT_END_RETURN(array, QList<int>(),
136 }
137 
139 {
140  QString string(*m_ba.data());
141 
142  return string;
143 }
144 
145 
146 } // Zbl
static void registerType()
Registers ZByteArray as a QML type.
Definition: ZByteArray.cpp:54
int getSize() const
Definition: ZByteArray.cpp:60
#define Z_FAC_JS
Definition: zglobal.h:123
Q_INVOKABLE QString toHexString() const
Definition: ZByteArray.cpp:89
Q_INVOKABLE int at(int index) const
Definition: ZByteArray.cpp:74
Definition: ZAndGate.cpp:6
Q_INVOKABLE void stringAppend(const QString &text)
Definition: ZByteArray.cpp:119
#define ZBL_SLOT_BEGIN_TRY
Definition: zglobal.h:128
#define ZBL_SLOT_END_VOID(facility, code, error_message)
Definition: zglobal.h:134
ZByteArray(QObject *parent=0)
Definition: ZByteArray.cpp:32
Q_INVOKABLE QString getString()
Definition: ZByteArray.cpp:138
QSharedPointer< QByteArray > ZqByteArrayPtr
Definition: zglobal.h:166
Q_INVOKABLE void jAppend(QList< int > data)
Definition: ZByteArray.cpp:110
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)
Definition: zglobal.h:141
ZqByteArrayPtr m_ba
Definition: ZByteArray.h:103
Q_INVOKABLE void clear()
Definition: ZByteArray.cpp:81
Q_INVOKABLE QList< int > toArray()
Definition: ZByteArray.cpp:127