HaikuDepot: notify work status from main window
[haiku.git] / src / kits / shared / JsonWriter.cpp
blobeea12b6282c21c172615837b3df841a029d703b2
1 /*
2 * Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>
3 * Distributed under the terms of the MIT License.
4 */
7 #include "JsonWriter.h"
9 #include <stdio.h>
10 #include <stdlib.h>
12 #include <UnicodeChar.h>
15 BJsonWriter::BJsonWriter()
17 fErrorStatus(B_OK)
22 BJsonWriter::~BJsonWriter()
27 void
28 BJsonWriter::HandleError(status_t status, int32 line,
29 const char* message)
31 if(fErrorStatus == B_OK) {
32 if (message == NULL)
33 message = "?";
34 fErrorStatus = status;
35 fprintf(stderr, "! json err @line %" B_PRIi32 " - %s : %s\n", line,
36 strerror(status), message);
41 status_t
42 BJsonWriter::ErrorStatus()
44 return fErrorStatus;
48 status_t
49 BJsonWriter::WriteBoolean(bool value)
51 if (value)
52 return WriteTrue();
54 return WriteFalse();
58 status_t
59 BJsonWriter::WriteTrue()
61 Handle(BJsonEvent(B_JSON_TRUE));
62 return fErrorStatus;
66 status_t
67 BJsonWriter::WriteFalse()
69 Handle(BJsonEvent(B_JSON_FALSE));
70 return fErrorStatus;
74 status_t
75 BJsonWriter::WriteNull()
77 Handle(BJsonEvent(B_JSON_NULL));
78 return fErrorStatus;
82 status_t
83 BJsonWriter::WriteInteger(int64 value)
85 Handle(BJsonEvent(value));
86 return fErrorStatus;
90 status_t
91 BJsonWriter::WriteDouble(double value)
93 Handle(BJsonEvent(value));
94 return fErrorStatus;
98 status_t
99 BJsonWriter::WriteString(const char* value)
101 Handle(BJsonEvent(value));
102 return fErrorStatus;
106 status_t
107 BJsonWriter::WriteObjectStart()
109 Handle(BJsonEvent(B_JSON_OBJECT_START));
110 return fErrorStatus;
114 status_t
115 BJsonWriter::WriteObjectName(const char* value)
117 Handle(BJsonEvent(B_JSON_OBJECT_NAME, value));
118 return fErrorStatus;
122 status_t
123 BJsonWriter::WriteObjectEnd()
125 Handle(BJsonEvent(B_JSON_OBJECT_END));
126 return fErrorStatus;
130 status_t
131 BJsonWriter::WriteArrayStart()
133 Handle(BJsonEvent(B_JSON_ARRAY_START));
134 return fErrorStatus;
138 status_t
139 BJsonWriter::WriteArrayEnd()
141 Handle(BJsonEvent(B_JSON_ARRAY_END));
142 return fErrorStatus;