Tweak code formatting
[survex.git] / src / pos.cc
blobdf4a849a1a85d94cf48d4cf553813f69e6629be1
1 /* pos.cc
2 * Export from Aven as Survex .pos.
3 */
4 /* Copyright (C) 2001,2002,2011,2013,2014,2015 Olly Betts
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.
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.
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
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #include "pos.h"
27 #include "export.h" // For LABELS, etc
29 #include <algorithm>
30 #include <stdio.h>
31 #include <string.h>
33 #include "message.h"
34 #include "namecompare.h"
35 #include "osalloc.h"
36 #include "useful.h"
38 using namespace std;
40 POS::~POS()
42 vector<pos_label*>::const_iterator i;
43 for (i = todo.begin(); i != todo.end(); ++i) {
44 delete [] *i;
46 todo.clear();
49 const int *
50 POS::passes() const
52 static const int default_passes[] = { LABELS|ENTS|FIXES|EXPORTS, 0 };
53 return default_passes;
56 void POS::header(const char *, const char *, time_t,
57 double, double, double, double, double, double)
59 fputsnl(msg(/*( Easting, Northing, Altitude )*/195), fh);
62 void
63 POS::label(const img_point *p, const char *s, bool /*fSurface*/, int /*type*/)
65 size_t len = strlen(s);
66 pos_label * l = (pos_label*)new char[offsetof(pos_label, name) + len + 1];
67 l->x = p->x;
68 l->y = p->y;
69 l->z = p->z;
70 memcpy(l->name, s, len + 1);
71 todo.push_back(l);
74 class pos_label_ptr_cmp {
75 char separator;
77 public:
78 explicit pos_label_ptr_cmp(char separator_) : separator(separator_) { }
80 bool operator()(const POS::pos_label* a, const POS::pos_label* b) {
81 return name_cmp(a->name, b->name, separator) < 0;
85 void
86 POS::footer()
88 sort(todo.begin(), todo.end(), pos_label_ptr_cmp(separator));
89 vector<pos_label*>::const_iterator i;
90 for (i = todo.begin(); i != todo.end(); ++i) {
91 fprintf(fh, "(%8.2f, %8.2f, %8.2f ) %s\n",
92 (*i)->x, (*i)->y, (*i)->z, (*i)->name);