32#include "MyBaseTypeFactory.h"
34#include <libdap/BaseType.h>
35#include <libdap/BaseTypeFactory.h>
37#include <libdap/Array.h>
38#include <libdap/Byte.h>
39#include <libdap/Float32.h>
40#include <libdap/Float64.h>
41#include <libdap/Grid.h>
42#include <libdap/Int16.h>
43#include <libdap/Int32.h>
45#include <libdap/Sequence.h>
46#include <libdap/Str.h>
47#include <libdap/Structure.h>
48#include <libdap/UInt16.h>
49#include <libdap/UInt32.h>
50#include <libdap/Url.h>
58libdap::BaseTypeFactory* MyBaseTypeFactory::_spFactory =
new BaseTypeFactory();
61MyBaseTypeFactory::MyBaseTypeFactory()
65MyBaseTypeFactory::~MyBaseTypeFactory()
74 return unique_ptr<BaseType>(_spFactory->NewByte(name));
78 return unique_ptr<BaseType>(_spFactory->NewInt16(name));
82 return unique_ptr<BaseType>(_spFactory->NewUInt16(name));
86 return unique_ptr<BaseType>(_spFactory->NewInt32(name));
90 return unique_ptr<BaseType>(_spFactory->NewUInt32(name));
94 return unique_ptr<BaseType>(_spFactory->NewFloat32(name));
98 return unique_ptr<BaseType>(_spFactory->NewFloat64(name));
102 return unique_ptr<BaseType>(_spFactory->NewStr(name));
106 return unique_ptr<BaseType>(_spFactory->NewUrl(name));
110 THROW_NCML_INTERNAL_ERROR(
"MyBaseTypeFactory::makeVariable(): no longer can make Array, instead use Array<T> form!");
113 case dods_structure_c:
114 return unique_ptr<BaseType>(_spFactory->NewStructure(name));
117 case dods_sequence_c:
118 return unique_ptr<BaseType>(_spFactory->NewSequence(name));
122 return unique_ptr<BaseType>(_spFactory->NewGrid(name));
126 THROW_NCML_INTERNAL_ERROR(
"MyBaseTypeFactory::makeVariable(): request to make an unknown variable type.");
128 return unique_ptr<BaseType>(0);
148 if (name ==
"Byte") {
151 else if (name ==
"Int16") {
154 else if (name ==
"UInt16") {
155 return dods_uint16_c;
158 else if (name ==
"Int32") {
162 else if (name ==
"UInt32") {
163 return dods_uint32_c;
166 else if (name ==
"Float32") {
167 return dods_float32_c;
170 else if (name ==
"Float64") {
171 return dods_float64_c;
174 else if (name ==
"String" || name ==
"string") {
178 else if (name ==
"URL") {
182 else if (name ==
"Array") {
186 else if (name ==
"Structure") {
187 return dods_structure_c;
190 else if (name ==
"Sequence") {
191 return dods_sequence_c;
194 else if (name ==
"Grid") {
225 return (typeName.find(
"Array<") == 0 && (typeName.at(typeName.size() - 1) ==
'>'));
228std::unique_ptr<libdap::Array>
231 Array* pNew =
nullptr;
232 if (type ==
"Array<Byte>") {
234 if (makeTemplateVar) {
235 pNew->add_var_nocopy(
makeVariable(
"Byte", name).release());
238 else if (type ==
"Array<Int16>") {
240 if (makeTemplateVar) {
241 pNew->add_var_nocopy(
makeVariable(
"Int16", name).release());
244 else if (type ==
"Array<UInt16>") {
246 if (makeTemplateVar) {
247 pNew->add_var_nocopy(
makeVariable(
"UInt16", name).release());
250 else if (type ==
"Array<Int32>") {
252 if (makeTemplateVar) {
253 pNew->add_var_nocopy(
makeVariable(
"Int32", name).release());
256 else if (type ==
"Array<UInt32>") {
258 if (makeTemplateVar) {
259 pNew->add_var_nocopy(
makeVariable(
"UInt32", name).release());
262 else if (type ==
"Array<Float32>") {
264 if (makeTemplateVar) {
265 pNew->add_var_nocopy(
makeVariable(
"Float32", name).release());
268 else if (type ==
"Array<Float64>") {
270 if (makeTemplateVar) {
271 pNew->add_var_nocopy(
makeVariable(
"Float64", name).release());
274 else if (type ==
"Array<String>" || type ==
"Array<Str>") {
276 if (makeTemplateVar) {
277 pNew->add_var_nocopy(
makeVariable(
"String", name).release());
280 else if (type ==
"Array<URL>" || type ==
"Array<Url>") {
282 if (makeTemplateVar) {
283 pNew->add_var_nocopy(
makeVariable(
"URL", name).release());
287 THROW_NCML_INTERNAL_ERROR(
"MyBaseTypeFactory::makeArrayTemplateVariable(): can't create type=" + type);
292 THROW_NCML_INTERNAL_ERROR(
293 "MyBaseTypeFactory::makeArrayTemplateVariable(): failed to allocate memory for type=" + type);
296 return unique_ptr<Array>(pNew);
static std::unique_ptr< libdap::Array > makeArrayTemplateVariable(const std::string &type, const std::string &name, bool addTemplateVar)
static bool isArrayTemplate(const std::string &typeName)
static libdap::Type getType(const std::string &name)
static std::unique_ptr< libdap::BaseType > makeVariable(const libdap::Type &type, const std::string &name)
static bool isSimpleType(const std::string &typeName)
A parameterized subclass of libdap::Array that allows us to apply constraints on NcML-specified data ...
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...