source: git/src/pos.cc @ 8553bdb

RELEASE/1.2debug-cidebug-ci-sanitiserswalls-datawalls-data-hanging-as-warning
Last change on this file since 8553bdb was 8553bdb, checked in by Olly Betts <olly@…>, 6 years ago

Fix -Wcast-align warning in pos.cc

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/* pos.cc
2 * Export from Aven as Survex .pos.
3 */
4/* Copyright (C) 2001,2002,2011,2013,2014,2015,2018 Olly Betts
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19 */
20
21#ifdef HAVE_CONFIG_H
22# include <config.h>
23#endif
24
25#include "pos.h"
26
27#include "export.h" // For LABELS, etc
28
29#include <algorithm>
30#include <stdio.h>
31#include <string.h>
32
33#include "message.h"
34#include "namecompare.h"
35#include "osalloc.h"
36#include "useful.h"
37
38using namespace std;
39
40POS::~POS()
41{
42    vector<pos_label*>::const_iterator i;
43    for (i = todo.begin(); i != todo.end(); ++i) {
44        free(*i);
45    }
46    todo.clear();
47}
48
49const int *
50POS::passes() const
51{
52    static const int default_passes[] = { LABELS|ENTS|FIXES|EXPORTS, 0 };
53    return default_passes;
54}
55
56void POS::header(const char *, const char *, time_t,
57                 double, double, double, double, double, double)
58{
59    /* TRANSLATORS: Heading line for .pos file.  Please try to ensure the “,”s
60     * (or at least the columns) are in the same place */
61    fputsnl(msg(/*( Easting, Northing, Altitude )*/195), fh);
62}
63
64void
65POS::label(const img_point *p, const char *s, bool /*fSurface*/, int /*type*/)
66{
67    size_t len = strlen(s);
68    pos_label * l = (pos_label*)malloc(offsetof(pos_label, name) + len + 1);
69    if (l == NULL)
70        throw std::bad_alloc();
71    l->x = p->x;
72    l->y = p->y;
73    l->z = p->z;
74    memcpy(l->name, s, len + 1);
75    todo.push_back(l);
76}
77
78class pos_label_ptr_cmp {
79    char separator;
80
81  public:
82    explicit pos_label_ptr_cmp(char separator_) : separator(separator_) { }
83
84    bool operator()(const POS::pos_label* a, const POS::pos_label* b) {
85        return name_cmp(a->name, b->name, separator) < 0;
86    }
87};
88
89void
90POS::footer()
91{
92    sort(todo.begin(), todo.end(), pos_label_ptr_cmp(separator));
93    vector<pos_label*>::const_iterator i;
94    for (i = todo.begin(); i != todo.end(); ++i) {
95        fprintf(fh, "(%8.2f, %8.2f, %8.2f ) %s\n",
96                (*i)->x, (*i)->y, (*i)->z, (*i)->name);
97    }
98}
Note: See TracBrowser for help on using the repository browser.