source: ntrip/trunk/BNC/src/t_prn.cpp@ 5741

Last change on this file since 5741 was 5741, checked in by mervart, 8 years ago
File size: 2.2 KB
Line 
1#include <sstream>
2#include <iomanip>
3#include <stdlib.h>
4
5#include "t_prn.h"
6
7using namespace BNC;
8using namespace std;
9
10//
11//////////////////////////////////////////////////////////////////////////////
12int t_prn::toInt() const {
13 if (_system == 'G') {
14 return _number;
15 }
16 else if (_system == 'R') {
17 return MAXPRN_GPS + _number;
18 }
19 return 0;
20}
21
22//
23//////////////////////////////////////////////////////////////////////////////
24string t_prn::toString() const {
25 stringstream ss;
26 ss << _system << setfill('0') << setw(2) << _number;
27 return ss.str();
28}
29
30// Set from string
31////////////////////////////////////////////////////////////////////////////
32void t_prn::setValue(const std::string& str) {
33 unsigned prn = 0;
34 char system = '\x0';
35 const char* number = 0;
36 if ( str[0] == 'G' || str[0] == 'R') {
37 system = str[0];
38 number = str.c_str() + 1;
39 }
40 else if ( isdigit(str[0]) ) {
41 system = 'G';
42 number = str.c_str();
43 }
44 else {
45 throw "t_prn::setValue: wrong satellite ID: " + str;
46 }
47
48 char* tmpc = 0;
49 prn = strtol(number, &tmpc, 10);
50 if ( tmpc == number || *tmpc != '\x0' ) {
51 throw "t_prn::setValue: wrong satellite ID: " + str;
52 }
53
54 try {
55 this->setValue(system, prn);
56 }
57 catch (string exc) {
58 throw "t_prn::setValue: wrong satellite ID: " + str;
59 }
60}
61
62void t_prn::setValue(char system, unsigned prn) {
63 _system = system;
64 _number = prn;
65 int maxprn = 0;
66 switch (system) {
67 case 'G':
68 maxprn = MAXPRN_GPS;
69 break;
70 case 'R':
71 maxprn = MAXPRN_GLONASS;
72 break;
73 default:
74 throw "t_prn::setValue: wrong satellite system identifier";
75 break;
76 }
77 if (_number > maxprn) {
78 ostringstream msg;
79 msg << "wrong satellite ID, system ID: " << system << " number: " << prn;
80 throw "t_prn::setValue: " + msg.str();
81 }
82}
83
84//
85//////////////////////////////////////////////////////////////////////////////
86t_prn::operator unsigned() const {
87 return toInt();
88}
89
90//
91//////////////////////////////////////////////////////////////////////////////
92istream& GPSS::operator >> (istream& in, t_prn& prn) {
93 string str;
94 in >> str;
95 if (str.length() == 1 && !isdigit(str[0])) {
96 string str2;
97 in >> str2;
98 str += str2;
99 }
100 prn.setValue(str);
101 return in;
102}
Note: See TracBrowser for help on using the repository browser.