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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
|
/**
* @file thsurvey.cxx
*/
/* Copyright (C) 2000 Stacho Mudrak
*
* $Date: $
* $RCSfile: $
* $Revision: $
*
* --------------------------------------------------------------------
* 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
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* --------------------------------------------------------------------
*/
#include "thsurvey.h"
#include "thexception.h"
#include "thchenc.h"
#include "thdate.h"
#include "thtfangle.h"
#include "thinfnan.h"
#include "thdata.h"
thsurvey::thsurvey()
{
this->full_name = "";
this->reverse_full_name = this->full_name;
this->foptr = NULL;
this->loptr = NULL;
this->decdef = false;
this->decuds = thnan;
this->num1 = 0;
this->level = 0;
this->person_renames.clear();
this->entrance.clear();
this->data = NULL;
this->privatens = true;
this->surveyns = NULL;
}
thsurvey * thsurvey::get_nss()
{
if (this->surveyns == NULL) {
this->surveyns = this;
if (!this->privatens) {
while ((!this->surveyns->privatens) && (this->surveyns->fsptr != NULL)) {
this->surveyns = this->surveyns->fsptr;
}
}
}
return this->surveyns;
}
thsurvey::~thsurvey()
{
}
int thsurvey::get_class_id()
{
return TT_SURVEY_CMD;
}
bool thsurvey::is(int class_id)
{
if (class_id == TT_SURVEY_CMD)
return true;
else
return thdataobject::is(class_id);
}
int thsurvey::get_cmd_nargs()
{
return 1;
}
const char * thsurvey::get_cmd_end()
{
// insert endcommand if multiline command
return NULL;
}
const char * thsurvey::get_cmd_name()
{
// insert endcommand if multiline command
return "survey";
}
thcmd_option_desc thsurvey::get_cmd_option_desc(const char * opts)
{
int id = thmatch_token(opts, thtt_survey_opt);
if (id == TT_SURVEY_UNKNOWN)
return thdataobject::get_cmd_option_desc(opts);
else switch (id) {
case TT_SURVEY_PERSON_RENAME:
return thcmd_option_desc(id,2);
default:
return thcmd_option_desc(id);
}
}
enum {
TT_SNS_EXPORT,
TT_SNS_PRIVATE,
TT_SNS_UNKNOWN,
};
static const thstok thtt_sns[] = {
{"off",TT_SNS_EXPORT},
{"on",TT_SNS_PRIVATE},
{NULL, TT_SNS_UNKNOWN},
};
void thsurvey::set(thcmd_option_desc cod, char ** args, int argenc, unsigned long indataline)
{
thperson tmpp1, tmpp2;
if (cod.id == 1)
cod.id = TT_DATAOBJECT_NAME;
switch (cod.id) {
case TT_SURVEY_NAMESPACE:
switch (thmatch_token(*args, thtt_sns)) {
case TT_SNS_PRIVATE:
this->privatens = false;
break;
case TT_SNS_EXPORT:
this->privatens = false;
break;
default:
ththrow(("invalid -namespace switch -- %s", *args))
}
break;
case TT_SURVEY_DECLINATION:
this->parse_declination(*args);
break;
case TT_SURVEY_PERSON_RENAME:
thencode(&(this->db->buff_enc), args[0], argenc);
tmpp1.parse(this->db, this->db->buff_enc.get_buffer());
thencode(&(this->db->buff_enc), args[1], argenc);
tmpp2.parse(this->db, this->db->buff_enc.get_buffer());
this->person_renames[tmpp1] = tmpp2;
break;
case TT_SURVEY_ENTRANCE:
thparse_objectname(this->entrance, & this->db->buff_stations, *args);
break;
case TT_DATAOBJECT_NAME:
if (th_is_keyword(*args))
this->name = this->db->strstore(*args);
else
ththrow(("invalid keyword -- %s", *args));
break;
default:
thdataobject::set(cod, args, argenc, indataline);
}
}
void thsurvey::self_delete()
{
delete this;
}
void thsurvey::self_print_properties(FILE * outf)
{
size_t nval, idx;
thtfpwfxy * vals;
thdataobject::self_print_properties(outf);
fprintf(outf,"thsurvey:\n");
fprintf(outf,"\tfull name: \"%s\" (\"%s\")\n", this->full_name,
this->reverse_full_name.get_buffer());
if (this->decdef) {
fprintf(outf,"\tdeclination:\n");
nval = this->declin.get_size();
vals = this->declin.get_values();
for(idx = 0; idx < nval; idx++) {
fprintf(outf,"\t\t%0.2f -> %8.5f deg\n",vals[idx].x,vals[idx].y);
}
}
else
fprintf(outf,"\tdeclination: none\n");
fprintf(outf,"\tlength: %g\n",this->stat.length);
}
int thsurvey::get_context()
{
return (THCTX_SURVEY | THCTX_NONE);
}
const char * thsurvey::get_full_name()
{
return this->full_name;
}
void thsurvey::parse_declination(char * str)
{
// splitne input string
thtfangle du;
thdate dd;
double decl, //year,
dumdt;
double * all_data = NULL;
double data2 [2];
int nid, idx, dateidx, typedt;
thsplit_args(& this->db->mbuff_tmp, str);
long nargs = this->db->mbuff_tmp.get_size();
char ** args = this->db->mbuff_tmp.get_buffer();
// ak 1 4 6 ... error
if ((nargs == 1) || (((nargs % 2) == 0) && (nargs > 3)))
ththrow(("invalid declination specification -- \"%s\"",str))
// ak 0 tak resetuje a nastavi na 0
if (nargs == 0) {
this->decdef = false;
return;
}
// ak nie, tak parsne jednotky
nargs--;
du.parse_units(args[nargs]);
// ak 2 tak nastavi pausalne s rokom 0
if (nargs == 1) {
thparse_double(nid, decl, args[0]);
if (nid != TT_SV_NUMBER)
ththrow(("invalid declination -- %s", args[0]))
decl = du.transform(decl);
data2[0] = 0.0;
data2[1] = decl;
this->decuds = decl;
this->declin.set(1,data2);
this->decdef = true;
return;
}
all_data = new double [nargs];
nargs = nargs/2;
dateidx = 0;
for(idx = 0; idx < nargs; idx++) {
// let's try if undated declination specification
thparse_double(typedt, dumdt, args[2 * idx]);
if (typedt == TT_SV_NAN) {
thparse_double(nid, decl, args[2 * idx + 1]);
if (nid != TT_SV_NUMBER) {
delete [] all_data;
ththrow(("invalid declination -- %s", args[2 * idx + 1]))
}
this->decuds = decl;
}
// if not, try dated declination specification
else {
try {
dd.parse(args[2 * idx]);
} catch (...) {
delete [] all_data;
threthrow(("invalid declination specification"))
}
all_data[2 * dateidx] = dd.get_start_year();
// parse declination
thparse_double(nid, decl, args[2 * idx + 1]);
if (nid != TT_SV_NUMBER) {
delete [] all_data;
ththrow(("invalid declination -- %s", args[2 * idx + 1]))
}
all_data[2 * dateidx + 1] = du.transform(decl);
dateidx++;
}
}
// set declination
if (dateidx == 0) {
data2[0] = 0.0;
data2[1] = this->decuds;
this->declin.set(1,data2);
}
else
this->declin.set(dateidx,all_data);
this->decdef = true;
delete [] all_data;
}
void thsurvey::full_name_reverse()
{
size_t fnln = strlen(this->full_name), i1, i2, si; //, ei;
const char * c1, *c3;
char * c2;
c1 = this->full_name;
si = 0;
bool has_dot = false;
for(i1 = 0; i1 <= fnln; i1++, c1++) {
if ((*c1 == '.') || ((i1 == fnln) && has_dot)) {
has_dot = true;
c3 = this->full_name + si;
c2 = this->reverse_full_name.get_buffer() + fnln - i1;
if (i1 < fnln) {
c2--;
*c2 = '.';
c2++;
}
for(i2 = si; i2 < i1; i2++, c2++, c3++)
*c2 = *c3;
si = i1 + 1;
}
}
}
|