forked from sttp/cppapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTable.cpp
More file actions
188 lines (162 loc) · 5.89 KB
/
DataTable.cpp
File metadata and controls
188 lines (162 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//******************************************************************************************************
// DataTable.cpp - Gbtc
//
// Copyright © 2019, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
// file except in compliance with the License. You may obtain a copy of the License at:
//
// http://opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 11/03/2018 - J. Ritchie Carroll
// Generated original version of source code.
//
//******************************************************************************************************
// ReSharper disable CppClangTidyClangDiagnosticExitTimeDestructors
// ReSharper disable CppClangTidyClangDiagnosticCoveredSwitchDefault
#include "DataTable.h"
#include "DataSet.h"
using namespace std;
using namespace sttp;
using namespace sttp::data;
const DataTablePtr DataTable::NullPtr = nullptr;
DataTable::DataTable(DataSetPtr parent, string name) :
m_parent(std::move(parent)),
m_name(std::move(name))
{
if (m_parent == nullptr)
throw DataSetException("DataSet parent is null");
}
DataTable::~DataTable() = default;
const DataSetPtr& DataTable::Parent() const
{
return m_parent;
}
const string& DataTable::Name() const
{
return m_name;
}
void DataTable::AddColumn(DataColumnPtr column)
{
column->m_index = ConvertInt32(m_columns.size());
m_columnIndexes.insert(pair<string, int32_t>(column->Name(), column->m_index));
m_columns.push_back(std::move(column));
}
const DataColumnPtr& DataTable::Column(const string& columnName) const
{
const auto iterator = m_columnIndexes.find(columnName);
if (iterator != m_columnIndexes.end())
return Column(iterator->second);
return DataColumn::NullPtr;
}
const DataColumnPtr& DataTable::Column(const int32_t index) const
{
if (index < 0 || index >= ConvertInt32(m_columns.size()))
return DataColumn::NullPtr;
return m_columns[index];
}
const DataColumnPtr& DataTable::operator[](const string& columnName) const
{
return Column(columnName);
}
const DataColumnPtr& DataTable::operator[](const int32_t index) const
{
return Column(index);
}
DataColumnPtr DataTable::CreateColumn(const string& name, const DataType type, string expression)
{
return NewSharedPtr<DataColumn, DataTablePtr, string, DataType, string>(shared_from_this(), name, type, std::move(expression));
}
DataColumnPtr DataTable::CloneColumn(const DataColumnPtr& source)
{
return CreateColumn(source->Name(), source->Type(), source->Expression());
}
int32_t DataTable::ColumnCount() const
{
return ConvertInt32(m_columns.size());
}
const DataRowPtr& DataTable::Row(const int32_t index)
{
if (index < 0 || index >= ConvertInt32(m_rows.size()))
return DataRow::NullPtr;
return m_rows[index];
}
void DataTable::AddRow(DataRowPtr row)
{
m_rows.push_back(std::move(row));
}
DataRowPtr DataTable::CreateRow()
{
return NewSharedPtr<DataRow, DataTablePtr>(shared_from_this());
}
DataRowPtr DataTable::CloneRow(const DataRowPtr& source)
{
DataRowPtr row = CreateRow();
const int32_t columnCount = ConvertInt32(m_columns.size());
for (int32_t i = 0; i < columnCount; i++)
{
switch (m_columns[i]->m_type)
{
case DataType::String:
row->SetStringValue(i, source->ValueAsString(i));
break;
case DataType::Boolean:
row->SetBooleanValue(i, source->ValueAsBoolean(i));
break;
case DataType::DateTime:
row->SetDateTimeValue(i, source->ValueAsDateTime(i));
break;
case DataType::Single:
row->SetSingleValue(i, source->ValueAsSingle(i));
break;
case DataType::Double:
row->SetDoubleValue(i, source->ValueAsDouble(i));
break;
case DataType::Decimal:
row->SetDecimalValue(i, source->ValueAsDecimal(i));
break;
case DataType::Guid:
row->SetGuidValue(i, source->ValueAsGuid(i));
break;
case DataType::Int8:
row->SetInt8Value(i, source->ValueAsInt8(i));
break;
case DataType::Int16:
row->SetInt16Value(i, source->ValueAsInt16(i));
break;
case DataType::Int32:
row->SetInt32Value(i, source->ValueAsInt32(i));
break;
case DataType::Int64:
row->SetInt64Value(i, source->ValueAsInt64(i));
break;
case DataType::UInt8:
row->SetUInt8Value(i, source->ValueAsUInt8(i));
break;
case DataType::UInt16:
row->SetUInt16Value(i, source->ValueAsUInt16(i));
break;
case DataType::UInt32:
row->SetUInt32Value(i, source->ValueAsUInt32(i));
break;
case DataType::UInt64:
row->SetUInt64Value(i, source->ValueAsUInt64(i));
break;
default:
throw DataSetException("Unexpected column data type encountered");
}
}
return row;
}
int32_t DataTable::RowCount() const
{
return ConvertInt32(m_rows.size());
}