libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::cbor::JsonStreamWriter Class Reference

#include <jsonstreamwriter.h>

Inheritance diagram for pappso::cbor::JsonStreamWriter:

Public Member Functions

 JsonStreamWriter (QIODevice *device)
 
virtual ~JsonStreamWriter ()
 
void startArray ()
 
void endArray ()
 
void startMap ()
 
void endMap ()
 
void writeCborMap (const QCborMap &cbor_map)
 
void writeCborArray (const QCborArray &cbor_array)
 
void appendKey (const QString &key)
 
void appendValue (const QString &value)
 
void writeArray (QStringList &str_list)
 

Protected Member Functions

void comma ()
 

Private Attributes

bool m_isStart = true
 
bool m_nextIsValue = false
 

Detailed Description

Todo
write docs

Definition at line 38 of file jsonstreamwriter.h.

Constructor & Destructor Documentation

◆ JsonStreamWriter()

pappso::cbor::JsonStreamWriter::JsonStreamWriter ( QIODevice * device)

Default constructor

Definition at line 34 of file jsonstreamwriter.cpp.

34 : QTextStream(device)
35{
36}

◆ ~JsonStreamWriter()

pappso::cbor::JsonStreamWriter::~JsonStreamWriter ( )
virtual

Destructor

Definition at line 38 of file jsonstreamwriter.cpp.

39{
40}

Member Function Documentation

◆ appendKey()

void pappso::cbor::JsonStreamWriter::appendKey ( const QString & key)

Definition at line 95 of file jsonstreamwriter.cpp.

96{
97 if(!m_isStart)
98 comma();
99 *this << "\"" << key << "\":";
100 m_isStart = false;
101 m_nextIsValue = true;
102}

References comma(), m_isStart, and m_nextIsValue.

◆ appendValue()

void pappso::cbor::JsonStreamWriter::appendValue ( const QString & value)

Definition at line 105 of file jsonstreamwriter.cpp.

106{
107 *this << "\"" << value << "\"";
108 m_nextIsValue = false;
109}

References m_nextIsValue.

◆ comma()

void pappso::cbor::JsonStreamWriter::comma ( )
protected

Definition at line 118 of file jsonstreamwriter.cpp.

119{
120 *this << "," << Qt::endl;
121 m_isStart = false;
122}

References m_isStart.

Referenced by appendKey(), startArray(), and startMap().

◆ endArray()

void pappso::cbor::JsonStreamWriter::endArray ( )

Definition at line 43 of file jsonstreamwriter.cpp.

44{
45 *this << "]" << Qt::endl;
46 m_isStart = false;
47 m_nextIsValue = false;
48}

References m_isStart, and m_nextIsValue.

◆ endMap()

void pappso::cbor::JsonStreamWriter::endMap ( )

Definition at line 51 of file jsonstreamwriter.cpp.

52{
53 *this << "}" << Qt::endl;
54 m_isStart = false;
55 m_nextIsValue = false;
56}

References m_isStart, and m_nextIsValue.

◆ startArray()

void pappso::cbor::JsonStreamWriter::startArray ( )

Definition at line 59 of file jsonstreamwriter.cpp.

60{
61 if(!m_nextIsValue)
62 comma();
63 *this << Qt::endl << "[";
64 m_isStart = true;
65}

References comma(), m_isStart, and m_nextIsValue.

◆ startMap()

void pappso::cbor::JsonStreamWriter::startMap ( )

Definition at line 67 of file jsonstreamwriter.cpp.

68{
69 if(!m_nextIsValue)
70 comma();
71 *this << Qt::endl << "{";
72 m_isStart = true;
73}

References comma(), m_isStart, and m_nextIsValue.

◆ writeArray()

void pappso::cbor::JsonStreamWriter::writeArray ( QStringList & str_list)

Definition at line 112 of file jsonstreamwriter.cpp.

113{
114 *this << "[\"" << str_list.join("\", \"") << "\"]" << Qt::endl;
115}

◆ writeCborArray()

void pappso::cbor::JsonStreamWriter::writeCborArray ( const QCborArray & cbor_array)

Definition at line 85 of file jsonstreamwriter.cpp.

86{
87 QJsonDocument doc;
88 doc.setArray(QCborValue(cbor_array).toJsonValue().toArray());
89
90 *this << doc.toJson();
91}

◆ writeCborMap()

void pappso::cbor::JsonStreamWriter::writeCborMap ( const QCborMap & cbor_map)

Definition at line 76 of file jsonstreamwriter.cpp.

77{
78 QJsonDocument doc;
79 doc.setObject(QCborValue(cbor_map).toJsonValue().toObject());
80
81 *this << doc.toJson();
82}

Member Data Documentation

◆ m_isStart

bool pappso::cbor::JsonStreamWriter::m_isStart = true
private

Definition at line 67 of file jsonstreamwriter.h.

Referenced by appendKey(), comma(), endArray(), endMap(), startArray(), and startMap().

◆ m_nextIsValue

bool pappso::cbor::JsonStreamWriter::m_nextIsValue = false
private

Definition at line 68 of file jsonstreamwriter.h.

Referenced by appendKey(), appendValue(), endArray(), endMap(), startArray(), and startMap().


The documentation for this class was generated from the following files: