MCPcopy Create free account
hub / github.com/Kitware/VTK / ReadTextAttribute

Method ReadTextAttribute

IO/NetCDF/vtkNetCDFAccessor.cxx:138–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136}
137
138bool vtkNetCDFAccessor::ReadTextAttribute(
139 int ncid, int varId, const char* name, std::string& result)
140{
141 size_t length;
142 if (this->inq_attlen(ncid, varId, name, &length) != NC_NOERR)
143 {
144 return false;
145 }
146
147 result.resize(length);
148 if (length > 0)
149 {
150 if (this->get_att_text(ncid, varId, name, &result.at(0)) != NC_NOERR)
151 {
152 return false;
153 }
154 }
155 else
156 {
157 // If length == 0, then there really is nothing to read. Do nothing
158 }
159
160 // The line below seems weird, but it is here for a good reason. In general,
161 // text attributes are not null terminated, so you have to add your own (which
162 // the std::string will do for us). However, sometimes a null terminating
163 // character is written in the attribute anyway. In a C string this is no big
164 // deal. But it means that the std::string has a null character in it and it
165 // is technically different than its own C string. This line corrects that
166 // regardless of whether the null string was written we will get the right
167 // string.
168 // NOLINTNEXTLINE(readability-redundant-string-cstr)
169 result = result.c_str();
170
171 return true;
172}
173
174bool vtkNetCDFAccessor::NeedsFileName()
175{

Callers 2

GetCoordinatesMethod · 0.95
LoadMetaDataMethod · 0.80

Calls 5

inq_attlenMethod · 0.95
get_att_textMethod · 0.95
resizeMethod · 0.45
atMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected