~ubuntu-branches/ubuntu/vivid/libdap/vivid

« back to all changes in this revision

Viewing changes to Str.cc

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2013-10-17 22:12:11 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20131017221211-re1r37k4d6wrtmeq
Tags: 3.12.0-1
* New upstream release.
  - No longer need curl-types-remove.patch 
* Add debian/watch file.
* Fix typo in hardening flags; Change  to =all,-pie ; 
  Use DEB_LDFLAGS_MAINT_APPEND. Closes: #697387.
* Enable parallel build. Closes: #723938.
* Depend on libcurl4-gnutls-dev | libcurl-dev. Closes: #722701.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
//
20
20
// You should have received a copy of the GNU Lesser General Public
21
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
 
22
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23
23
//
24
24
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
25
 
36
36
 
37
37
#include "config.h"
38
38
 
39
 
static char rcsid[] not_used =
40
 
    {"$Id: Str.cc 21699 2009-11-05 00:06:01Z jimg $"
41
 
    };
 
39
#include <sstream>
42
40
 
43
41
#include "Byte.h"
44
42
#include "Int16.h"
54
52
#include "Sequence.h"
55
53
#include "Grid.h"
56
54
 
 
55
#include "Marshaller.h"
 
56
#include "UnMarshaller.h"
57
57
 
58
58
#include "DDS.h"
59
59
#include "util.h"
77
77
    created.
78
78
 
79
79
*/
80
 
Str::Str(const string &n) : BaseType(n, dods_str_c), _buf("")
 
80
Str::Str(const string &n) : BaseType(n, dods_str_c), d_buf("")
81
81
{}
82
82
 
83
83
/** The Str server-side constructor accepts the name of the variable and the
88
88
    variable is created
89
89
*/
90
90
Str::Str(const string &n, const string &d)
91
 
    : BaseType(n, d, dods_str_c), _buf("")
 
91
    : BaseType(n, d, dods_str_c), d_buf("")
92
92
{}
93
93
 
94
94
Str::Str(const Str &copy_from) : BaseType(copy_from)
95
95
{
96
 
    _buf = copy_from._buf;
 
96
    d_buf = copy_from.d_buf;
97
97
}
98
98
 
99
99
BaseType *
111
111
    // Call BaseType::operator=.
112
112
    dynamic_cast<BaseType &>(*this) = rhs;
113
113
 
114
 
    _buf = rhs._buf;
 
114
    d_buf = rhs.d_buf;
115
115
 
116
116
    return *this;
117
117
}
119
119
unsigned int
120
120
Str::length()
121
121
{
122
 
    return _buf.length();
 
122
    return d_buf.length();
123
123
}
124
124
 
125
125
unsigned int
126
 
Str::width()
 
126
Str::width(bool)
127
127
{
128
128
    return sizeof(string);
129
129
}
147
147
 
148
148
    dds.timeout_off();
149
149
 
150
 
    m.put_str( _buf ) ;
 
150
    m.put_str( d_buf ) ;
151
151
 
152
 
    DBG(cerr << "Exiting: buf = " << _buf << endl);
 
152
    DBG(cerr << "Exiting: buf = " << d_buf << endl);
153
153
 
154
154
    return true;
155
155
}
159
159
bool
160
160
Str::deserialize(UnMarshaller &um, DDS *, bool)
161
161
{
162
 
    um.get_str( _buf ) ;
 
162
    um.get_str( d_buf ) ;
163
163
 
164
164
    return false;
165
165
}
183
183
                          "No place to store a reference to the data.");
184
184
    // If *val is null, then the caller has not allocated storage for the
185
185
    // value; we must. If there is storage there, assume it is a string and
186
 
    // assign _buf's value to that storage.
 
186
    // assign d_buf's value to that storage.
187
187
    if (!*val)
188
 
        *val = new string(_buf);
 
188
        *val = new string(d_buf);
189
189
    else
190
 
        *static_cast<string*>(*val) = _buf;
 
190
        *static_cast<string*>(*val) = d_buf;
191
191
 
192
192
    return sizeof(string*);
193
193
}
211
211
    if (!val)
212
212
        throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
213
213
 
214
 
    _buf = *static_cast<string*>(val);
 
214
    d_buf = *static_cast<string*>(val);
215
215
 
216
216
    return sizeof(string*);
217
217
}
223
223
bool
224
224
Str::set_value(const string &value)
225
225
{
226
 
    _buf = value;
 
226
    d_buf = value;
227
227
    set_read_p(true);
228
228
 
229
229
    return true;
234
234
string
235
235
Str::value() const
236
236
{
237
 
    return _buf;
 
237
    return d_buf;
238
238
}
239
239
 
240
 
#if FILE_METHODS
241
240
void
242
241
Str::print_val(FILE *out, string space, bool print_decl_p)
243
242
{
244
 
    if (print_decl_p) {
245
 
        print_decl(out, space, false);
246
 
        fprintf(out, " = \"%s\";\n", escattr(_buf).c_str()) ;
247
 
    }
248
 
    else
249
 
        fprintf(out, "\"%s\"", escattr(_buf).c_str()) ;
 
243
    ostringstream oss;
 
244
    print_val(oss, space, print_decl_p);
 
245
    fwrite(oss.str().data(), sizeof(char), oss.str().length(), out);
250
246
}
251
 
#endif
252
247
 
253
248
void
254
249
Str::print_val(ostream &out, string space, bool print_decl_p)
255
250
{
256
251
    if (print_decl_p) {
257
252
        print_decl(out, space, false);
258
 
        out << " = \"" << escattr(_buf) << "\";\n" ;
 
253
        out << " = \"" << escattr(d_buf) << "\";\n" ;
259
254
    }
260
255
    else
261
 
        out << "\"" << escattr(_buf) << "\"" ;
 
256
        out << "\"" << escattr(d_buf) << "\"" ;
262
257
}
263
258
 
264
259
bool
286
281
 
287
282
    switch (b->type()) {
288
283
    case dods_str_c:
289
 
        return rops<string, string, StrCmp<string, string> >
290
 
               (_buf, dynamic_cast<Str *>(b)->_buf, op);
 
284
        return StrCmp<string, string>(op, d_buf, static_cast<Str*>(b)->value());
291
285
    case dods_url_c:
292
 
        return rops<string, string, StrCmp<string, string> >
293
 
               (_buf, dynamic_cast<Url *>(b)->_buf, op);
 
286
        return StrCmp<string, string>(op, d_buf, static_cast<Url*>(b)->value());
294
287
    default:
295
288
        return false;
296
289
    }
311
304
    << (void *)this << ")" << endl ;
312
305
    DapIndent::Indent() ;
313
306
    BaseType::dump(strm) ;
314
 
    strm << DapIndent::LMarg << "value: " << _buf << endl ;
 
307
    strm << DapIndent::LMarg << "value: " << d_buf << endl ;
315
308
    DapIndent::UnIndent() ;
316
309
}
317
310