bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
DmrppStr.cc
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of the BES
5
6// Copyright (c) 2016 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#include "config.h"
26
27#include <string>
28
29#include "BESError.h"
30#include "BESInternalError.h"
31#include "BESDebug.h"
32
33#include "Chunk.h"
34#include "DmrppStr.h"
35
36using namespace libdap;
37using namespace std;
38
39namespace dmrpp {
40
42DmrppStr::operator=(const DmrppStr &rhs)
43{
44 if (this == &rhs)
45 return *this;
46
47 dynamic_cast<Str &>(*this) = rhs; // run Constructor=
48
49 dynamic_cast<DmrppCommon &>(*this) = rhs;
50 //DmrppCommon::m_duplicate_common(rhs);
51
52 return *this;
53}
54
55bool
56DmrppStr::read()
57{
58 if (!get_chunks_loaded())
59 load_chunks(this);
60
61 if (read_p())
62 return true;
63
64 // The following replaces a call to DmrppCommon::read_atomic() because the
65 // string code requires special processing of the data array and requires information
66 // about the chunk size to produce correct answers.
67
68 if (get_chunks_size() != 1)
69 throw BESInternalError(string("Expected only a single chunk for variable ") + name(), __FILE__, __LINE__);
70
71 auto chunk = get_immutable_chunks()[0];
72 chunk->read_chunk();
73 auto chunk_size= chunk->get_size();
74 char *data = chunk->get_rbuf();
75
76 // It is possible that the string data is not null terminated and/or
77 // Does not span the full width of the chunk.
78 // This should correct those issues.
79 unsigned long long str_len=0;
80 bool done = false;
81 while(!done){
82 done = (str_len >= chunk_size) || (data[str_len] == 0);
83 if(!done) str_len++;
84 }
85 string value(data,str_len);
86 set_value(value); // sets read_p too
87 return true;
88}
89
90void
91DmrppStr::set_send_p(bool state)
92{
94 load_attributes(this);
95
96 Str::set_send_p(state);
97}
98
99void DmrppStr::dump(ostream & strm) const
100{
101 strm << BESIndent::LMarg << "DmrppStr::dump - (" << (void *) this << ")" << endl;
102 BESIndent::Indent();
103 DmrppCommon::dump(strm);
104 Str::dump(strm);
105 strm << BESIndent::LMarg << "value: " << d_buf << endl;
106 BESIndent::UnIndent();
107}
108
109} // namespace dmrpp
virtual void load_attributes(libdap::BaseType *btp)
Load the attribute information for this variable.
virtual bool get_chunks_loaded() const
Have the chunks been loaded?
virtual size_t get_chunks_size() const
Use this when the number of chunks is needed.
virtual const std::vector< std::shared_ptr< Chunk > > & get_immutable_chunks() const
A const reference to the vector of chunks.
virtual void load_chunks(libdap::BaseType *btp)
Load chunk information for this variable.
virtual bool get_attributes_loaded() const
Have the attributes been loaded?