libdap++  Updated for version 3.8.2
DataDDS.cc
Go to the documentation of this file.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 static char rcsid[] not_used =
38  {"$Id: DataDDS.cc 17856 2008-02-02 21:25:59Z pwest $"
39  };
40 
41 
42 #include <iostream>
43 #include <iomanip>
44 #include <sstream>
45 #include <string>
46 
47 #include "DataDDS.h"
48 #include "debug.h"
49 
50 using namespace std;
51 
52 namespace libdap {
53 
54 // private
55 
59 void
60 DataDDS::m_version_string_to_numbers()
61 {
62  string num = d_server_version.substr(d_server_version.find('/') + 1);
63 
64  if (!num.empty() && num.find('.') != string::npos) {
65  istringstream iss(num);
66  char c;
67 
68  iss >> d_server_version_major;
69  iss >> c; // This reads the `.' in the version string
70  iss >> d_server_version_minor;
71 
72  // Did it parse?
73  if (!(c == '.' && d_server_version_major > 0
74  && d_server_version_minor > 0)) {
75 
76  d_server_version_major = 0;
77  d_server_version_minor = 0;
78  }
79  }
80  else {
81  d_server_version_major = 0;
82  d_server_version_minor = 0;
83  }
84 
85  DBG(cerr << "Server version: " << d_server_version_major << "." \
86  << d_server_version_minor << endl);
87 }
88 
92 void
93 DataDDS::m_protocol_string_to_numbers()
94 {
95 
96  if (!d_protocol_version.empty() && d_protocol_version.find('.')
97  != string::npos) {
98  istringstream iss(d_protocol_version);
99  char c;
100 
101  iss >> d_server_protocol_major;
102  iss >> c; // This reads the `.' in the version string
103  iss >> d_server_protocol_minor;
104 
105  // Did it parse?
106  if (!(c == '.' && d_server_protocol_major > 0)) {
107  d_server_protocol_major = 2;
108  d_server_protocol_minor = 0;
109  }
110  }
111  else {
112  d_server_protocol_major = 2;
113  d_server_protocol_minor = 0;
114  }
115 
116  DBG(cerr << "Server version: " << d_server_version_major << "." \
117  << d_server_version_minor << endl);
118 }
119 
127 void
128 DataDDS::dump(ostream &strm) const
129 {
130  strm << DapIndent::LMarg << "DataDDS::dump - ("
131  << (void *)this << ")" << endl ;
132  DapIndent::Indent() ;
133  DDS::dump(strm) ;
134  strm << DapIndent::LMarg << "server version: " << d_server_version
135  << endl ;
136  strm << DapIndent::LMarg << "version major: " << d_server_version_major
137  << endl ;
138  strm << DapIndent::LMarg << "version minor: " << d_server_version_minor
139  << endl ;
140  strm << DapIndent::LMarg << "protocol version: " << d_protocol_version
141  << endl ;
142  strm << DapIndent::LMarg << "protocol major: " << d_server_protocol_major
143  << endl ;
144  strm << DapIndent::LMarg << "protocol minor: " << d_server_protocol_minor
145  << endl ;
146  DapIndent::UnIndent() ;
147 }
148 
149 // public
150 
163 DataDDS::DataDDS(BaseTypeFactory *factory, const string &n, const string &v,
164  const string &p)
165  : DDS(factory, n), d_server_version(v), d_protocol_version(p)
166 {
167  m_version_string_to_numbers();
168  m_protocol_string_to_numbers();
169 }
170 
171 } // namespace libdap
172 
#define not_used
Definition: config.h:850
#define DBG(x)
Definition: debug.h:58