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

Last change on this file since 6148 was 6128, checked in by mervart, 10 years ago
File size: 1.8 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 else if (_system == 'E') {
19 return MAXPRN_GPS + MAXPRN_GLONASS + _number;
20 }
21 return 0;
22}
23
24//
25//////////////////////////////////////////////////////////////////////////////
26string t_prn::toString() const {
27 stringstream ss;
28 ss << _system << setfill('0') << setw(2) << _number;
29 return ss.str();
30}
31
32// Set from string
33////////////////////////////////////////////////////////////////////////////
34void t_prn::set(const std::string& str) {
35 unsigned prn = 0;
36 char system = '\x0';
37 const char* number = 0;
38 if ( str[0] == 'G' || str[0] == 'R' || str[0] == 'E' ||
39 str[0] == 'J' || str[0] == 'S' || str[0] == 'C' ) {
40 system = str[0];
41 number = str.c_str() + 1;
42 }
43 else if ( isdigit(str[0]) ) {
44 system = 'G';
45 number = str.c_str();
46 }
47 else {
48 throw "t_prn::set: wrong satellite ID: " + str;
49 }
50
51 char* tmpc = 0;
52 prn = strtol(number, &tmpc, 10);
53 if ( tmpc == number || *tmpc != '\x0' ) {
54 throw "t_prn::set: wrong satellite ID: " + str;
55 }
56
57 try {
58 this->set(system, prn);
59 }
60 catch (string exc) {
61 throw "t_prn::set: wrong satellite ID: " + str;
62 }
63}
64
65//
66//////////////////////////////////////////////////////////////////////////////
67t_prn::operator unsigned() const {
68 return toInt();
69}
70
71//
72//////////////////////////////////////////////////////////////////////////////
73istream& operator >> (istream& in, t_prn& prn) {
74 string str;
75 in >> str;
76 if (str.length() == 1 && !isdigit(str[0])) {
77 string str2;
78 in >> str2;
79 str += str2;
80 }
81 prn.set(str);
82 return in;
83}
Note: See TracBrowser for help on using the repository browser.