File: DataDDS.cc

package info (click to toggle)
libdap 3.12.0-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,764 kB
  • ctags: 6,626
  • sloc: cpp: 35,470; sh: 22,308; ansic: 15,103; exp: 2,008; yacc: 1,789; makefile: 858; xml: 435; perl: 52
file content (167 lines) | stat: -rw-r--r-- 5,279 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// (c) COPYRIGHT URI/MIT 1997-1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
//      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>

//
// jhrg 9/19/97

#include "config.h"

#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>

#include "DataDDS.h"
#include "debug.h"

using namespace std;

namespace libdap {

// private

/** Parse the version string. A string that does not parse causes the
    version to default to 0.0. This is better than throwing an Error since
    this method is called from a constructor. */
void
DataDDS::m_version_string_to_numbers()
{
    string num = d_server_version.substr(d_server_version.find('/') + 1);

    if (!num.empty() && num.find('.') != string::npos) {
        istringstream iss(num);
        char c;

        iss >> d_server_version_major;
        iss >> c;               // This reads the `.' in the version string
        iss >> d_server_version_minor;

        // Did it parse?
        if (!(c == '.' && d_server_version_major > 0
              && d_server_version_minor > 0)) {

            d_server_version_major = 0;
            d_server_version_minor = 0;
        }
    }
    else {
        d_server_version_major = 0;
        d_server_version_minor = 0;
    }

    DBG(cerr << "Server version: " << d_server_version_major << "." \
        << d_server_version_minor << endl);
}

/** Parse the protocol string. A string that does not parse causes the
    version to default to 2.0. This is better than throwing an Error since
    this method is called from a constructor. */
void
DataDDS::m_protocol_string_to_numbers()
{

    if (!d_protocol_version.empty() && d_protocol_version.find('.')
        != string::npos) {
        istringstream iss(d_protocol_version);
        char c;

        iss >> d_server_protocol_major;
        iss >> c;               // This reads the `.' in the version string
        iss >> d_server_protocol_minor;

        // Did it parse?
        if (!(c == '.' && d_server_protocol_major > 0)) {
            d_server_protocol_major = 2;
            d_server_protocol_minor = 0;
        }
    }
    else {
        d_server_protocol_major = 2;
        d_server_protocol_minor = 0;
    }

    DBG(cerr << "Server version: " << d_server_version_major << "." \
        << d_server_version_minor << endl);
}

/** @brief dumps information about this object
 *
 * Displays the pointer value of this instance and then calls parent dump
 *
 * @param strm C++ i/o stream to dump the information to
 * @return void
 */
void
DataDDS::dump(ostream &strm) const
{
    strm << DapIndent::LMarg << "DataDDS::dump - ("
    << (void *)this << ")" << endl ;
    DapIndent::Indent() ;
    DDS::dump(strm) ;
    strm << DapIndent::LMarg << "server version: " << d_server_version
         << endl ;
    strm << DapIndent::LMarg << "version major: " << d_server_version_major
         << endl ;
    strm << DapIndent::LMarg << "version minor: " << d_server_version_minor
         << endl ;
    strm << DapIndent::LMarg << "protocol version: " << d_protocol_version
         << endl ;
    strm << DapIndent::LMarg << "protocol major: " << d_server_protocol_major
         << endl ;
    strm << DapIndent::LMarg << "protocol minor: " << d_server_protocol_minor
         << endl ;
    DapIndent::UnIndent() ;
}

// public

/** @brief Make an instance of DataDDS
    A DataDDS instance is a DDS with additional information about the version
    of the server from which the data came.
    @param factory Use this BaseTypeFactory to instantiate the variables.
    Caller must free; can also be set using the set_factory() method. Never
    delete until just before deleting the DDS itself unless you intend to
    replace the factory with a new instance.
    @param n The name of the dataset. Can also be set using the
    set_dataset_name() method.
    @param v The server version.
    @param p The protocol version. */

DataDDS::DataDDS(BaseTypeFactory *factory, const string &n, const string &v,
                 const string &p)
        : DDS(factory, n), d_server_version(v), d_protocol_version(p)
{
    m_version_string_to_numbers();
    m_protocol_string_to_numbers();
}

} // namespace libdap