File: validate.cc

package info (click to toggle)
gpsbabel 1.7.0%2Bds-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 100,408 kB
  • sloc: cpp: 104,725; xml: 14,055; sh: 4,699; ansic: 2,062; makefile: 960; perl: 681; tcl: 138; javascript: 9
file content (116 lines) | stat: -rw-r--r-- 3,943 bytes parent folder | download
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*

    validate internal data structures.

    Copyright (C) 2013 Robert Lipe   robertlipe+source@gpsbabel.org

    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 Street, Fifth Floor, Boston, MA  02110-1301, USA.

 */

#include "defs.h"
#include "validate.h"
#include <cstdio>

#if FILTERS_ENABLED
#define MYNAME "validate"

void ValidateFilter::validate_head(const route_head*)
{
  head_ct += 1;
  segment_ct_start = point_ct;
}

void ValidateFilter::validate_head_trl(const route_head* header)
{
  int segment_waypt_ct = point_ct - segment_ct_start;
  if (debug) {
    fprintf(stderr, "%s %d ct: %d, waypt_count: %d\n", segment_type, header->rte_num,  segment_waypt_ct, header->rte_waypt_ct);
  }
  if (!debug && (segment_waypt_ct != header->rte_waypt_ct)) {
    fatal(MYNAME ":%s %d count mismatch, expected %d, actual %d\n", segment_type, header->rte_num, header->rte_waypt_ct, segment_waypt_ct);
  }
}

void ValidateFilter::validate_point(const Waypoint*)
{
  point_ct += 1;
}

void ValidateFilter::process()
{
  WayptFunctor<ValidateFilter> validate_point_f(this, &ValidateFilter::validate_point);
  RteHdFunctor<ValidateFilter> validate_head_f(this, &ValidateFilter::validate_head);
  RteHdFunctor<ValidateFilter> validate_head_trl_f(this, &ValidateFilter::validate_head_trl);

  debug = *opt_debug == '1';
  checkempty = *opt_checkempty == '1';

  point_ct = 0;
  if (debug) {
    fprintf(stderr, "\nProcessing waypts\n");
  }
  waypt_disp_all(validate_point_f);
  if (debug) {
    fprintf(stderr, "point ct: %u, waypt_count: %u\n", point_ct, waypt_count());
  }
  if (!debug && (point_ct != waypt_count())) {
    fatal(MYNAME ":Waypoint count mismatch, expected %u, actual %u\n", waypt_count(), point_ct);
  }

  head_ct = 0;
  point_ct = 0;
  segment_type = "route";
  if (debug) {
    fprintf(stderr, "\nProcessing routes\n");
  }
  route_disp_all(validate_head_f, validate_head_trl_f, validate_point_f);
  if (debug) {
    fprintf(stderr, "route head ct: %u, route_count: %u\n", head_ct, route_count());
    fprintf(stderr, "total route point ct: %u, route_waypt_count: %u\n", point_ct, route_waypt_count());
  }
  if (!debug && (head_ct != route_count())) {
    fatal(MYNAME ":Route count mismatch, expected %u, actual %u\n", route_count(), head_ct);
  }
  if (!debug && (point_ct != route_waypt_count())) {
    fatal(MYNAME ":Total route waypoint count mismatch, expected %u, actual %u\n", route_waypt_count(), point_ct);
  }

  head_ct = 0;
  point_ct = 0;
  segment_type = "track";
  if (debug) {
    fprintf(stderr, "\nProcessing tracks\n");
  }
  track_disp_all(validate_head_f, validate_head_trl_f, validate_point_f);
  if (debug) {
    fprintf(stderr, "track head ct: %u, track_count: %u\n", head_ct, track_count());
    fprintf(stderr, "total track point ct: %u, track_waypt_count: %u\n", point_ct, track_waypt_count());
  }
  if (!debug && (head_ct != track_count())) {
    fatal(MYNAME ":Track count mismatch, expected %u, actual %u\n", track_count(), head_ct);
  }
  if (!debug && (point_ct != track_waypt_count())) {
    fatal(MYNAME ":Total track waypoint count mismatch, expected %u, actual %u\n", track_waypt_count(), point_ct);
  }

  if (checkempty) {
    if (waypt_count()==0 && route_waypt_count()==0 && track_waypt_count()==0) {
      fatal(MYNAME ":No input\n");
    }
  }
}

#endif