31 #include "MyBaseTypeFactory.h"
34 #include "BaseTypeFactory.h"
43 #include "NCMLArray.h"
46 #include "Structure.h"
57 libdap::BaseTypeFactory* MyBaseTypeFactory::_spFactory =
new BaseTypeFactory();
59 MyBaseTypeFactory::MyBaseTypeFactory()
63 MyBaseTypeFactory::~MyBaseTypeFactory()
67 auto_ptr<libdap::BaseType> MyBaseTypeFactory::makeVariable(
const libdap::Type& t,
const string &name)
71 return auto_ptr<BaseType>(_spFactory->NewByte(name));
75 return auto_ptr<BaseType>(_spFactory->NewInt16(name));
79 return auto_ptr<BaseType>(_spFactory->NewUInt16(name));
83 return auto_ptr<BaseType>(_spFactory->NewInt32(name));
87 return auto_ptr<BaseType>(_spFactory->NewUInt32(name));
91 return auto_ptr<BaseType>(_spFactory->NewFloat32(name));
95 return auto_ptr<BaseType>(_spFactory->NewFloat64(name));
99 return auto_ptr<BaseType>(_spFactory->NewStr(name));
103 return auto_ptr<BaseType>(_spFactory->NewUrl(name));
107 THROW_NCML_INTERNAL_ERROR(
"MyBaseTypeFactory::makeVariable(): no longer can make Array, instead use Array<T> form!");
110 case dods_structure_c:
111 return auto_ptr<BaseType>(_spFactory->NewStructure(name));
114 case dods_sequence_c:
115 return auto_ptr<BaseType>(_spFactory->NewSequence(name));
119 return auto_ptr<BaseType>(_spFactory->NewGrid(name));
123 return auto_ptr<BaseType>(0);
127 auto_ptr<libdap::BaseType> MyBaseTypeFactory::makeVariable(
const string& type,
const std::string& name)
129 if (isArrayTemplate(type)) {
132 return auto_ptr<BaseType>(makeArrayTemplateVariable(type, name,
true).release());
135 return makeVariable(getType(type), name);
142 if (name ==
"Byte") {
145 else if (name ==
"Int16") {
148 else if (name ==
"UInt16") {
149 return dods_uint16_c;
152 else if (name ==
"Int32") {
156 else if (name ==
"UInt32") {
157 return dods_uint32_c;
160 else if (name ==
"Float32") {
161 return dods_float32_c;
164 else if (name ==
"Float64") {
165 return dods_float64_c;
168 else if (name ==
"String" || name ==
"string") {
172 else if (name ==
"URL") {
176 else if (name ==
"Array") {
180 else if (name ==
"Structure") {
181 return dods_structure_c;
184 else if (name ==
"Sequence") {
185 return dods_sequence_c;
188 else if (name ==
"Grid") {
197 bool MyBaseTypeFactory::isSimpleType(
const string& name)
199 Type t = getType(name);
216 bool MyBaseTypeFactory::isArrayTemplate(
const string& typeName)
219 return (typeName.find(
"Array<") == 0 && (typeName.at(typeName.size() - 1) ==
'>'));
222 std::auto_ptr<libdap::Array> MyBaseTypeFactory::makeArrayTemplateVariable(
const string& type,
const string& name,
223 bool makeTemplateVar)
229 if (type ==
"Array<Byte>") {
231 if (makeTemplateVar) {
232 pNew->add_var_nocopy(makeVariable(
"Byte", name).release());
235 else if (type ==
"Array<Int16>") {
237 if (makeTemplateVar) {
238 pNew->add_var_nocopy(makeVariable(
"Int16", name).release());
241 else if (type ==
"Array<UInt16>") {
243 if (makeTemplateVar) {
244 pNew->add_var_nocopy(makeVariable(
"UInt16", name).release());
247 else if (type ==
"Array<Int32>") {
249 if (makeTemplateVar) {
250 pNew->add_var_nocopy(makeVariable(
"Int32", name).release());
253 else if (type ==
"Array<UInt32>") {
255 if (makeTemplateVar) {
256 pNew->add_var_nocopy(makeVariable(
"UInt32", name).release());
259 else if (type ==
"Array<Float32>") {
261 if (makeTemplateVar) {
262 pNew->add_var_nocopy(makeVariable(
"Float32", name).release());
265 else if (type ==
"Array<Float64>") {
267 if (makeTemplateVar) {
268 pNew->add_var_nocopy(makeVariable(
"Float64", name).release());
271 else if (type ==
"Array<String>" || type ==
"Array<Str>") {
273 if (makeTemplateVar) {
274 pNew->add_var_nocopy(makeVariable(
"String", name).release());
277 else if (type ==
"Array<URL>" || type ==
"Array<Url>") {
279 if (makeTemplateVar) {
280 pNew->add_var_nocopy(makeVariable(
"URL", name).release());
284 THROW_NCML_INTERNAL_ERROR(
"MyBaseTypeFactory::makeArrayTemplateVariable(): can't create type=" + type);
289 THROW_NCML_INTERNAL_ERROR(
290 "MyBaseTypeFactory::makeArrayTemplateVariable(): failed to allocate memory for type=" + type);
292 return auto_ptr<Array>(pNew);