Changeset 1722 for trunk/bindings
- Timestamp:
- 28/10/11 14:49:56 (7 months ago)
- File:
-
- 1 edited
-
trunk/bindings/cpp/NeXusFile.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bindings/cpp/NeXusFile.cpp
r1719 r1722 63 63 template<> 64 64 NXDLL_EXPORT NXnumtype getType(char number) { 65 return CHAR; 66 /* This causes runtime errors for getAttr(string, string). 65 67 stringstream msg; 66 68 msg << "NeXus::getType() does not know type of \"char\" " << number; 67 69 throw Exception(msg.str()); 68 } 69 #endif /* _MSC_VER */ 70 */ 71 } 72 #endif 73 /* _MSC_VER */ 70 74 71 75 // template specialisations for types we know … … 340 344 } 341 345 342 void File::writeData(const string& name, const string& value) { 343 if (value.empty()) { 344 throw Exception("Supplied empty value to makeData"); 345 } 346 void File::writeData(const string& name, const string& value) 347 { 348 string my_value(value); 349 // Allow empty strings by defaulting to a space 350 if (my_value.empty()) 351 my_value = " "; 346 352 vector<int> dims; 347 dims.push_back( value.size());353 dims.push_back(static_cast<int>(my_value.size())); 348 354 this->makeData(name, CHAR, dims, true); 349 355 350 string my_value(value);351 356 this->putData(&(my_value[0])); 352 357 353 358 this->closeData(); 354 359 } 360 355 361 356 362 … … 1111 1117 } 1112 1118 char* value = new char[info.length + 1]; 1113 this->getAttr(info, value, info.length+1); 1114 res = string(value, info.length); 1115 delete[] value; 1119 try 1120 { 1121 this->getAttr(info, value, info.length+1); 1122 } 1123 catch (Exception& e) 1124 { 1125 //Avoid memory leak 1126 delete [] value; 1127 throw e; //re-throw 1128 } 1129 1130 //res = string(value, info.length); 1131 //allow the constructor to find the ending point of the string. Janik Zikovsky, sep 22, 2010 1132 res = string(value); 1133 delete [] value; 1134 1116 1135 return res; 1117 1136 }
Note: See TracChangeset
for help on using the changeset viewer.
