libdap  Updated for version 3.19.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
DataDDS.cc
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 // (c) COPYRIGHT URI/MIT 1997-1999
27 // Please read the full copyright statement in the file COPYRIGHT_URI.
28 //
29 // Authors:
30 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31 
32 //
33 // jhrg 9/19/97
34 
35 #include "config.h"
36 
37 #include <iostream>
38 #include <iomanip>
39 #include <sstream>
40 #include <string>
41 
42 #include "DataDDS.h"
43 #include "debug.h"
44 
45 using namespace std;
46 
47 namespace libdap {
48 
49 // private
50 
54 void
55 DataDDS::m_version_string_to_numbers()
56 {
57  string num = d_server_version.substr(d_server_version.find('/') + 1);
58 
59  if (!num.empty() && num.find('.') != string::npos) {
60  istringstream iss(num);
61  char c;
62 
63  iss >> d_server_version_major;
64  iss >> c; // This reads the `.' in the version string
65  iss >> d_server_version_minor;
66 
67  // Did it parse?
68  if (!(c == '.' && d_server_version_major > 0
69  && d_server_version_minor > 0)) {
70 
71  d_server_version_major = 0;
72  d_server_version_minor = 0;
73  }
74  }
75  else {
76  d_server_version_major = 0;
77  d_server_version_minor = 0;
78  }
79 
80  DBG(cerr << "Server version: " << d_server_version_major << "." \
81  << d_server_version_minor << endl);
82 }
83 
87 void
88 DataDDS::m_protocol_string_to_numbers()
89 {
90 
91  if (!d_protocol_version.empty() && d_protocol_version.find('.')
92  != string::npos) {
93  istringstream iss(d_protocol_version);
94  char c;
95 
96  iss >> d_server_protocol_major;
97  iss >> c; // This reads the `.' in the version string
98  iss >> d_server_protocol_minor;
99 
100  // Did it parse?
101  if (!(c == '.' && d_server_protocol_major > 0)) {
102  d_server_protocol_major = 2;
103  d_server_protocol_minor = 0;
104  }
105  }
106  else {
107  d_server_protocol_major = 2;
108  d_server_protocol_minor = 0;
109  }
110 
111  DBG(cerr << "Server version: " << d_server_version_major << "." \
112  << d_server_version_minor << endl);
113 }
114 
122 void
123 DataDDS::dump(ostream &strm) const
124 {
125  strm << DapIndent::LMarg << "DataDDS::dump - ("
126  << (void *)this << ")" << endl ;
127  DapIndent::Indent() ;
128  DDS::dump(strm) ;
129  strm << DapIndent::LMarg << "server version: " << d_server_version
130  << endl ;
131  strm << DapIndent::LMarg << "version major: " << d_server_version_major
132  << endl ;
133  strm << DapIndent::LMarg << "version minor: " << d_server_version_minor
134  << endl ;
135  strm << DapIndent::LMarg << "protocol version: " << d_protocol_version
136  << endl ;
137  strm << DapIndent::LMarg << "protocol major: " << d_server_protocol_major
138  << endl ;
139  strm << DapIndent::LMarg << "protocol minor: " << d_server_protocol_minor
140  << endl ;
141  DapIndent::UnIndent() ;
142 }
143 
144 // public
145 
158 DataDDS::DataDDS(BaseTypeFactory *factory, const string &n, const string &v,
159  const string &p)
160  : DDS(factory, n), d_server_version(v), d_protocol_version(p)
161 {
162  m_version_string_to_numbers();
163  m_protocol_string_to_numbers();
164 }
165 
166 } // namespace libdap
167 
STL namespace.