9 #ifndef vtkSMVectorPropertyTemplate_h
10 #define vtkSMVectorPropertyTemplate_h
16 #include "vtk_doubleconversion.h"
17 #include VTK_DOUBLECONVERSION_HEADER(double-conversion.h)
32 std::string AsString(
const T& var)
34 std::ostringstream str;
40 vtkMaybeUnused(
"not used in non-double specializations") inline std::
string
41 AsString(const
double& var)
44 const double_conversion::DoubleToStringConverter& converter =
45 double_conversion::DoubleToStringConverter::EcmaScriptConverter();
46 double_conversion::StringBuilder builder(buf,
sizeof(buf));
48 converter.ToShortest(var, &builder);
49 return builder.Finalize();
53 B vtkSMVPConvertFromString(
const std::string& string_representation)
56 std::istringstream buffer(string_representation);
62 vtkMaybeUnused(
"not used in non-string specializations") inline std::
string
63 vtkSMVPConvertFromString<std::
string>(const std::
string& string_representation)
65 return string_representation;
84 this->Property = property;
85 this->DefaultsValid =
false;
86 this->Initialized =
false;
92 this->DefaultValues.clear();
93 this->DefaultValues.insert(this->DefaultValues.end(), this->Values.begin(), this->Values.end());
94 this->DefaultsValid =
true;
100 this->UncheckedValues.resize(num);
101 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
107 return static_cast<unsigned int>(this->UncheckedValues.size());
116 if (num == this->Values.size())
120 this->Values.resize(num);
121 this->UncheckedValues.resize(num);
125 this->Initialized =
true;
129 this->Initialized =
false;
137 assert(idx < this->
Values.size());
138 return this->Values[idx];
145 if (idx >= 0 && idx <
static_cast<int>(this->DefaultValues.size()))
147 return this->DefaultValues[idx];
150 static T empty_value = T();
155 T*
GetElements() {
return !this->Values.empty() ? &this->Values[0] :
nullptr; }
160 return (!this->UncheckedValues.empty()) ? &this->UncheckedValues[0] :
nullptr;
166 return this->UncheckedValues[idx];
174 this->UncheckedValues.resize(idx + 1);
177 if (this->UncheckedValues[idx] !=
value)
179 this->UncheckedValues[idx] =
value;
180 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
193 bool modified =
false;
195 if (numArgs != numValues)
197 this->UncheckedValues.resize(numValues);
203 modified = !std::equal(this->UncheckedValues.begin(), this->UncheckedValues.end(), values);
211 std::copy(values, values + numArgs, this->UncheckedValues.begin());
213 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
222 if (this->Initialized && idx < numElems && value == this->
GetElement(idx))
231 this->Values[idx] =
value;
235 this->Initialized =
true;
250 bool modified =
false;
252 if (numArgs != numValues)
254 this->Values.resize(numValues);
255 this->UncheckedValues.resize(numValues);
261 modified = !std::equal(this->Values.begin(), this->Values.end(), values);
263 if (!modified && this->Initialized)
268 std::copy(values, values + numArgs, this->Values.begin());
269 this->Initialized =
true;
270 if (!modified && numValues == 0)
289 this->UncheckedValues.insert(std::end(this->UncheckedValues), values, values + numValues);
290 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
298 this->Values.insert(std::end(this->Values), values, values + numValues);
299 this->Initialized =
true;
311 bool modified =
false;
313 if (this->Values != dsrc->
Values)
315 this->Values = dsrc->
Values;
321 this->Initialized =
true;
329 if (this->UncheckedValues != dsrc->
Values)
331 this->UncheckedValues = dsrc->
Values;
336 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
344 if (this->DefaultsValid)
346 if (this->DefaultValues != this->Values || this->DefaultValues != this->UncheckedValues)
351 this->Initialized =
true;
358 this->Values.clear();
359 this->Initialized =
true;
373 std::vector<T> new_values;
375 for (
unsigned int i = 0; i < numElems; i++)
378 if (current->
GetName() && strcmp(current->
GetName(),
"Element") == 0)
384 if (
index <=
static_cast<int>(new_values.size()))
386 new_values.resize(
index + 1);
389 new_values[
index] = vtkSMVPConvertFromString<T>(str_value);
393 if (!new_values.empty())
395 this->
SetElements(&new_values[0],
static_cast<unsigned int>(new_values.size()));
415 for (
unsigned int i = 0; i <
size; i++)
418 elementElement->
SetName(
"Element");
430 this->UncheckedValues = this->
Values;
431 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
437 if (this->Values.size() != this->DefaultValues.size())
442 return std::equal(this->Values.begin(), this->Values.end(), this->DefaultValues.begin());