libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Attributes.h
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) 2013 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#ifndef _d4attributes_h
27#define _d4attributes_h 1
28
29#include <string>
30#include <vector>
31
32#include "D4AttributeType.h"
33#include "DapObj.h"
34#include "XMLWriter.h"
35
36using namespace std;
37
38namespace libdap {
39
40class AttrTable;
41class D4Attributes;
42
43class D4Attribute : public DapObj {
44 string d_name;
45 D4AttributeType d_type; // Attributes are limited to the simple types
46 bool is_utf8_str = false;
47
48 // If d_type is attr_container_c is true, use d_attributes to read
49 // the contained attributes, otherwise use d_values to read the vector
50 // of values.
51 D4Attributes *d_attributes;
52
53 // IF d_type is attr_otherxml_c, the first string in d_values holds the
54 // XML, otherwise, the strings hold attributes of type d_type.
55 vector<string> d_values;
56
57 // perform a deep copy
58 void m_duplicate(const D4Attribute &src);
59
60public:
63
64 D4Attribute() : d_name(""), d_type(attr_null_c), d_attributes(0) {}
65 D4Attribute(const string &name, D4AttributeType type) : d_name(name), d_type(type), d_attributes(0) {}
66
67 D4Attribute(const D4Attribute &src);
70
71 string name() const { return d_name; }
72 void set_name(const string &name) { d_name = name; }
73
74 D4AttributeType type() const { return d_type; }
75 void set_type(D4AttributeType type) { d_type = type; }
76
77 bool get_utf8_str_flag() const { return is_utf8_str; }
78 void set_utf8_str_flag(bool utf8_str_flag) { is_utf8_str = utf8_str_flag; }
79
80 void add_value(const string &value) { d_values.push_back(value); }
81 void add_value_vector(const vector<string> &values) { d_values = values; }
82
83 D4AttributeIter value_begin() { return d_values.begin(); }
84 D4AttributeIter value_end() { return d_values.end(); }
85
86 unsigned int num_values() const { return d_values.size(); }
87 string value(unsigned int i) const { return d_values[i]; }
88
90
91 bool is_dap4_type(const std::string &path, std::vector<std::string> &inventory);
92
93 void print_dap4(XMLWriter &xml) const;
94
95 virtual void dump(ostream &strm) const;
96};
97
98class D4Attributes : public DapObj {
99public:
102
103private:
104 vector<D4Attribute *> d_attrs;
105
106 void m_duplicate(const D4Attributes &src) {
107 D4AttributesCIter i = src.d_attrs.begin();
108 while (i != src.d_attrs.end()) {
109 d_attrs.push_back(new D4Attribute(**i++)); // deep copy
110 }
111 }
112
113 D4Attribute *find_depth_first(const string &name, D4AttributesIter i);
114
115public:
117 D4Attributes(const D4Attributes &rhs) { m_duplicate(rhs); }
118
119 virtual ~D4Attributes() {
120 D4AttributesIter i = d_attrs.begin();
121 while (i != d_attrs.end()) {
122 delete *i++;
123 }
124 }
125
127 if (this == &rhs)
128 return *this;
129 m_duplicate(rhs);
130 return *this;
131 }
132
134 void transform_attrs_to_dap2(AttrTable *d2_attr_table);
135
136 bool empty() const { return d_attrs.empty(); }
137
138 void add_attribute(D4Attribute *attr) { d_attrs.push_back(new D4Attribute(*attr)); }
139
140 void add_attribute_nocopy(D4Attribute *attr) { d_attrs.push_back(attr); }
141
143 D4AttributesIter attribute_begin() { return d_attrs.begin(); }
144
146 D4AttributesIter attribute_end() { return d_attrs.end(); }
147
148 D4Attribute *find(const string &name);
149 D4Attribute *get(const string &fqn);
150 void erase(const string &fqn);
151 void erase_named_attribute(const string &name);
152
158 const vector<D4Attribute *> &attributes() const { return d_attrs; }
159
160 bool has_dap4_types(const std::string &path, std::vector<std::string> &inventory) const;
161
162 void print_dap4(XMLWriter &xml) const;
163
164 virtual void dump(ostream &strm) const;
165};
166
169
170} // namespace libdap
171
172#endif // _d4attributes_h
D4AttributeType
@ attr_null_c
Contains the attributes for a dataset.
Definition AttrTable.h:150
D4Attributes * attributes()
bool is_dap4_type(const std::string &path, std::vector< std::string > &inventory)
void add_value_vector(const vector< string > &values)
void print_dap4(XMLWriter &xml) const
D4AttributeIter value_begin()
vector< string >::const_iterator D4AttributeCIter
D4Attribute & operator=(const D4Attribute &rhs)
unsigned int num_values() const
void add_value(const string &value)
bool get_utf8_str_flag() const
string value(unsigned int i) const
vector< string >::iterator D4AttributeIter
void set_type(D4AttributeType type)
void set_name(const string &name)
void set_utf8_str_flag(bool utf8_str_flag)
virtual void dump(ostream &strm) const
dumps information about this object
D4Attribute(const string &name, D4AttributeType type)
D4AttributeType type() const
string name() const
D4AttributeIter value_end()
void erase(const string &fqn)
Erase the given attribute.
D4Attribute * find(const string &name)
D4Attributes(const D4Attributes &rhs)
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
D4Attributes & operator=(const D4Attributes &rhs)
D4Attribute * get(const string &fqn)
void add_attribute_nocopy(D4Attribute *attr)
void add_attribute(D4Attribute *attr)
const vector< D4Attribute * > & attributes() const
D4AttributesIter attribute_begin()
Get an iterator to the start of the enumerations.
D4AttributesIter attribute_end()
Get an iterator to the end of the enumerations.
void print_dap4(XMLWriter &xml) const
void transform_attrs_to_dap2(AttrTable *d2_attr_table)
Copy the attributes from this D4Attributes object to a DAP2 AttrTable.
bool has_dap4_types(const std::string &path, std::vector< std::string > &inventory) const
virtual void dump(ostream &strm) const
dumps information about this object
void erase_named_attribute(const string &name)
Erase an attribute from a specific container This method expects to find 'name' in the D4Attributes o...
vector< D4Attribute * >::iterator D4AttributesIter
vector< D4Attribute * >::const_iterator D4AttributesCIter
libdap base object for common functionality of libdap objects
Definition DapObj.h:49
STL iterator class.
STL iterator class.
top level DAP object to house generic methods
Definition AISConnect.cc:30
D4AttributeType StringToD4AttributeType(string s)
string D4AttributeTypeToString(D4AttributeType at)