libdap++ Updated for version 3.8.2

DataDDS.cc

Go to the documentation of this file.
00001 
00002 // -*- mode: c++; c-basic-offset:4 -*-
00003 
00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00005 // Access Protocol.
00006 
00007 // Copyright (c) 2002,2003 OPeNDAP, Inc.
00008 // Author: James Gallagher <jgallagher@opendap.org>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00025 
00026 // (c) COPYRIGHT URI/MIT 1997-1999
00027 // Please read the full copyright statement in the file COPYRIGHT_URI.
00028 //
00029 // Authors:
00030 //      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
00031 
00032 //
00033 // jhrg 9/19/97
00034 
00035 #include "config.h"
00036 
00037 static char rcsid[] not_used =
00038     {"$Id: DataDDS.cc 17856 2008-02-02 21:25:59Z pwest $"
00039     };
00040 
00041 
00042 #include <iostream>
00043 #include <iomanip>
00044 #include <sstream>
00045 #include <string>
00046 
00047 #include "DataDDS.h"
00048 #include "debug.h"
00049 
00050 using namespace std;
00051 
00052 namespace libdap {
00053 
00054 // private
00055 
00059 void
00060 DataDDS::m_version_string_to_numbers()
00061 {
00062     string num = d_server_version.substr(d_server_version.find('/') + 1);
00063 
00064     if (!num.empty() && num.find('.') != string::npos) {
00065         istringstream iss(num);
00066         char c;
00067 
00068         iss >> d_server_version_major;
00069         iss >> c;               // This reads the `.' in the version string
00070         iss >> d_server_version_minor;
00071 
00072         // Did it parse?
00073         if (!(c == '.' && d_server_version_major > 0
00074               && d_server_version_minor > 0)) {
00075 
00076             d_server_version_major = 0;
00077             d_server_version_minor = 0;
00078         }
00079     }
00080     else {
00081         d_server_version_major = 0;
00082         d_server_version_minor = 0;
00083     }
00084 
00085     DBG(cerr << "Server version: " << d_server_version_major << "." \
00086         << d_server_version_minor << endl);
00087 }
00088 
00092 void
00093 DataDDS::m_protocol_string_to_numbers()
00094 {
00095 
00096     if (!d_protocol_version.empty() && d_protocol_version.find('.')
00097         != string::npos) {
00098         istringstream iss(d_protocol_version);
00099         char c;
00100 
00101         iss >> d_server_protocol_major;
00102         iss >> c;               // This reads the `.' in the version string
00103         iss >> d_server_protocol_minor;
00104 
00105         // Did it parse?
00106         if (!(c == '.' && d_server_protocol_major > 0)) {
00107             d_server_protocol_major = 2;
00108             d_server_protocol_minor = 0;
00109         }
00110     }
00111     else {
00112         d_server_protocol_major = 2;
00113         d_server_protocol_minor = 0;
00114     }
00115 
00116     DBG(cerr << "Server version: " << d_server_version_major << "." \
00117         << d_server_version_minor << endl);
00118 }
00119 
00127 void
00128 DataDDS::dump(ostream &strm) const
00129 {
00130     strm << DapIndent::LMarg << "DataDDS::dump - ("
00131     << (void *)this << ")" << endl ;
00132     DapIndent::Indent() ;
00133     DDS::dump(strm) ;
00134     strm << DapIndent::LMarg << "server version: " << d_server_version
00135          << endl ;
00136     strm << DapIndent::LMarg << "version major: " << d_server_version_major
00137          << endl ;
00138     strm << DapIndent::LMarg << "version minor: " << d_server_version_minor
00139          << endl ;
00140     strm << DapIndent::LMarg << "protocol version: " << d_protocol_version
00141          << endl ;
00142     strm << DapIndent::LMarg << "protocol major: " << d_server_protocol_major
00143          << endl ;
00144     strm << DapIndent::LMarg << "protocol minor: " << d_server_protocol_minor
00145          << endl ;
00146     DapIndent::UnIndent() ;
00147 }
00148 
00149 // public
00150 
00163 DataDDS::DataDDS(BaseTypeFactory *factory, const string &n, const string &v,
00164                  const string &p)
00165         : DDS(factory, n), d_server_version(v), d_protocol_version(p)
00166 {
00167     m_version_string_to_numbers();
00168     m_protocol_string_to_numbers();
00169 }
00170 
00171 } // namespace libdap
00172