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

Last change on this file since 5844 was 5838, checked in by mervart, 10 years ago
File size: 1.7 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::set(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::set: 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::set: wrong satellite ID: " + str;
51 }
52
53 try {
54 this->set(system, prn);
55 }
56 catch (string exc) {
57 throw "t_prn::set: wrong satellite ID: " + str;
58 }
59}
60
61//
62//////////////////////////////////////////////////////////////////////////////
63t_prn::operator unsigned() const {
64 return toInt();
65}
66
67//
68//////////////////////////////////////////////////////////////////////////////
69istream& operator >> (istream& in, t_prn& prn) {
70 string str;
71 in >> str;
72 if (str.length() == 1 && !isdigit(str[0])) {
73 string str2;
74 in >> str2;
75 str += str2;
76 }
77 prn.set(str);
78 return in;
79}
Note: See TracBrowser for help on using the repository browser.