File: json.cc

package info (click to toggle)
survex 1.4.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,348 kB
  • sloc: ansic: 21,576; cpp: 18,167; sh: 5,942; javascript: 832; perl: 755; makefile: 614; python: 83; xml: 35
file content (87 lines) | stat: -rw-r--r-- 2,132 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* json.cc
 * Export from Aven as JSON.
 */
/* Copyright (C) 2015,2016,2022,2024 Olly Betts
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

#include <config.h>

#include "json.h"

#include "export.h"

#include <stdio.h>

using namespace std;

const int *
JSON::passes() const
{
    static const int default_passes[] = { LEGS|SURF, 0 };
    return default_passes;
}

void
JSON::header(const char * title, time_t datestamp_numeric,
	     double min_x, double min_y, double min_z,
	     double max_x, double max_y, double max_z)
{
    (void)title;
    (void)datestamp_numeric;
#if 0
    if (title) {
	fputs("title: \"", fh);
	json_escape(fh, title);
	fputs("\",\n", fh);
    }
    if (datestamp_numeric != time_t(-1)) {
	fprintf("date: %ld,\n", (long)datestamp_numeric);
    }
#endif
    fprintf(fh, "{\"bounds\":[%.2f,%.2f,%.2f,%.2f,%.2f,%.2f],\n\"traverses\":[\n",
	    min_x, min_z, min_y, max_x, max_z, max_y);
}

void
JSON::line(const img_point *p1, const img_point *p, unsigned /*flags*/, bool fPendingMove)
{
    if (fPendingMove) {
	if (in_segment) {
	    fputs("],\n[", fh);
	} else {
	    fputs("[", fh);
	    in_segment = true;
	}
	fprintf(fh, "[%.2f,%.2f,%.2f]", p1->x, p1->z, p1->y);
    }
    fprintf(fh, ",[%.2f,%.2f,%.2f]", p->x, p->z, p->y);
}

void
JSON::label(const img_point *p, const wxString&, int /*sflags*/, int type)
{
    (void)p;
    (void)type;
}

void
JSON::footer()
{
    if (in_segment)
	fputs("]\n", fh);
    fputs("]}\n", fh);
}