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

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