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

Last change on this file since 6018 was 6014, 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 system = str[0];
40 number = str.c_str() + 1;
41 }
42 else if ( isdigit(str[0]) ) {
43 system = 'G';
44 number = str.c_str();
45 }
46 else {
47 throw "t_prn::set: wrong satellite ID: " + str;
48 }
49
50 char* tmpc = 0;
51 prn = strtol(number, &tmpc, 10);
52 if ( tmpc == number || *tmpc != '\x0' ) {
53 throw "t_prn::set: wrong satellite ID: " + str;
54 }
55
56 try {
57 this->set(system, prn);
58 }
59 catch (string exc) {
60 throw "t_prn::set: wrong satellite ID: " + str;
61 }
62}
63
64//
65//////////////////////////////////////////////////////////////////////////////
66t_prn::operator unsigned() const {
67 return toInt();
68}
69
70//
71//////////////////////////////////////////////////////////////////////////////
72istream& operator >> (istream& in, t_prn& prn) {
73 string str;
74 in >> str;
75 if (str.length() == 1 && !isdigit(str[0])) {
76 string str2;
77 in >> str2;
78 str += str2;
79 }
80 prn.set(str);
81 return in;
82}
Note: See TracBrowser for help on using the repository browser.