Merge pull request #19 from nspaseski/master
[deliverable/titan.core.git] / compiler2 / ttcn3 / JsonAST.cc
CommitLineData
970ed795 1///////////////////////////////////////////////////////////////////////////////
3abe9331 2// Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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#include "JsonAST.hh"
9#include "../../common/memory.h"
10#include <cstddef>
11#include <cstdio>
12
3abe9331 13void JsonSchemaExtension::init(const char* p_key, const char* p_value)
14{
15 key = mcopystr(p_key);
16 value = mcopystr(p_value);
17}
18
19JsonSchemaExtension::~JsonSchemaExtension()
20{
21 Free(key);
22 Free(value);
23}
24
970ed795
EL
25void JsonAST::init_JsonAST()
26{
27 omit_as_null = false;
28 alias = NULL;
29 as_value = false;
30 default_value = NULL;
3abe9331 31 metainfo_unbound = false;
970ed795
EL
32}
33
34JsonAST::JsonAST(const JsonAST *other_val)
35{
36 init_JsonAST();
37 if (NULL != other_val) {
38 omit_as_null = other_val->omit_as_null;
39 alias = (NULL != other_val->alias) ? mcopystr(other_val->alias) : NULL;
40 as_value = other_val->as_value;
41 default_value = (NULL != other_val->default_value) ? mcopystr(other_val->default_value) : NULL;
3abe9331 42 for (size_t i = 0; i < other_val->schema_extensions.size(); ++i) {
43 schema_extensions.add(new JsonSchemaExtension(*other_val->schema_extensions[i]));
44 }
45 metainfo_unbound = other_val->metainfo_unbound;
970ed795
EL
46 }
47}
48
49JsonAST::~JsonAST()
50{
51 Free(alias);
52 Free(default_value);
3abe9331 53 for (size_t i = 0; i < schema_extensions.size(); ++i) {
54 delete schema_extensions[i];
55 }
56 schema_extensions.clear();
970ed795
EL
57}
58
59void JsonAST::print_JsonAST() const
60{
61 printf("\n\rOmit encoding: ");
62 if (omit_as_null) {
63 printf("as null value\n\r");
64 } else {
65 printf("skip field\n\r");
66 }
67 if (alias) {
68 printf("Name as %s\n\r", alias);
69 }
70 if (as_value) {
71 printf("Encoding unions as JSON value\n\r");
72 }
73 if (default_value) {
74 printf("Default value: %s\n\r", default_value);
75 }
3abe9331 76 if (0 != schema_extensions.size()) {
77 printf("Extensions:");
78 for (size_t i = 0; i < schema_extensions.size(); ++i) {
79 printf(" \"%s\" : \"%s\"", schema_extensions[i]->key, schema_extensions[i]->value);
80 }
81 }
82 if (metainfo_unbound) {
83 printf("Metainfo for unbound field(s)\n\r");
84 }
970ed795 85}
This page took 0.02899 seconds and 5 git commands to generate.