Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Data/DataRow.cpp (1 of 5 files). Show all
Unified · Split
| @@ -49,7 +49,14 @@ DataRow::DataRow(DataTablePtr parent) : · 48 unmodified lines | ||
| 49 | 49 | DataRow::~DataRow() |
| 50 | 50 | { |
| 51 | 51 | for (uint32_t i = 0; i < m_values.size(); i++) |
| 52 | − free(m_values[i]); | |
| 52 | + { | |
| 53 | + const DataColumnPtr column = m_parent->Column(i); | |
| 54 | + | |
| 55 | + if (column != nullptr && column->Computed()) | |
| 56 | + delete static_cast<FilterExpressionParser*>(m_values[i]); | |
| 57 | + else | |
| 58 | + free(m_values[i]); | |
| 59 | + } | |
| 53 | 60 | } |
| 54 | 61 | |
| 55 | 62 | int32_t DataRow::GetColumnIndex(const string& columnName) const |
| @@ -88,30 +95,30 @@ ExpressionTreePtr DataRow::GetExpressionTree(const DataColumnPtr& column) · 32 unmodified lines | ||
| 88 | 95 | { |
| 89 | 96 | const int columnIndex = column->Index(); |
| 90 | 97 | |
| 91 | − FilterExpressionParser* parser = static_cast<FilterExpressionParser*>(m_values[columnIndex]); | |
| 98 | + if (m_values[columnIndex] == nullptr) | |
| 99 | + { | |
| 100 | + const DataTablePtr& dataTable = column->Parent(); | |
| 101 | + FilterExpressionParser* parser = new FilterExpressionParser(column->Expression()); | |
| 92 | 102 | |
| 93 | − if (parser) | |
| 94 | − return parser->GetExpressionTrees()[0]; | |
| 103 | + parser->SetDataSet(dataTable->Parent()); | |
| 104 | + parser->SetPrimaryTableName(dataTable->Name()); | |
| 105 | + parser->SetTrackFilteredSignalIDs(false); | |
| 106 | + parser->SetTrackFilteredRows(false); | |
| 95 | 107 | |
| 96 | − const DataTablePtr& dataTable = column->Parent(); | |
| 97 | − parser = new FilterExpressionParser(column->Expression()); | |
| 108 | + const auto expressionTrees = parser->GetExpressionTrees(); | |
| 98 | 109 | |
| 99 | − parser->SetDataSet(dataTable->Parent()); | |
| 100 | − parser->SetPrimaryTableName(dataTable->Name()); | |
| 101 | − parser->SetTrackFilteredSignalIDs(false); | |
| 102 | − parser->SetTrackFilteredRows(false); | |
| 110 | + if (expressionTrees.empty()) | |
| 111 | + { | |
| 112 | + delete parser; | |
| 113 | + throw DataSetException("Expression defined for computed DataColumn \"" + column->Name() + " for table \"" + m_parent->Name() + "\" cannot produce a value"); | |
| 114 | + } | |
| 103 | 115 | |
| 104 | − const auto expressionTrees = parser->GetExpressionTrees(); | |
| 116 | + m_values[columnIndex] = parser; | |
| 105 | 117 | |
| 106 | − if (expressionTrees.empty()) | |
| 107 | − { | |
| 108 | − delete parser; | |
| 109 | − throw DataSetException("Expression defined for computed DataColumn \"" + column->Name() + " for table \"" + m_parent->Name() + "\" cannot produce a value"); | |
| 118 | + return expressionTrees[0]; | |
| 110 | 119 | } |
| 111 | 120 | |
| 112 | − m_values[columnIndex] = parser; | |
| 113 | − | |
| 114 | − return expressionTrees[0]; | |
| 121 | + return static_cast<FilterExpressionParser*>(m_values[columnIndex])->GetExpressionTrees()[0]; | |
| 115 | 122 | } |
| 116 | 123 | |
| 117 | 124 | Object DataRow::GetComputedValue(const DataColumnPtr& column, DataType targetType) |
| @@ -334,7 +341,7 @@ Object DataRow::GetComputedValue(const DataColumnPtr& column, DataType targetTyp · 216 unmodified lines | ||
| 334 | 341 | case DataType::Single: |
| 335 | 342 | return static_cast<float32_t>(stod(value)); |
| 336 | 343 | case DataType::Double: |
| 337 | − return stod(value); | |
| 344 | + return static_cast<float64_t>(stod(value)); | |
| 338 | 345 | case DataType::Decimal: |
| 339 | 346 | return decimal_t(value); |
| 340 | 347 | case DataType::Guid: |
| @@ -436,7 +443,7 @@ Object DataRow::GetComputedValue(const DataColumnPtr& column, DataType targetTyp · 95 unmodified lines | ||
| 436 | 443 | } |
| 437 | 444 | } |
| 438 | 445 | |
| 439 | −template<typename T> | |
| 446 | +template<class T> | |
| 440 | 447 | Nullable<T> DataRow::GetValue(const int32_t columnIndex, DataType targetType) |
| 441 | 448 | { |
| 442 | 449 | const DataColumnPtr& column = ValidateColumnType(columnIndex, targetType, true); |
| @@ -452,7 +459,7 @@ Nullable<T> DataRow::GetValue(const int32_t columnIndex, DataType targetType) · 9 unmodified lines | ||
| 452 | 459 | return nullptr; |
| 453 | 460 | } |
| 454 | 461 | |
| 455 | −template<typename T> | |
| 462 | +template<class T> | |
| 456 | 463 | void DataRow::SetValue(const int32_t columnIndex, const Nullable<T>& value, DataType targetType) |
| 457 | 464 | { |
| 458 | 465 | ValidateColumnType(columnIndex, targetType); |
| @@ -521,6 +528,11 @@ bool DataRow::IsNull(const int32_t columnIndex) · 62 unmodified lines | ||
| 521 | 528 | } |
| 522 | 529 | } |
| 523 | 530 | |
| 531 | +bool DataRow::IsNull(const std::string& columnName) | |
| 532 | +{ | |
| 533 | + return IsNull(GetColumnIndex(columnName)); | |
| 534 | +} | |
| 535 | + | |
| 524 | 536 | void DataRow::SetNullValue(const int32_t columnIndex) |
| 525 | 537 | { |
| 526 | 538 | const DataColumnPtr column = m_parent->Column(columnIndex); |