Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Baranyi, Botond | |
11 | * | |
12 | ******************************************************************************/ | |
970ed795 EL |
13 | #include "JsonAST.hh" |
14 | #include "../../common/memory.h" | |
15 | #include <cstddef> | |
16 | #include <cstdio> | |
17 | ||
3abe9331 | 18 | void JsonSchemaExtension::init(const char* p_key, const char* p_value) |
19 | { | |
20 | key = mcopystr(p_key); | |
21 | value = mcopystr(p_value); | |
22 | } | |
23 | ||
24 | JsonSchemaExtension::~JsonSchemaExtension() | |
25 | { | |
26 | Free(key); | |
27 | Free(value); | |
28 | } | |
29 | ||
970ed795 EL |
30 | void JsonAST::init_JsonAST() |
31 | { | |
32 | omit_as_null = false; | |
33 | alias = NULL; | |
34 | as_value = false; | |
35 | default_value = NULL; | |
3abe9331 | 36 | metainfo_unbound = false; |
970ed795 EL |
37 | } |
38 | ||
39 | JsonAST::JsonAST(const JsonAST *other_val) | |
40 | { | |
41 | init_JsonAST(); | |
42 | if (NULL != other_val) { | |
43 | omit_as_null = other_val->omit_as_null; | |
44 | alias = (NULL != other_val->alias) ? mcopystr(other_val->alias) : NULL; | |
45 | as_value = other_val->as_value; | |
46 | default_value = (NULL != other_val->default_value) ? mcopystr(other_val->default_value) : NULL; | |
3abe9331 | 47 | for (size_t i = 0; i < other_val->schema_extensions.size(); ++i) { |
48 | schema_extensions.add(new JsonSchemaExtension(*other_val->schema_extensions[i])); | |
49 | } | |
50 | metainfo_unbound = other_val->metainfo_unbound; | |
970ed795 EL |
51 | } |
52 | } | |
53 | ||
54 | JsonAST::~JsonAST() | |
55 | { | |
56 | Free(alias); | |
57 | Free(default_value); | |
3abe9331 | 58 | for (size_t i = 0; i < schema_extensions.size(); ++i) { |
59 | delete schema_extensions[i]; | |
60 | } | |
61 | schema_extensions.clear(); | |
970ed795 EL |
62 | } |
63 | ||
64 | void JsonAST::print_JsonAST() const | |
65 | { | |
66 | printf("\n\rOmit encoding: "); | |
67 | if (omit_as_null) { | |
68 | printf("as null value\n\r"); | |
69 | } else { | |
70 | printf("skip field\n\r"); | |
71 | } | |
72 | if (alias) { | |
73 | printf("Name as %s\n\r", alias); | |
74 | } | |
75 | if (as_value) { | |
76 | printf("Encoding unions as JSON value\n\r"); | |
77 | } | |
78 | if (default_value) { | |
79 | printf("Default value: %s\n\r", default_value); | |
80 | } | |
3abe9331 | 81 | if (0 != schema_extensions.size()) { |
82 | printf("Extensions:"); | |
83 | for (size_t i = 0; i < schema_extensions.size(); ++i) { | |
84 | printf(" \"%s\" : \"%s\"", schema_extensions[i]->key, schema_extensions[i]->value); | |
85 | } | |
86 | } | |
87 | if (metainfo_unbound) { | |
88 | printf("Metainfo for unbound field(s)\n\r"); | |
89 | } | |
970ed795 | 90 | } |